You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2018/06/13 12:36:25 UTC

[GitHub] dkulp closed pull request #423: CXF-7758 MTOM + SchemaValidation results in empty input stream from d…

dkulp closed pull request #423: CXF-7758 MTOM + SchemaValidation results in empty input stream from d…
URL: https://github.com/apache/cxf/pull/423
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/java/org/apache/cxf/helpers/ServiceUtils.java b/core/src/main/java/org/apache/cxf/helpers/ServiceUtils.java
index a4537a27cab..69c4b1d974e 100644
--- a/core/src/main/java/org/apache/cxf/helpers/ServiceUtils.java
+++ b/core/src/main/java/org/apache/cxf/helpers/ServiceUtils.java
@@ -108,30 +108,30 @@ private static SchemaValidationType getOverrideSchemaValidationType(Message mess
 
     private static SchemaValidationType getSchemaValidationTypeFromModel(Message message) {
         Exchange exchange = message.getExchange();
+        SchemaValidationType validationType = null;
 
         if (exchange != null) {
-            BindingOperationInfo boi = exchange.getBindingOperationInfo();
-            Endpoint endpoint = exchange.getEndpoint();
 
-            if (boi != null && endpoint != null) {
-                SchemaValidationType validationType = null;
+            BindingOperationInfo boi = exchange.getBindingOperationInfo();
+            if (boi != null) {
                 OperationInfo opInfo = boi.getOperationInfo();
-                EndpointInfo ep = endpoint.getEndpointInfo();
-
                 if (opInfo != null) {
                     validationType = getSchemaValidationTypeFromModel(opInfo);
+                }
+            }
 
-                    if (validationType == null && ep != null) {
+            if (validationType == null) {
+                Endpoint endpoint = exchange.getEndpoint();
+                if (endpoint != null) {
+                    EndpointInfo ep = endpoint.getEndpointInfo();
+                    if (ep != null) {
                         validationType = getSchemaValidationTypeFromModel(ep);
                     }
                 }
-
-                return validationType;
             }
         }
 
-        // else
-        return null;
+        return validationType;
     }
 
     private static SchemaValidationType getSchemaValidationTypeFromModel(
diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/AttachmentService.java b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/AttachmentService.java
new file mode 100644
index 00000000000..6acbf6c51e3
--- /dev/null
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/AttachmentService.java
@@ -0,0 +1,36 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.systest.jaxws.attachment;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.xml.bind.annotation.XmlElement;
+
+import org.apache.cxf.annotations.SchemaValidation;
+
+@WebService(name = "AttachmentService", targetNamespace = "http://org.apache.cxf/service/AttachmentService")
+@SchemaValidation(type = SchemaValidation.SchemaValidationType.IN)
+public interface AttachmentService {
+
+    @WebMethod
+    int test(@WebParam(name = "request") @XmlElement(required = true) Request request) throws Exception;
+
+}
diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/AttachmentServiceImpl.java b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/AttachmentServiceImpl.java
new file mode 100644
index 00000000000..b6a4511347f
--- /dev/null
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/AttachmentServiceImpl.java
@@ -0,0 +1,45 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.systest.jaxws.attachment;
+
+import java.io.InputStream;
+
+import javax.activation.DataHandler;
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.ws.soap.MTOM;
+
+import org.apache.cxf.annotations.SchemaValidation;
+import org.apache.cxf.helpers.IOUtils;
+
+@WebService(name = "AttachmentService", targetNamespace = "http://org.apache.cxf/service/AttachmentService")
+@SchemaValidation(type = SchemaValidation.SchemaValidationType.IN)
+@MTOM(enabled = true)
+public class AttachmentServiceImpl implements AttachmentService {
+
+    @WebMethod
+    public int test(@WebParam(name = "request") @XmlElement(required = true) Request request) throws Exception {
+        DataHandler dataHandler = request.getContent();
+        InputStream inputStream = dataHandler.getInputStream();
+        return IOUtils.readBytesFromStream(inputStream).length;
+    }
+}
diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/Request.java b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/Request.java
new file mode 100644
index 00000000000..b9f082076e7
--- /dev/null
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/Request.java
@@ -0,0 +1,45 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.systest.jaxws.attachment;
+
+import javax.activation.DataHandler;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "request", propOrder = {"content"})
+public class Request {
+
+    @XmlElement(name = "content", required = true)
+    private DataHandler content;
+
+    public Request() {
+    }
+
+    public DataHandler getContent() {
+        return content;
+    }
+
+    public void setContent(DataHandler content) {
+        this.content = content;
+    }
+}
diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/ValidationWithAttachmentTest.java b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/ValidationWithAttachmentTest.java
new file mode 100644
index 00000000000..cda53f20b9f
--- /dev/null
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/attachment/ValidationWithAttachmentTest.java
@@ -0,0 +1,83 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.systest.jaxws.attachment;
+
+import javax.activation.DataHandler;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.soap.SOAPBinding;
+
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
+import org.apache.cxf.testutil.common.TestUtil;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ValidationWithAttachmentTest {
+
+    static final String PORT = TestUtil.getNewPortNumber(ValidationWithAttachmentTest.class);
+    static final String ADDRESS = "http://localhost:" + PORT + "/" + ValidationWithAttachmentTest.class.getSimpleName();
+
+    static Server server;
+    static AttachmentService client;
+
+    @BeforeClass
+    public static void setUp() {
+        initServer();
+        initClient();
+    }
+
+    @AfterClass
+    public static void tearDown() {
+        server.stop();
+    }
+
+    @Test
+    public void test() throws Exception {
+        Request request = new Request();
+        request.setContent(new DataHandler("test", "text/plain"));
+
+        int bytes = client.test(request);
+        Assert.assertTrue("Attachment data were not received", bytes > 0);
+    }
+
+    private static void initServer() {
+        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
+        factory.setServiceClass(AttachmentServiceImpl.class);
+        factory.setAddress(ADDRESS);
+        factory.setServiceBean(new AttachmentServiceImpl());
+        server = factory.create();
+    }
+
+    private static void initClient() {
+        JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
+        clientFactory.setServiceClass(AttachmentService.class);
+        clientFactory.setAddress(ADDRESS);
+        client = (AttachmentService) clientFactory.create();
+
+        //enable MTOM in client
+        BindingProvider bp = (BindingProvider) client;
+        SOAPBinding binding = (SOAPBinding) bp.getBinding();
+        binding.setMTOMEnabled(true);
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services