Author: veithen
Date: Sun Jan  4 10:36:29 2009
New Revision: 731318

URL: http://svn.apache.org/viewvc?rev=731318&view=rev
Log:
Fixed WSCOMMONS-427 and WSCOMMONS-429.

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java?rev=731318&r1=731317&r2=731318&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/XOPAwareStAXOMBuilder.java
 Sun Jan  4 10:36:29 2009
@@ -117,8 +117,7 @@
         if (MTOMConstants.XOP_INCLUDE.equals(elementName)
                 && MTOMConstants.XOP_NAMESPACE_URI.equals(namespaceURI)) {
             OMText node;
-            String contentID = ElementHelper.getContentID(parser, getDocument()
-                    .getCharsetEncoding());
+            String contentID = ElementHelper.getContentID(parser);
             if (log.isDebugEnabled()) {
                 log.debug("Encountered xop:include for cid:" + contentID);
             }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java?rev=731318&r1=731317&r2=731318&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
 Sun Jan  4 10:36:29 2009
@@ -26,6 +26,7 @@
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.om.impl.util.OMSerializerUtil;
+import org.apache.axiom.om.util.ElementHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -546,7 +547,7 @@
      */ 
     protected boolean serializeXOPInclude(XMLStreamReader reader,
                                           XMLStreamWriter writer) {
-       String cid = reader.getAttributeValue(null, "href");
+       String cid = ElementHelper.getContentID(reader);
        DataHandler dh = getDataHandler(cid, (OMAttachmentAccessor) reader);
        if (dh == null) {
            return false;

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java?rev=731318&r1=731317&r2=731318&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/ElementHelper.java
 Sun Jan  4 10:36:29 2009
@@ -134,36 +134,47 @@
         return null;
     }
 
+    /**
+     * @deprecated use {...@link #getContentID(XMLStreamReader)} instead (see 
WSCOMMONS-429)
+     */
     public static String getContentID(XMLStreamReader parser, String 
charsetEncoding) {
-        String contentID;
-        String contentIDName;
-        if (parser.getAttributeCount() > 0) {
-            contentID = parser.getAttributeValue(0);
-            contentID = contentID.trim();
-            contentIDName = parser.getAttributeLocalName(0);
-            if (contentIDName.equalsIgnoreCase("href")
-                    & contentID.substring(0, 3).equalsIgnoreCase("cid")) {
-                contentID = contentID.substring(4);
-                String charEnc = charsetEncoding == null || 
"".equals(charsetEncoding) ? "UTF-8" :
-                        charsetEncoding;
-                try {
-                    contentID = URLDecoder.decode(contentID, charEnc);
-                } catch (UnsupportedEncodingException e) {
-                    throw new OMException("Unsupported Character Encoding 
Found", e);
-                }
-            } else if (!(contentIDName.equalsIgnoreCase("href")
-                    & (!contentID.equals("")))) {
-                throw new OMException(
-                        "contentID not Found in XOP:Include element");
-            }
+        return getContentID(parser);
+    }
+
+    public static String getContentID(XMLStreamReader parser) {
+        if (parser.getAttributeCount() > 0 &&
+                parser.getAttributeLocalName(0).equals("href")) {
+            return getContentIDFromHref(parser.getAttributeValue(0));
         } else {
             throw new OMException(
                     "Href attribute not found in XOP:Include element");
         }
-        return contentID;
     }
 
     /**
+     * Extract the content ID from a href attribute value, i.e. from a URI 
following the
+     * cid: scheme defined by RFC2392.
+     * 
+     * @param href the value of the href attribute
+     * @return the corresponding content ID
+     */
+    public static String getContentIDFromHref(String href) {
+        if (href.startsWith("cid:")) {
+            try {
+                // URIs should always be decoded using UTF-8 (see 
WSCOMMONS-429). On the
+                // other hand, since non ASCII characters are not allowed in 
content IDs,
+                // we can simply decode using ASCII (which is a subset of 
UTF-8)
+                return URLDecoder.decode(href.substring(4), "ascii");
+            } catch (UnsupportedEncodingException ex) {
+                // We should never get here
+                throw new OMException(ex);
+            }
+        } else {
+            throw new OMException("href attribute didn't contain a valid cid: 
URI");
+        }
+    }
+    
+    /**
      * Some times two OMElements needs to be added to the same object tree. 
But in Axiom, a single
      * tree should always contain object created from the same type of factory 
(eg:
      * LinkedListImplFactory, DOMFactory, etc.,). If one OMElement is created 
from a different

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java?rev=731318&r1=731317&r2=731318&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/MTOMStAXSOAPModelBuilder.java
 Sun Jan  4 10:36:29 2009
@@ -77,8 +77,7 @@
         // create an OMBlob if the element is an <xop:Include>
         if (XOP_INCLUDE.equals(elementName) && 
XOP_NAMESPACE_URI.equals(namespaceURI)) {
             OMText node;
-            String contentID = ElementHelper.getContentID(parser, getDocument()
-                    .getCharsetEncoding());
+            String contentID = ElementHelper.getContentID(parser);
             
             if (log.isDebugEnabled()) {
                 log.debug("Encountered xop:include for cid:" + contentID);

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java?rev=731318&r1=731317&r2=731318&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java
 Sun Jan  4 10:36:29 2009
@@ -100,6 +100,7 @@
      * the XOP is preserved when it is serialized.
      * @throws Exception
      */
+    // TODO: because of the serializeAndConsume, this is actually NOT testing 
MTOMStAXSOAPModelBuilder, but StreamingOMSerializer!!!
     public void testCreateAndSerializeOptimized() throws Exception {
         String contentTypeString =
                 "multipart/Related; charset=\"UTF-8\"; 
type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; 
start=\"SOAPPart\"";
@@ -120,7 +121,7 @@
         String msg = baos.toString();
         // Make sure there is an xop:Include element and an optimized 
attachment
         assertTrue(msg.indexOf("xop:Include") > 0);
-        assertTrue(msg.indexOf("Content-ID: <cid:-1609420109260943731>") > 0);
+        assertTrue(msg.indexOf("Content-ID: <-1609420109260943731>") > 0);
     }
     
     /**
@@ -248,7 +249,7 @@
         String contentTypeString =
                 "multipart/Related; charset=\"UTF-8\"; 
type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; 
start=\"SOAPPart\"";
         String originalCID = 
"1.urn:uuid:[email protected]";
-        String encodedCID = URLEncoder.encode(originalCID, "UTF-16");
+        String encodedCID = URLEncoder.encode(originalCID, "UTF-8"); // URIs 
are always encoded using UTF-8 (see WSCOMMONS-429)
         String xmlPlusMime1 = "------=_AxIs2_Def_boundary_=42214532\r\n" +
                 "Content-Type: application/xop+xml; charset=UTF-16\r\n" +
                 "Content-Transfer-Encoding: 8bit\r\n" +


Reply via email to