Author: veithen
Date: Mon Nov 12 00:20:17 2018
New Revision: 1846368

URL: http://svn.apache.org/viewvc?rev=1846368&view=rev
Log:
AXIOM-492: Fix incorrect parsing of MIME headers for MTOM.

Added:
    webservices/axiom/trunk/systests/jaxws-tests/   (with props)
    webservices/axiom/trunk/systests/jaxws-tests/pom.xml   (with props)
    webservices/axiom/trunk/systests/jaxws-tests/src/
    webservices/axiom/trunk/systests/jaxws-tests/src/test/
    webservices/axiom/trunk/systests/jaxws-tests/src/test/java/
    webservices/axiom/trunk/systests/jaxws-tests/src/test/java/MTOMTest.java   
(with props)
    webservices/axiom/trunk/systests/jaxws-tests/src/test/wsdl/
    webservices/axiom/trunk/systests/jaxws-tests/src/test/wsdl/image-upload.wsdl
Modified:
    webservices/axiom/trunk/axiom-api/pom.xml
    
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
    webservices/axiom/trunk/pom.xml
    webservices/axiom/trunk/systests/pom.xml
    webservices/axiom/trunk/testing/spring-ws-testsuite/pom.xml

Modified: webservices/axiom/trunk/axiom-api/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/pom.xml?rev=1846368&r1=1846367&r2=1846368&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/pom.xml (original)
+++ webservices/axiom/trunk/axiom-api/pom.xml Mon Nov 12 00:20:17 2018
@@ -336,6 +336,7 @@
                                 org.apache.axiom.om.OMXMLBuilderFactory -> 
org.apache.axiom.soap.SOAPMessage,
                                 org.apache.axiom.om.OMXMLBuilderFactory -> 
org.apache.axiom.soap.SOAPModelBuilder,
                                 org.apache.axiom.om.OMXMLBuilderFactory -> 
org.apache.axiom.soap.SOAPProcessingException,
+                                org.apache.axiom.om.OMXMLBuilderFactory -> 
org.apache.axiom.soap.SOAPVersion,
                                 <!-- The public API shouldn't depend on 
classes in o.a.a.om.util -->
                                 org.apache.axiom.om.OMMetaFactorySPI -> 
org.apache.axiom.om.util.StAXParserConfiguration,
                                 org.apache.axiom.om.OMXMLBuilderFactory -> 
org.apache.axiom.om.util.StAXParserConfiguration,

Modified: 
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java?rev=1846368&r1=1846367&r2=1846368&view=diff
==============================================================================
--- 
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
 (original)
+++ 
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
 Mon Nov 12 00:20:17 2018
@@ -20,6 +20,7 @@ package org.apache.axiom.om;
 
 import java.io.InputStream;
 import java.io.Reader;
+import java.text.ParseException;
 
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamReader;
@@ -29,12 +30,15 @@ import javax.xml.transform.sax.SAXSource
 
 import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
+import org.apache.axiom.mime.ContentType;
+import org.apache.axiom.mime.MediaType;
 import org.apache.axiom.mime.MultipartBody;
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPModelBuilder;
 import org.apache.axiom.soap.SOAPProcessingException;
+import org.apache.axiom.soap.SOAPVersion;
 import org.apache.axiom.util.stax.XMLStreamReaderUtils;
 import org.w3c.dom.EntityReference;
 import org.w3c.dom.Node;
@@ -714,11 +718,16 @@ public class OMXMLBuilderFactory {
      */
     public static SOAPModelBuilder createSOAPModelBuilder(OMMetaFactory 
metaFactory,
             MultipartBody message) {
-        String type = 
message.getRootPart().getContentType().getParameter("type");
+        MediaType type;
+        try {
+            type = new 
ContentType(message.getRootPart().getContentType().getParameter("type")).getMediaType();
+        } catch (ParseException ex) {
+            throw new OMException("Failed to parse root part content type", 
ex);
+        }
         SOAPFactory soapFactory;
-        if ("text/xml".equalsIgnoreCase(type)) {
+        if (type.equals(SOAPVersion.SOAP11.getMediaType())) {
             soapFactory = metaFactory.getSOAP11Factory();
-        } else if ("application/soap+xml".equalsIgnoreCase(type)) {
+        } else if (type.equals(SOAPVersion.SOAP12.getMediaType())) {
             soapFactory = metaFactory.getSOAP12Factory();
         } else {
             throw new OMException("Unable to determine SOAP version");

Modified: webservices/axiom/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/pom.xml?rev=1846368&r1=1846367&r2=1846368&view=diff
==============================================================================
--- webservices/axiom/trunk/pom.xml (original)
+++ webservices/axiom/trunk/pom.xml Mon Nov 12 00:20:17 2018
@@ -535,6 +535,16 @@
                 <artifactId>jaxb-runtime</artifactId>
                 <version>2.3.1</version>
             </dependency>
+            <dependency>
+                <groupId>org.eclipse.jetty</groupId>
+                <artifactId>jetty-server</artifactId>
+                <version>9.4.12.v20180830</version>
+            </dependency>
+            <dependency>
+                <groupId>org.eclipse.jetty</groupId>
+                <artifactId>jetty-webapp</artifactId>
+                <version>9.4.12.v20180830</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 
@@ -740,6 +750,11 @@
                     <version>0.1</version>
                 </plugin>
                 <plugin>
+                    <groupId>com.github.veithen.maven</groupId>
+                    <artifactId>wsimport-maven-plugin</artifactId>
+                    <version>0.3-SNAPSHOT</version>
+                </plugin>
+                <plugin>
                     <groupId>org.codehaus.mojo</groupId>
                     <artifactId>aspectj-maven-plugin</artifactId>
                     <version>1.11</version>

Propchange: webservices/axiom/trunk/systests/jaxws-tests/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Nov 12 00:20:17 2018
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target

Added: webservices/axiom/trunk/systests/jaxws-tests/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/systests/jaxws-tests/pom.xml?rev=1846368&view=auto
==============================================================================
--- webservices/axiom/trunk/systests/jaxws-tests/pom.xml (added)
+++ webservices/axiom/trunk/systests/jaxws-tests/pom.xml Mon Nov 12 00:20:17 
2018
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License. You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied. See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.ws.commons.axiom</groupId>
+        <artifactId>systests</artifactId>
+        <version>1.3.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>jaxws-tests</artifactId>
+    <packaging>jar</packaging>
+
+    <name>JAX-WS Tests</name>
+    <description>
+        Tests interoperability with the JAX-WS reference implementation.
+    </description>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>axiom-impl</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.xml.ws</groupId>
+            <artifactId>jaxws-rt</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.truth</groupId>
+            <artifactId>truth</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-server</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-webapp</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.github.veithen.maven</groupId>
+                <artifactId>wsimport-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>generate-test-sources</goal>
+                        </goals>
+                        <configuration>
+                            <wsdlFiles>
+                                
<wsdlFile>src/test/wsdl/image-upload.wsdl</wsdlFile>
+                            </wsdlFiles>
+                            <generateService>true</generateService>
+                            <extension>true</extension>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Propchange: webservices/axiom/trunk/systests/jaxws-tests/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/systests/jaxws-tests/src/test/java/MTOMTest.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/systests/jaxws-tests/src/test/java/MTOMTest.java?rev=1846368&view=auto
==============================================================================
--- webservices/axiom/trunk/systests/jaxws-tests/src/test/java/MTOMTest.java 
(added)
+++ webservices/axiom/trunk/systests/jaxws-tests/src/test/java/MTOMTest.java 
Mon Nov 12 00:20:17 2018
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import static com.google.common.truth.Truth.assertThat;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.soap.MTOMFeature;
+
+import org.apache.axiom.mime.MultipartBody;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPMessage;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.example.ImageService;
+import org.example.ImageServicePort;
+import org.junit.Test;
+
+public class MTOMTest {
+    /**
+     * Regression test for <a 
href="https://issues.apache.org/jira/browse/AXIOM-492";>AXIOM-492</a>.
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testSOAP12() throws Exception {
+        Server server = new Server();
+        ServerConnector connector = new ServerConnector(server);
+        connector.setPort(0);
+        server.setConnectors(new Connector[] { connector });
+        ServletContextHandler handler = new ServletContextHandler(server, "/");
+        HttpServlet servlet = new HttpServlet() {
+            @Override
+            protected void doPost(HttpServletRequest request, 
HttpServletResponse response)
+                    throws ServletException, IOException {
+                MultipartBody mp = MultipartBody.builder()
+                        .setInputStream(request.getInputStream())
+                        .setContentType(request.getContentType())
+                        .build();
+                OMXMLBuilderFactory.createSOAPModelBuilder(mp);
+                SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
+                SOAPMessage message = factory.createDefaultSOAPMessage();
+                OMElement responseElement = factory.createOMElement(
+                        "uploadImageResponse", 
factory.createOMNamespace("http://example.org/";, "ns"),
+                        message.getSOAPEnvelope().getBody());
+                factory.createOMElement("return", null, 
responseElement).setText("OK");
+                
response.setContentType(factory.getSOAPVersion().getMediaType().toString());
+                try {
+                    message.serialize(response.getOutputStream());
+                } catch (XMLStreamException ex) {
+                    throw new ServletException(ex);
+                }
+            }
+        };
+        ServletHolder servletHolder = new ServletHolder(servlet);
+        servletHolder.setName("test");
+        servletHolder.setInitOrder(1);
+        handler.addServlet(servletHolder, "/");
+        server.start();
+        try {
+            ImageServicePort imageService = new 
ImageService().getImageServicePort(new MTOMFeature());
+            ((BindingProvider)imageService).getRequestContext().put(
+                    BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+                    String.format("http://localhost:%d/";, 
connector.getLocalPort()));
+            assertThat(imageService.uploadImage(new 
byte[4096])).isEqualTo("OK");
+        } finally {
+            server.stop();
+        }
+    }
+}

Propchange: 
webservices/axiom/trunk/systests/jaxws-tests/src/test/java/MTOMTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/axiom/trunk/systests/jaxws-tests/src/test/wsdl/image-upload.wsdl
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/systests/jaxws-tests/src/test/wsdl/image-upload.wsdl?rev=1846368&view=auto
==============================================================================
--- 
webservices/axiom/trunk/systests/jaxws-tests/src/test/wsdl/image-upload.wsdl 
(added)
+++ 
webservices/axiom/trunk/systests/jaxws-tests/src/test/wsdl/image-upload.wsdl 
Mon Nov 12 00:20:17 2018
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License. You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied. See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<definitions 
+        xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"; 
+        xmlns:tns="http://example.org/"; 
+        xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
+        xmlns="http://schemas.xmlsoap.org/wsdl/"; 
+        targetNamespace="http://example.org/"; 
+        name="ImageServerImplService">
+    <types></types>
+    <message name="uploadImage">
+        <part name="data" type="xsd:base64Binary"></part>
+    </message>
+    <message name="uploadImageResponse">
+        <part name="return" type="xsd:string"></part>
+    </message>
+    <portType name="ImageServicePort">
+        <operation name="uploadImage">
+            <input message="tns:uploadImage"></input>
+            <output message="tns:uploadImageResponse"></output>
+        </operation>
+    </portType>
+    <binding name="ImageServiceBinding" type="tns:ImageServicePort">
+        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"; 
style="rpc"/>
+        <operation name="uploadImage">
+            <soap12:operation soapAction=""/>
+            <input>
+                <soap12:body use="literal" namespace="http://example.org/"/>
+            </input>
+            <output>
+                <soap12:body use="literal" namespace="http://example.org/"/>
+            </output>
+        </operation>
+    </binding>
+    <service name="ImageService">
+        <port name="ImageServicePort" binding="tns:ImageServiceBinding">
+            <soap12:address location="http://localhost:9999/ws/image"/>
+        </port>
+    </service>
+</definitions>

Modified: webservices/axiom/trunk/systests/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/systests/pom.xml?rev=1846368&r1=1846367&r2=1846368&view=diff
==============================================================================
--- webservices/axiom/trunk/systests/pom.xml (original)
+++ webservices/axiom/trunk/systests/pom.xml Mon Nov 12 00:20:17 2018
@@ -35,6 +35,7 @@
         <module>compat-tests</module>
         <module>cross-om-tests</module>
         <module>eclipse-tests</module>
+        <module>jaxws-tests</module>
         <module>wildfly-tests</module>
         <module>old-tests</module>
         <module>osgi-tests</module>

Modified: webservices/axiom/trunk/testing/spring-ws-testsuite/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/spring-ws-testsuite/pom.xml?rev=1846368&r1=1846367&r2=1846368&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/spring-ws-testsuite/pom.xml (original)
+++ webservices/axiom/trunk/testing/spring-ws-testsuite/pom.xml Mon Nov 12 
00:20:17 2018
@@ -54,12 +54,10 @@
         <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-server</artifactId>
-            <version>9.4.12.v20180830</version>
         </dependency>
         <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-webapp</artifactId>
-            <version>9.4.12.v20180830</version>
         </dependency>
         <dependency>
             <groupId>org.springframework</groupId>


Reply via email to