Author: veithen
Date: Fri Apr 27 19:42:08 2012
New Revision: 1331552

URL: http://svn.apache.org/viewvc?rev=1331552&view=rev
Log:
Removed the code that attempts to determine the charset encoding and/or byte 
order using the algorithm described in the "Autodetection of Character 
Encodings" appendix of the XML spec. It is the role of the XML parser to do 
that. The code was necessary in earlier Axis2 versions because the message 
builders used a Reader instead of an InputStream (see AXIS2-2508). Since they 
now pass the InputStream directly to the parser, the getCharSetEncoding thing 
is no longer required.

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

Modified: 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java?rev=1331552&r1=1331551&r2=1331552&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/BuilderUtil.java
 Fri Apr 27 19:42:08 2012
@@ -89,6 +89,9 @@ import java.util.Map;
 public class BuilderUtil {
     private static final Log log = LogFactory.getLog(BuilderUtil.class);
 
+    /**
+     * @deprecated
+     */
     public static final int BOM_SIZE = 4;
 
     public static SOAPEnvelope buildsoapMessage(MessageContext messageContext,
@@ -262,13 +265,9 @@ public class BuilderUtil {
     }
 
     /**
-     * Use the BOM Mark to identify the encoding to be used. Fall back to 
default encoding
-     * specified
-     *
-     * @param is              the InputStream of a message
-     * @param charSetEncoding default character set encoding
-     * @return a Reader with the correct encoding already set
-     * @throws java.io.IOException
+     * @deprecated Instead of using this method, you should probably pass the 
{@link InputStream}
+     *             directly to the XML parser. If the stream is not XML, you 
shouldn't be using this
+     *             method anyway.
      */
     public static Reader getReader(final InputStream is, final String 
charSetEncoding)
             throws IOException {
@@ -290,24 +289,19 @@ public class BuilderUtil {
     }
 
     /**
-     * Convenience method to get a PushbackInputStream so that we can read the 
BOM
-     *
-     * @param is a regular InputStream
-     * @return a PushbackInputStream wrapping the passed one
+     * @deprecated If you need a {@link PushbackInputStream} just construct 
one (with the
+     *             appropriate size).
      */
     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 defaultEncoding default encoding style if no BOM
-     * @return the selected character set encoding
-     * @throws java.io.IOException
+     * @deprecated It's the role of the XML parser to determine the charset 
encoding and/or byte
+     *             order using the algorithm described in the "Autodetection 
of Character Encodings"
+     *             appendix of the XML spec. If you need this method, then 
something is wrong:
+     *             probably you are using a {@link Reader} where you should 
use an
+     *             {@link InputStream}.
      */
     public static String getCharSetEncoding(PushbackInputStream is2, String 
defaultEncoding)
             throws IOException {
@@ -453,14 +447,7 @@ public class BuilderUtil {
         msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
                                charSetEncoding);
 
-        try {
-            PushbackInputStream pis = 
getPushbackInputStream(attachments.getSOAPPartInputStream());
-            String actualCharSetEncoding = getCharSetEncoding(pis, 
charSetEncoding);
-
-            streamReader = StAXUtils.createXMLStreamReader(pis, 
actualCharSetEncoding);
-        } catch (IOException e) {
-            throw new XMLStreamException(e);
-        }
+        streamReader = 
StAXUtils.createXMLStreamReader(attachments.getSOAPPartInputStream(), 
charSetEncoding);
 
         // Setting the Attachments map to new SwA API
         msgContext.setAttachmentMap(attachments);

Modified: 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/MTOMBuilder.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/MTOMBuilder.java?rev=1331552&r1=1331551&r2=1331552&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/MTOMBuilder.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/MTOMBuilder.java
 Fri Apr 27 19:42:08 2012
@@ -34,7 +34,6 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamReader;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.PushbackInputStream;
 
 public class MTOMBuilder implements Builder {
 
@@ -47,12 +46,8 @@ public class MTOMBuilder implements Buil
             String charSetEncoding = (String) messageContext
             .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(StAXParserConfiguration.SOAP, pis, 
actualCharSetEncoding);        
+            streamReader = 
StAXUtils.createXMLStreamReader(StAXParserConfiguration.SOAP, inputStream, 
charSetEncoding);        
             StAXBuilder builder = new MTOMStAXSOAPModelBuilder(streamReader,
                     attachments);
             SOAPEnvelope envelope = (SOAPEnvelope) 
builder.getDocumentElement();

Modified: 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java?rev=1331552&r1=1331551&r2=1331552&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java
 Fri Apr 27 19:42:08 2012
@@ -30,7 +30,6 @@ import org.apache.axis2.context.MessageC
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.PushbackInputStream;
 
 public class SOAPBuilder implements Builder {
 
@@ -46,14 +45,10 @@ public class SOAPBuilder implements Buil
             DetachableInputStream is = new DetachableInputStream(inputStream);
             messageContext.setProperty(Constants.DETACHABLE_INPUT_STREAM, is);
             
-            // Get the actual encoding by looking at the BOM of the InputStream
-            PushbackInputStream pis = BuilderUtil.getPushbackInputStream(is);
-            String actualCharSetEncoding = BuilderUtil.getCharSetEncoding(pis, 
charSetEncoding);
-            
             // createSOAPModelBuilder takes care of configuring the underlying 
parser to
             // avoid the security issue described in CVE-2010-1632
-            OMXMLParserWrapper builder = 
OMXMLBuilderFactory.createSOAPModelBuilder(pis,
-                    actualCharSetEncoding);
+            OMXMLParserWrapper builder = 
OMXMLBuilderFactory.createSOAPModelBuilder(is,
+                    charSetEncoding);
             SOAPEnvelope envelope = (SOAPEnvelope) 
builder.getDocumentElement();
             BuilderUtil
                     
.validateSOAPVersion(BuilderUtil.getEnvelopeNamespace(contentType), envelope);


Reply via email to