You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2007/04/11 21:02:11 UTC

svn commit: r527612 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder: BuilderUtil.java MTOMBuilder.java SOAPBuilder.java

Author: scheu
Date: Wed Apr 11 12:02:10 2007
New Revision: 527612

URL: http://svn.apache.org/viewvc?view=rev&rev=527612
Log:
AXIS2-2508
Contributor:Rich Scheuerle
Avoid conversoin of InputStream into Reader

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MTOMBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java?view=diff&rev=527612&r1=527611&r2=527612
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java Wed Apr 11 12:02:10 2007
@@ -183,13 +183,36 @@
      * @throws java.io.IOException
      */
     public static Reader getReader(InputStream is, String charSetEncoding) throws IOException {
-        PushbackInputStream is2 = new PushbackInputStream(is, BOM_SIZE);
+        PushbackInputStream is2 = getPushbackInputStream(is);
+        String encoding = getCharSetEncoding(is2, charSetEncoding);
+        return new BufferedReader(new InputStreamReader(is2, encoding));
+    }
+    
+    /**
+     * Convenience method to get a PushbackInputStream so that we can read the BOM
+     * @param is
+     * @return PushbackInputStream
+     * @see getActualEncoding()
+     */
+    public static PushbackInputStream getPushbackInputStream(InputStream is) {
+        return new PushbackInputStream(is, BOM_SIZE);
+    }
+    
+    /**
+     * Use the BOM Mark to identify the encoding to be used. Fall back to
+     * default encoding specified
+     *
+     * @param is2 PushBackInputStream (it must be a pushback input stream so that we can unread the BOM)
+     * @param charSetEncoding
+     * @throws java.io.IOException
+     */
+    public static String getCharSetEncoding(PushbackInputStream is2, String defaultEncoding) throws IOException {
         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;
@@ -208,17 +231,16 @@
             encoding = "UTF-32LE";
             unread = n - 4;
         } else {
-
+            
             // Unicode BOM mark not found, unread all bytes
-            encoding = charSetEncoding;
+            encoding = defaultEncoding;
             unread = n;
         }
-
+        
         if (unread > 0) {
             is2.unread(bom, (n - unread), unread);
         }
-
-        return new BufferedReader(new InputStreamReader(is2, encoding));
+        return encoding;
     }
 
 
@@ -296,11 +318,14 @@
                                charSetEncoding);
 
         try {
-            streamReader = StAXUtils.createXMLStreamReader(getReader(
-                    attachments.getSOAPPartInputStream(), charSetEncoding));
+            PushbackInputStream pis = getPushbackInputStream(attachments.getSOAPPartInputStream());
+            String actualCharSetEncoding = getCharSetEncoding(pis, charSetEncoding);
+            
+            streamReader = StAXUtils.createXMLStreamReader(pis, actualCharSetEncoding);
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
+
 
         //  Put a reference to Attachments Map in to the message context For
         // backword compatibility with Axis2 1.0 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MTOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MTOMBuilder.java?view=diff&rev=527612&r1=527611&r2=527612
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MTOMBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/MTOMBuilder.java Wed Apr 11 12:02:10 2007
@@ -30,6 +30,7 @@
 import javax.xml.stream.XMLStreamReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PushbackInputStream;
 
 public class MTOMBuilder implements Builder {
 
@@ -40,11 +41,16 @@
         try {
             Attachments attachments = messageContext.getAttachmentMap();
             String charSetEncoding = (String) messageContext
-                    .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
-            streamReader = StAXUtils.createXMLStreamReader(BuilderUtil.getReader(inputStream,
-                                                                                 charSetEncoding));
+            .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+            
+            // Get the actual encoding by looking at the BOM of the InputStream
+            PushbackInputStream pis = BuilderUtil.getPushbackInputStream(inputStream);
+            String actualCharSetEncoding = BuilderUtil.getCharSetEncoding(pis, charSetEncoding);
+            
+            // Get the XMLStreamReader for this input stream
+            streamReader = StAXUtils.createXMLStreamReader(pis, actualCharSetEncoding);        
             StAXBuilder builder = new MTOMStAXSOAPModelBuilder(streamReader,
-                                                               attachments);
+                    attachments);
             SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
             BuilderUtil
                     .validateSOAPVersion(BuilderUtil.getEnvelopeNamespace(contentType), envelope);

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java?view=diff&rev=527612&r1=527611&r2=527612
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java Wed Apr 11 12:02:10 2007
@@ -29,6 +29,7 @@
 import javax.xml.stream.XMLStreamReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PushbackInputStream;
 
 public class SOAPBuilder implements Builder {
 
@@ -38,8 +39,14 @@
         try {
             String charSetEncoding = (String) messageContext
                     .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
-            streamReader = StAXUtils.createXMLStreamReader(BuilderUtil.getReader(inputStream,
-                                                                                 charSetEncoding));
+            
+            // Get the actual encoding by looking at the BOM of the InputStream
+            PushbackInputStream pis = BuilderUtil.getPushbackInputStream(inputStream);
+            String actualCharSetEncoding = BuilderUtil.getCharSetEncoding(pis, charSetEncoding);
+            
+            // Get the XMLStreamReader for this input stream
+            streamReader = StAXUtils.createXMLStreamReader(pis, actualCharSetEncoding);
+
             StAXBuilder builder = new StAXSOAPModelBuilder(streamReader);
             SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
             BuilderUtil



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