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/05/07 12:42:50 UTC

[GitHub] jimma closed pull request #417: [CXF-7736]:DispatchImpl doesn't work for an empty Source

jimma closed pull request #417: [CXF-7736]:DispatchImpl doesn't work for an empty Source
URL: https://github.com/apache/cxf/pull/417
 
 
   

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/endpoint/ClientImpl.java b/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
index 799c26e0593..c4a3e8282d4 100644
--- a/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
+++ b/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
@@ -666,9 +666,9 @@ private void enrichFault(Fault fault) {
                 boi = boi.getWrappedOperation();
             }
             if (!boi.getOutput().getMessageParts().isEmpty()) {
-                //we were supposed to get some output, but didn't
-                throw new IllegalStateException("Response message did not contain proper response data. Expected: "
-                    + boi.getOutput().getMessageParts().get(0).getConcreteName());
+                //we were supposed to get some output, but didn't.
+                throw new IllegalEmptyResponseException("Response message did not contain proper response data."
+                    + " Expected: " + boi.getOutput().getMessageParts().get(0).getConcreteName());
             }
         }
         if (resList != null) {
@@ -1143,5 +1143,23 @@ public void setExecutor(Executor executor) {
         }
     }
 
+    
+    public class IllegalEmptyResponseException extends IllegalStateException {
+        public IllegalEmptyResponseException() {
+            super();
+        }
+
+        public IllegalEmptyResponseException(String message) {
+            super(message);
+        }
+
+        public IllegalEmptyResponseException(String message, Throwable cause) {
+            super(message, cause);
+        }
+
+        public IllegalEmptyResponseException(Throwable cause) {
+            super(cause);
+        }
+    }
 
 }
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
index 2e36c080c01..87e3ba2a310 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
@@ -71,6 +71,7 @@
 import org.apache.cxf.databinding.DataWriter;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.ClientCallback;
+import org.apache.cxf.endpoint.ClientImpl.IllegalEmptyResponseException;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.feature.Feature;
 import org.apache.cxf.helpers.DOMUtils;
@@ -318,12 +319,13 @@ public T invoke(T obj, boolean isOneWay) {
             Holder<T> holder = new Holder<T>(obj);
             opName = calculateOpName(holder, opName, hasOpName);
 
-            Object ret[] = client.invokeWrapped(opName,
-                                                holder.value);
+            Object ret[] = client.invokeWrapped(opName, holder.value);
             if (isOneWay || ret == null || ret.length == 0) {
                 return null;
             }
             return (T)ret[0];
+        } catch (IllegalEmptyResponseException ie) {
+            return null;
         } catch (Exception ex) {
             throw mapException(ex);
         }
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/EmptySOAPBodyTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/EmptySOAPBodyTest.java
index 9d0b6e206fe..5c7cf3e097b 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/EmptySOAPBodyTest.java
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/EmptySOAPBodyTest.java
@@ -19,18 +19,26 @@
 
 package org.apache.cxf.systest.soap;
 
+import java.io.StringReader;
 import java.net.URL;
 
 import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
 import javax.xml.ws.soap.SOAPFaultException;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.endpoint.ClientImpl.IllegalEmptyResponseException;
+import org.apache.cxf.ext.logging.LoggingFeature;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.hello_world_xml_http.bare.XMLService;
 import org.example.contract.doubleit.DoubleItPortType;
 
+import org.junit.Assert;
 import org.junit.BeforeClass;
 
 /**
@@ -50,6 +58,8 @@ public static void startServers() throws Exception {
             // set this to false to fork
             launchServer(EmptySOAPBodyServer.class, true)
         );
+        assertTrue("Server failed to launch",
+                   launchServer(EmptySoapProviderServer.class, true));
     }
 
     @org.junit.AfterClass
@@ -79,12 +89,38 @@ public void testPlaintext() throws Exception {
             fail("Should have thown an exception");
         } catch (SOAPFaultException t) {
             assertTrue("Wrong exception cause " + t.getCause(), 
-                 t.getCause() instanceof IllegalStateException);
+                 t.getCause() instanceof IllegalEmptyResponseException);
         }
 
         ((java.io.Closeable)port).close();
 
         bus.shutdown(true);
     }
+    
+    @org.junit.Test
+    public void testProviderSource() throws Exception {
+        QName providerServiceName = new QName("http://apache.org/hello_world_xml_http/bare",
+                                              "HelloProviderService");
+
+        QName providerPortName = new QName("http://apache.org/hello_world_xml_http/bare", "HelloProviderPort");
+
+        URL wsdl = new URL("http://localhost:" + EmptySoapProviderServer.REG_PORT
+                           + "/helloProvider/helloPort?wsdl");
+        assertNotNull(wsdl);
+
+        XMLService service = new XMLService(wsdl, providerServiceName, new LoggingFeature());
+        assertNotNull(service);
+        Dispatch<Source> dispatch = service.createDispatch(providerPortName, Source.class,
+                                                           javax.xml.ws.Service.Mode.PAYLOAD);
+
+        String str = new String("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>" 
+                              + "<ns2:in xmlns=\"http://apache.org/hello_world_xml_http/bare/types\""
+                              + " xmlns:ns2=\"http://apache.org/hello_world_xml_http/bare\">"
+                              + "<elem1>empty</elem1><elem2>this is element 2</elem2><elem3>42</elem3></ns2:in>"
+                              + "</soap:Body></soap:Envelope>");
+        StreamSource req = new StreamSource(new StringReader(str));
+        Source resSource = dispatch.invoke(req);
+        Assert.assertNull("null result is expected", resSource);
+    }
 
 }
\ No newline at end of file
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/EmptySoapProviderServer.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/EmptySoapProviderServer.java
new file mode 100644
index 00000000000..223c0b8759b
--- /dev/null
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/soap/EmptySoapProviderServer.java
@@ -0,0 +1,74 @@
+/**
+ * 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.soap;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.BindingType;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Provider;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceProvider;
+
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+public class EmptySoapProviderServer extends AbstractBusTestServerBase {
+    public static final String REG_PORT = allocatePort(EmptySoapProviderServer.class);
+
+    List<Endpoint> eps = new LinkedList<Endpoint>();
+
+    protected void run() {
+        String address = "http://localhost:" + REG_PORT + "/helloProvider/helloPort";
+        GreeterProvider provider = new GreeterProvider();
+        eps.add(Endpoint.publish(address, provider));
+    }
+
+    public void tearDown() {
+        while (!eps.isEmpty()) {
+            Endpoint ep = eps.remove(0);
+            ep.stop();
+        }
+    }
+
+    public static void main(String[] args) {
+        try {
+            EmptySoapProviderServer s = new EmptySoapProviderServer();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+    
+    @WebServiceProvider(serviceName = "HelloProviderService", 
+                        portName = "HelloProviderPort", 
+                        targetNamespace = "http://apache.org/hello_world_xml_http/bare")
+    @BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING)
+    @ServiceMode(value = javax.xml.ws.Service.Mode.PAYLOAD)
+    public class GreeterProvider implements Provider<Source> {
+        public Source invoke(Source req) {
+            return new StreamSource();
+        }
+    }
+}


 

----------------------------------------------------------------
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