You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by di...@apache.org on 2007/06/28 05:12:19 UTC

svn commit: r551431 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/attachments/ axiom-api/src/main/java/org/apache/axiom/om/impl/builder/ axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/

Author: dims
Date: Wed Jun 27 20:12:18 2007
New Revision: 551431

URL: http://svn.apache.org/viewvc?view=rev&rev=551431
Log:
Fix the really old Axis2 bug with a test case. AXIS2-489 - Axis2 cannot decode UTF16 URL encoded strings

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.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/attachments/Attachments.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java?view=diff&rev=551431&r1=551430&r2=551431
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java Wed Jun 27 20:12:18 2007
@@ -133,8 +133,12 @@
 
         // Boundary always have the prefix "--".
         try {
+            String encoding = contentType.getParameter("charset");
+            if(encoding == null || encoding.length()==0){
+                encoding = "UTF-8";
+            }
             this.boundary = ("--" + contentType.getParameter("boundary"))
-                    .getBytes("UTF-8");
+                    .getBytes(encoding);
         } catch (UnsupportedEncodingException e) {
             throw new OMException(e);
         }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?view=diff&rev=551431&r1=551430&r2=551431
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java Wed Jun 27 20:12:18 2007
@@ -82,6 +82,9 @@
         this.parser = parser;
         omfactory = ombuilderFactory;
         charEncoding = parser.getCharacterEncodingScheme();
+        if(charEncoding == null){
+            charEncoding = parser.getEncoding();
+        }
 
         if (parser instanceof BuilderAwareReader) {
             ((BuilderAwareReader) parser).setBuilder(this);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?view=diff&rev=551431&r1=551430&r2=551431
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Wed Jun 27 20:12:18 2007
@@ -59,6 +59,9 @@
     public StAXOMBuilder(OMFactory ombuilderFactory, XMLStreamReader parser) {
         super(ombuilderFactory, parser);
         document = ombuilderFactory.createOMDocument(this);
+        if (charEncoding != null) {
+            document.setCharsetEncoding(charEncoding);
+        }
     }
 
     /**
@@ -93,6 +96,9 @@
         super(parser);
         omfactory = OMAbstractFactory.getOMFactory();
         document = omfactory.createOMDocument(this);
+        if (charEncoding != null) {
+            document.setCharsetEncoding(charEncoding);
+        }
     }
 
     /**

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?view=diff&rev=551431&r1=551430&r2=551431
==============================================================================
--- 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 Wed Jun 27 20:12:18 2007
@@ -31,36 +31,36 @@
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.ByteArrayInputStream;
+import java.io.BufferedInputStream;
 import java.util.Iterator;
+import java.util.Arrays;
+import java.lang.reflect.Array;
+import java.net.URLEncoder;
 
 public class MTOMStAXSOAPModelBuilderTest extends AbstractTestCase {
-    Attachments attachments;
-
-    String inFileName;
-
-    OMXMLParserWrapper builder;
 
     /** @param testName  */
     public MTOMStAXSOAPModelBuilderTest(String testName) {
         super(testName);
     }
 
-    String contentTypeString =
-            "multipart/Related; type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; start=\"SOAPPart\"";
 
     protected void setUp() throws Exception {
         super.setUp();
-        inFileName = "mtom/MTOMBuilderTestIn.txt";
+    }
+
+    public void testCreateOMElement() throws Exception {
+        String contentTypeString =
+                "multipart/Related; charset=\"UTF-8\"; type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; start=\"SOAPPart\"";
+        String inFileName = "mtom/MTOMBuilderTestIn.txt";
         InputStream inStream = new FileInputStream(getTestResourceFile(inFileName));
-        attachments = new Attachments(inStream, contentTypeString);
+        Attachments attachments = new Attachments(inStream, contentTypeString);
         XMLStreamReader reader = XMLInputFactory.newInstance()
                 .createXMLStreamReader(new BufferedReader(new InputStreamReader(attachments
                         .getSOAPPartInputStream())));
-        builder = new MTOMStAXSOAPModelBuilder(reader, attachments,
+        OMXMLParserWrapper builder = new MTOMStAXSOAPModelBuilder(reader, attachments,
                                                SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-    }
-
-    public void testCreateOMElement() throws Exception {
         OMElement root = builder.getDocumentElement();
         OMElement body = (OMElement) root.getFirstOMChild();
         OMElement data = (OMElement) body.getFirstOMChild();
@@ -86,7 +86,45 @@
         //  assertEquals("Object check", expectedObject[5],actualObject[5] );
     }
 
-    public void testGetDataHandler() {
+    public void testUTF16MTOMMessage() throws Exception {
+        String contentTypeString =
+                "multipart/Related; charset=\"UTF-8\"; type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; start=\"SOAPPart\"";
+        String originalCID = "1.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org";
+        String encodedCID = URLEncoder.encode(originalCID, "UTF-16");
+        String xmlPlusMime1 = "------=_AxIs2_Def_boundary_=42214532\r\n" +
+                "Content-Type: application/xop+xml; charset=UTF-16\r\n" +
+                "Content-Transfer-Encoding: 8bit\r\n" +
+                "Content-ID: SOAPPart\r\n" +
+                "\r\n";
+        String xmlPlusMime2 = "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"><soapenv:Body><m:data xmlns:m=\"http://www.example.org/stuff\"><m:name m:contentType=\"text/plain\"><xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"cid:" + encodedCID + "\"></xop:Include></m:name></m:data></soapenv:Body></soapenv:Envelope>\r\n";
+        String xmlPlusMime3 = "\r\n------=_AxIs2_Def_boundary_=42214532\r\n" +
+                "Content-Transfer-Encoding: binary\r\n" +
+                "Content-ID: " + originalCID + "\r\n" +
+                "\r\n" +
+                "Foo Bar\r\n" +
+                "------=_AxIs2_Def_boundary_=42214532--\r\n";
+        byte[] bytes1 = xmlPlusMime1.getBytes();
+        byte[] bytes2 = xmlPlusMime2.getBytes("UTF-16");
+        byte[] bytes3 = xmlPlusMime3.getBytes();
+        byte[] full = append(bytes1, bytes2);
+        full = append(full, bytes3);
+        
+        InputStream inStream = new BufferedInputStream(new ByteArrayInputStream(full));
+        Attachments attachments = new Attachments(inStream, contentTypeString);
+        XMLStreamReader reader = XMLInputFactory.newInstance()
+                .createXMLStreamReader(attachments
+                        .getSOAPPartInputStream(),"UTF-16");
+        MTOMStAXSOAPModelBuilder builder = new MTOMStAXSOAPModelBuilder(reader, attachments,
+                                               SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+        OMElement root = builder.getDocumentElement();
+        root.build();
+        System.out.println(root.toString());
     }
 
+    private byte[] append(byte[] a, byte[] b) {
+        byte[] z = new byte[a.length + b.length];
+        System.arraycopy(a, 0, z, 0, a.length);
+        System.arraycopy(b, 0, z, a.length, b.length);
+        return z;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org