You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2011/07/15 20:34:19 UTC

svn commit: r1147272 - in /axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2: builder/ApplicationXMLBuilder.java builder/BuilderUtil.java transport/TransportUtils.java

Author: veithen
Date: Fri Jul 15 18:34:19 2011
New Revision: 1147272

URL: http://svn.apache.org/viewvc?rev=1147272&view=rev
Log:
Introduced replacements for some of the BuilderUtil#getXxxBuilder methods. They use the new API defined by AXIOM-353 and therefore enable usage of non standard Axiom implementations.

Modified:
    axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/ApplicationXMLBuilder.java
    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/transport/TransportUtils.java

Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/ApplicationXMLBuilder.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/ApplicationXMLBuilder.java?rev=1147272&r1=1147271&r2=1147272&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/ApplicationXMLBuilder.java (original)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/builder/ApplicationXMLBuilder.java Fri Jul 15 18:34:19 2011
@@ -21,7 +21,7 @@ package org.apache.axis2.builder;
 
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.util.DetachableInputStream;
 import org.apache.axiom.soap.SOAPBody;
 import org.apache.axiom.soap.SOAPEnvelope;
@@ -30,7 +30,6 @@ import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.context.MessageContext;
 
-import javax.xml.stream.XMLStreamException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
@@ -60,8 +59,8 @@ public class ApplicationXMLBuilder imple
                 int b;
                 if ((b = pushbackInputStream.read()) > 0) {
                     pushbackInputStream.unread(b);
-                    StAXBuilder builder =
-                            BuilderUtil.getPOXBuilder(pushbackInputStream,
+                    OMXMLParserWrapper builder =
+                            BuilderUtil.createPOXBuilder(pushbackInputStream,
                                     (String) messageContext.getProperty(
                                             Constants.Configuration.CHARACTER_SET_ENCODING));
                     OMElement documentElement = builder.getDocumentElement(true);
@@ -69,8 +68,6 @@ public class ApplicationXMLBuilder imple
                     body.addChild(documentElement);
                 }
 
-            } catch (XMLStreamException e) {
-                throw AxisFault.makeFault(e);
             } catch (IOException e) {
                 throw AxisFault.makeFault(e);
             }

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=1147272&r1=1147271&r2=1147272&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 Jul 15 18:34:19 2011
@@ -28,6 +28,8 @@ import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.MTOMConstants;
 import org.apache.axiom.om.impl.builder.StAXBuilder;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
@@ -40,6 +42,7 @@ import org.apache.axiom.soap.SOAPBody;
 import org.apache.axiom.soap.SOAPConstants;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPModelBuilder;
 import org.apache.axiom.soap.SOAPProcessingException;
 import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
@@ -226,6 +229,10 @@ public class BuilderUtil {
         }
     }
 
+    /**
+     * @deprecated Please use {@link #createPOXBuilder(InputStream, String)} to enable usage of non
+     *             standard Axiom implementations.
+     */
     public static StAXBuilder getPOXBuilder(InputStream inStream, String charSetEnc)
             throws XMLStreamException {
         StAXBuilder builder;
@@ -239,6 +246,22 @@ public class BuilderUtil {
     }
 
     /**
+     * Create a builder suitable for an XML message. This method uses
+     * {@link StAXParserConfiguration#SOAP} to disallow document type declarations (that potentially
+     * reference external entities).
+     * 
+     * @param in
+     *            the input stream containing the plain XML message
+     * @param encoding
+     *            the charset encoding of the message or <code>null</code> if the parser should
+     *            determine the charset encoding
+     * @return the builder
+     */
+    public static OMXMLParserWrapper createPOXBuilder(InputStream in, String encoding) {
+        return OMXMLBuilderFactory.createOMBuilder(StAXParserConfiguration.SOAP, in, encoding);
+    }
+
+    /**
      * Use the BOM Mark to identify the encoding to be used. Fall back to default encoding
      * specified
      *
@@ -613,11 +636,7 @@ public class BuilderUtil {
     }
 
     /**
-     * Creates an OMBuilder for a plain XML message. Default character set encording is used.
-     *
-     * @param inStream InputStream for a XML message
-     * @return Handler to a OMBuilder implementation instance
-     * @throws XMLStreamException
+     * @deprecated Please use {@link OMXMLBuilderFactory#createOMBuilder(InputStream)} instead.
      */
     public static StAXBuilder getBuilder(InputStream inStream) throws XMLStreamException {
         XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(inStream);
@@ -625,12 +644,35 @@ public class BuilderUtil {
     }
 
     /**
-     * Creates an OMBuilder for a plain XML message.
-     *
-     * @param inStream   InputStream for a XML message
-     * @param charSetEnc Character set encoding to be used
-     * @return Handler to a OMBuilder implementation instance
-     * @throws XMLStreamException
+     * Create a SOAP model builder. This method delegates to
+     * {@link OMXMLBuilderFactory#createSOAPModelBuilder(InputStream, String)} but generates
+     * additional logging if an error occurs.
+     * 
+     * @param in
+     *            the input stream containing the SOAP message
+     * @param encoding
+     *            the charset encoding of the SOAP message or <code>null</code> if the parser should
+     *            determine the charset encoding
+     * @return the builder
+     */
+    public static SOAPModelBuilder createSOAPModelBuilder(InputStream in, String encoding) {
+        try {
+            return OMXMLBuilderFactory.createSOAPModelBuilder(in, encoding);
+        } catch (OMException e) {
+            log.info("OMException in getSOAPBuilder", e);
+            try {
+                log.info("Remaining input stream :[" +
+                         new String(IOUtils.getStreamAsByteArray(in), encoding) + "]");
+            } catch (IOException e1) {
+                // Nothing here?
+            }
+            throw e;
+        }
+    }
+
+    /**
+     * @deprecated Please use {@link #createSOAPModelBuilder(InputStream, String)} to enable usage
+     *             of non standard Axiom implementations.
      */
     public static StAXBuilder getBuilder(InputStream inStream, String charSetEnc)
             throws XMLStreamException {
@@ -650,11 +692,8 @@ public class BuilderUtil {
     }
 
     /**
-     * Creates an OMBuilder for a SOAP message. Default character set encording is used.
-     *
-     * @param inStream InputStream for a SOAP message
-     * @return Handler to a OMBuilder implementation instance
-     * @throws XMLStreamException
+     * @deprecated Please use {@link #createSOAPModelBuilder(InputStream, String)} to enable usage
+     *             of non standard Axiom implementations.
      */
     public static StAXBuilder getSOAPBuilder(InputStream inStream) throws XMLStreamException {
         XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(inStream);
@@ -673,12 +712,8 @@ public class BuilderUtil {
     }
 
     /**
-     * Creates an OMBuilder for a SOAP message.
-     *
-     * @param inStream   InputStream for a SOAP message
-     * @param charSetEnc Character set encoding to be used
-     * @return Handler to a OMBuilder implementation instance
-     * @throws XMLStreamException
+     * @deprecated Please use {@link #createSOAPModelBuilder(InputStream, String)} to enable usage
+     *             of non standard Axiom implementations.
      */
     public static StAXBuilder getSOAPBuilder(InputStream inStream, String charSetEnc)
             throws XMLStreamException {

Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java?rev=1147272&r1=1147271&r2=1147272&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java (original)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java Fri Jul 15 18:34:19 2011
@@ -27,12 +27,13 @@ import org.apache.axiom.om.OMAbstractFac
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.util.DetachableInputStream;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPModelBuilder;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.builder.Builder;
@@ -184,7 +185,7 @@ public class TransportUtils {
                 if (log.isDebugEnabled()) {
                     log.debug("Could not find a Builder for type (" + type + ").  Using REST.");
                 }
-                StAXBuilder builder = BuilderUtil.getPOXBuilder(inStream, null);
+                OMXMLParserWrapper builder = BuilderUtil.createPOXBuilder(inStream, null);
                 documentElement = builder.getDocumentElement();
             } else {
                 // FIXME making soap defualt for the moment..might effect the
@@ -194,7 +195,7 @@ public class TransportUtils {
                 }
                 String charSetEnc = (String) msgContext
                         .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
-                StAXBuilder builder = BuilderUtil.getSOAPBuilder(inStream, charSetEnc);
+                SOAPModelBuilder builder = BuilderUtil.createSOAPModelBuilder(inStream, charSetEnc);
                 documentElement = builder.getDocumentElement();
             }
         }