You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by em...@apache.org on 2018/05/07 15:01:24 UTC
[cxf] branch 3.1.x-fixes updated: [CXF-7736]:DispatchImpl doesn't
work for an empty Source
This is an automated email from the ASF dual-hosted git repository.
ema pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
new 73486d7 [CXF-7736]:DispatchImpl doesn't work for an empty Source
73486d7 is described below
commit 73486d7981129aabba35a869d2466dd0f69fd837
Author: Jim Ma <em...@apache.org>
AuthorDate: Mon May 7 22:58:00 2018 +0800
[CXF-7736]:DispatchImpl doesn't work for an empty Source
---
.../java/org/apache/cxf/endpoint/ClientImpl.java | 24 ++++++-
.../java/org/apache/cxf/jaxws/DispatchImpl.java | 7 +-
.../apache/cxf/systest/soap/EmptySOAPBodyTest.java | 38 ++++++++++-
.../cxf/systest/soap/EmptySoapProviderServer.java | 74 ++++++++++++++++++++++
4 files changed, 136 insertions(+), 7 deletions(-)
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 6d2c8ce..14c4f19 100644
--- a/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
+++ b/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
@@ -658,9 +658,9 @@ public class ClientImpl
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) {
@@ -1130,5 +1130,23 @@ public class ClientImpl
}
}
+
+ 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 843bfa3..aa60039 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.common.util.StringUtils;
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;
@@ -317,13 +318,13 @@ public class DispatchImpl<T> implements Dispatch<T>, BindingProvider, Closeable
}
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 9d0b6e2..346ae93 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.feature.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 class EmptySOAPBodyTest extends AbstractBusClientServerTestBase {
// 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 class EmptySOAPBodyTest extends AbstractBusClientServerTestBase {
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 0000000..223c0b8
--- /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();
+ }
+ }
+}
--
To stop receiving notification emails like this one, please contact
ema@apache.org.