axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r357127 - in /webservices/axis2/trunk/java/modules: core/src/org/apache/axis2/transport/ core/src/org/apache/axis2/transport/http/ integration/test/org/apache/axis2/mtom/ xml/src/org/apache/axis2/om/impl/ xml/src/org/apache/axis2/soap/impl/...
Date Fri, 16 Dec 2005 05:50:27 GMT
Author: dims
Date: Thu Dec 15 21:50:17 2005
New Revision: 357127

URL: http://svn.apache.org/viewcvs?rev=357127&view=rev
Log:
Fixes for getting UTF-16/MTOM working:

- Added a getReader() in that can check/consume the BOM to find the encoding as well as to
create a InputStreamReader based on encoding.
- Get/Set CHARACTER_SET_ENCODING in OperationContext (See AbstractHTTPSender.java and TransportUtils.java)
otherwise it is getting lost.
- Switch on UTF-16 in EchoRawMTOMTest.java
- Switch ByteArrayOutputStream in OMOutputImpl to a StringWriter. Since we need a string in
MIMEOutputUtils anyway. no point converting back and forth.
  (also writing to OutputStream twice in UTF-16 was adding 2 BOM's)
- Roll back previous change to CRLF in writeBodyPart method in MIMEOutputUtils. It was an
untested change during hackathon.
- set the character encoding in StAXSOAPModelBuilder.java. Since we later check the character
encoding and throw an exception.


Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/TransportUtils.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMTest.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/TransportUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/TransportUtils.java?rev=357127&r1=357126&r2=357127&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/TransportUtils.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/TransportUtils.java
Thu Dec 15 21:50:17 2005
@@ -66,6 +66,9 @@
 
             String charSetEnc = (String)msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
             if(charSetEnc == null) {
+                charSetEnc = (String)opContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
+            }
+            if(charSetEnc == null) {
             	charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
             }
             

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?rev=357127&r1=357126&r2=357127&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
Thu Dec 15 21:50:17 2005
@@ -251,10 +251,10 @@
             for (int i = 0; i < headers.length; i++) {
                 NameValuePair charsetEnc = headers[i]
                         .getParameterByName(HTTPConstants.CHAR_SET_ENCODING);
+                OperationContext opContext = msgContext
+                        .getOperationContext();
                 if (headers[i].getName().equalsIgnoreCase(
                         HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED)) {
-                    OperationContext opContext = msgContext
-                            .getOperationContext();
                     if (opContext != null) {
                         opContext.setProperty(
                                 HTTPConstants.MTOM_RECIVED_CONTENT_TYPE, header
@@ -262,7 +262,7 @@
                     }
                 } else if (charsetEnc != null) {
 
-                    msgContext.setProperty(
+                    opContext.setProperty(
                             MessageContext.CHARACTER_SET_ENCODING, charsetEnc
                             .getValue()); //change to the value, which is text/xml or application/xml+soap
                 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?rev=357127&r1=357126&r2=357127&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
Thu Dec 15 21:50:17 2005
@@ -55,6 +55,8 @@
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
+import java.io.PushbackInputStream;
+import java.io.IOException;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -340,27 +342,23 @@
                 fileCacheForAttachments, attachmentRepoDir, attachmentSizeThreshold);
 
         String charSetEncoding = TransportUtils.getCharSetEncoding(mimeHelper.getSOAPPartContentType());
-        XMLStreamReader reader;
+        XMLStreamReader streamReader;
         if (charSetEncoding == null || "null".equalsIgnoreCase(charSetEncoding)) {
-            reader = XMLInputFactory.newInstance()
-                    .createXMLStreamReader(
-                            new BufferedReader(new InputStreamReader(mimeHelper
-                                    .getSOAPPartInputStream(),
-                                    charSetEncoding)));
-            msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING, charSetEncoding);
+            charSetEncoding = MessageContext.UTF_8;
+        }
 
-        } else {
-            reader = XMLInputFactory.newInstance()
+        try {
+            streamReader = XMLInputFactory.newInstance()
                     .createXMLStreamReader(
-                            new BufferedReader(new InputStreamReader(mimeHelper
-                                    .getSOAPPartInputStream())));
-            msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING, MessageContext.UTF_8);
-
+                            getReader(mimeHelper.getSOAPPartInputStream(), charSetEncoding));
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
         }
+        msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING, charSetEncoding);
 
         /*
-           * put a reference to Attachments in to the message context
-           */
+         * put a reference to Attachments in to the message context
+         */
         msgContext.setProperty(MTOMConstants.ATTACHMENTS, mimeHelper);
         if (mimeHelper.getAttachmentSpecType().equals(MTOMConstants.MTOM_TYPE)) {
             /*
@@ -368,17 +366,63 @@
              */
             builder =
                     new MTOMStAXSOAPModelBuilder(
-                            reader,
+                            streamReader,
                             mimeHelper,
                             null);
-        } else if (
-                mimeHelper.getAttachmentSpecType().equals(MTOMConstants.SWA_TYPE)) {
+        } else if (mimeHelper.getAttachmentSpecType().equals(MTOMConstants.SWA_TYPE)) {
             builder =
                     new StAXSOAPModelBuilder(
-                            reader,
+                            streamReader,
                             SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
         }
         return builder;
+    }
+    
+    private static final int BOM_SIZE = 4;
+
+    /**
+     * Use the BOM Mark to identify the encoding to be used. Fall back to default encoding
specified 
+     * 
+     * @param is
+     * @param charSetEncoding
+     * @return
+     * @throws IOException
+     */
+    private static Reader getReader(InputStream is, String charSetEncoding) throws IOException
{
+        PushbackInputStream is2 = new PushbackInputStream(is, BOM_SIZE);
+
+        String encoding;
+        byte bom[] = new byte[BOM_SIZE];
+        int n, unread;
+        n = is2.read(bom, 0, bom.length);
+
+        if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) &&
+                (bom[2] == (byte) 0xBF)) {
+            encoding = "UTF-8";
+            unread = n - 3;
+        } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
+            encoding = "UTF-16BE";
+            unread = n - 2;
+        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
+            encoding = "UTF-16LE";
+            unread = n - 2;
+        } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) &&
+                (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
+            encoding = "UTF-32BE";
+            unread = n - 4;
+        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) &&
+                (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) {
+            encoding = "UTF-32LE";
+            unread = n - 4;
+        } else {
+            // Unicode BOM mark not found, unread all bytes
+            encoding = charSetEncoding;
+            unread = n;
+        }
+        if (unread > 0) is2.unread(bom, (n - unread), unread);
+
+        return new BufferedReader(new InputStreamReader(is2,
+                encoding));
     }
 
     public static boolean checkEnvelopeForOptimise(SOAPEnvelope envelope) {

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMTest.java?rev=357127&r1=357126&r2=357127&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMTest.java
(original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMTest.java
Thu Dec 15 21:50:17 2005
@@ -19,12 +19,15 @@
 import junit.framework.TestCase;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.attachments.utils.ImageDataSource;
 import org.apache.axis2.attachments.utils.ImageIO;
 import org.apache.axis2.client.Options;
 import org.apache.axis2.client.async.AsyncResult;
 import org.apache.axis2.client.async.Callback;
 import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.engine.Echo;
 import org.apache.axis2.engine.util.TestConstants;
@@ -155,6 +158,9 @@
 
         Options options = new Options();
         call.setClientOptions(options);
+        options.setProperty(MessageContext.CHARACTER_SET_ENCODING, "UTF-16");
+        //options.setTimeOutInMilliSeconds(-1);
+        //options.setProperty(HTTPConstants.SO_TIMEOUT,new Integer(Integer.MAX_VALUE));
         options.setTo(targetEPR);
         options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
         options.setListenerTransportProtocol(Constants.TRANSPORT_HTTP);

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java?rev=357127&r1=357126&r2=357127&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
Thu Dec 15 21:50:17 2005
@@ -25,22 +25,23 @@
 import javax.mail.internet.MimeBodyPart;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.StringWriter;
 import java.util.Iterator;
 import java.util.LinkedList;
 
 public class MIMEOutputUtils {
 
-    private static String CRLF = "\r\n";
+    private static byte[] CRLF =  { 13, 10 };
     private Log log = LogFactory.getLog(getClass());
 
     public static void complete(OutputStream outStream,
-                                OutputStream bufferedSoapOutStream, LinkedList binaryNodeList,
+                                StringWriter writer, LinkedList binaryNodeList,
                                 String boundary, String contentId, String charSetEncoding,String
SOAPContentType) {
         try {
             startWritingMime(outStream, boundary);
 
-            javax.activation.DataHandler dh = new javax.activation.DataHandler(bufferedSoapOutStream.toString(),
-                    "text/xml");
+            javax.activation.DataHandler dh = new javax.activation.DataHandler(writer.toString(),
+                    "text/xml; charset=" + charSetEncoding);
             MimeBodyPart rootMimeBodyPart = new MimeBodyPart();
             rootMimeBodyPart.setDataHandler(dh);
             
@@ -50,13 +51,13 @@
             rootMimeBodyPart.addHeader("content-transfer-encoding", "binary");
             rootMimeBodyPart.addHeader("content-id","<"+contentId+">");
 
-            writeBodyPart(outStream, rootMimeBodyPart, boundary, charSetEncoding);
+            writeBodyPart(outStream, rootMimeBodyPart, boundary);
 
             Iterator binaryNodeIterator = binaryNodeList.iterator();
             while (binaryNodeIterator.hasNext()) {
                 OMText binaryNode = (OMText) binaryNodeIterator.next();
                 writeBodyPart(outStream, createMimeBodyPart(binaryNode),
-                        boundary, charSetEncoding);
+                        boundary);
             }
             finishWritingMime(outStream);
         } catch (IOException e) {
@@ -106,12 +107,11 @@
      */
     public static void writeBodyPart(OutputStream outStream,
                                      MimeBodyPart part, 
-                                     String boundary,
-                                     String encoding) throws IOException,
+                                     String boundary) throws IOException,
             MessagingException {
-        outStream.write(CRLF.getBytes(encoding));
+        outStream.write(CRLF);
         part.writeTo(outStream);
-        outStream.write(CRLF.getBytes(encoding));
+        outStream.write(CRLF);
         writeMimeBoundary(outStream, boundary);
     }
 

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java?rev=357127&r1=357126&r2=357127&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
Thu Dec 15 21:50:17 2005
@@ -27,6 +27,7 @@
 import javax.xml.stream.XMLStreamWriter;
 import java.io.ByteArrayOutputStream;
 import java.io.OutputStream;
+import java.io.StringWriter;
 import java.util.LinkedList;
 
 
@@ -39,7 +40,7 @@
     private XMLStreamWriter xmlWriter;
     private OutputStream outStream;
     private LinkedList binaryNodeList = new LinkedList();
-    private ByteArrayOutputStream bufferedSoapOutStream;
+    private StringWriter bufferedSOAPBody;
     private OMOutputFormat format = new OMOutputFormat();
 
     public OMOutputImpl(XMLStreamWriter xmlWriter) {
@@ -66,9 +67,8 @@
         XMLOutputFactory factory = XMLOutputFactory.newInstance();
 
         if (format.isOptimized()) {
-            bufferedSoapOutStream = new ByteArrayOutputStream();
-            xmlWriter = factory.createXMLStreamWriter(bufferedSoapOutStream,
-                    format.getCharSetEncoding());
+            bufferedSOAPBody = new StringWriter();
+            xmlWriter = factory.createXMLStreamWriter(bufferedSOAPBody);
         } else {
             xmlWriter = factory.createXMLStreamWriter(outStream,
                     format.getCharSetEncoding());
@@ -86,7 +86,7 @@
             }
             MIMEOutputUtils.complete(
                     outStream,
-                    bufferedSoapOutStream,
+                    bufferedSOAPBody,
                     binaryNodeList,
                     format.getMimeBoundary(),
                     format.getRootContentId(),

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java?rev=357127&r1=357126&r2=357127&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java
Thu Dec 15 21:50:17 2005
@@ -106,6 +106,9 @@
         soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
         isTempSOAPFactory = true;
         soapMessage = soapFactory.createSOAPMessage(this);
+        if(parser.getCharacterEncodingScheme() != null) {
+            document.setCharsetEncoding(parser.getCharacterEncodingScheme());
+        }
         identifySOAPVersion(soapVersion);
         parseHeaders();
     }

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java?rev=357127&r1=357126&r2=357127&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java
Thu Dec 15 21:50:17 2005
@@ -65,9 +65,9 @@
 
         MIMEOutputUtils.startWritingMime(outStream, boundary);
         MimeBodyPart part1 = MIMEOutputUtils.createMimeBodyPart(textData);
-        MIMEOutputUtils.writeBodyPart(outStream, part1, boundary, "UTF-8");
+        MIMEOutputUtils.writeBodyPart(outStream, part1, boundary);
         MimeBodyPart part2 = MIMEOutputUtils.createMimeBodyPart(text);
-        MIMEOutputUtils.writeBodyPart(outStream, part2, boundary, "UTF-8");
+        MIMEOutputUtils.writeBodyPart(outStream, part2, boundary);
         MIMEOutputUtils.finishWritingMime(outStream);
         buffer = outStream.toByteArray();
     }



Mime
View raw message