Author: alessio.soldano(a)jboss.com
Date: 2010-09-30 12:41:01 -0400 (Thu, 30 Sep 2010)
New Revision: 13049
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/AddressingTestCase.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/ServiceIface.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/ServiceImpl.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/jaxws/SayHello.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsa/WEB-INF/wsdl/AddressingService.wsdl
Log:
Improving wsa sample, adding a testcase using client with decoupledEndpoint
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/AddressingTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/AddressingTestCase.java 2010-09-30
09:27:48 UTC (rev 13048)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/AddressingTestCase.java 2010-09-30
16:41:01 UTC (rev 13049)
@@ -21,13 +21,21 @@
*/
package org.jboss.test.ws.jaxws.samples.wsa;
+import java.net.SocketTimeoutException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
import javax.xml.ws.soap.AddressingFeature;
import junit.framework.Test;
+
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.endpoint.ClientImpl;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.jboss.wsf.test.JBossWSTest;
import org.jboss.wsf.test.JBossWSTestSetup;
@@ -60,7 +68,7 @@
ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class, new
AddressingFeature());
((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
serviceURL);
// invoke method
- assertEquals("Hello World!", proxy.sayHello());
+ assertEquals("Hello World!", proxy.sayHello("World"));
}
/**
@@ -77,7 +85,46 @@
Service service = Service.create(wsdlURL, serviceName);
ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
// invoke method
- assertEquals("Hello World!", proxy.sayHello());
+ assertEquals("Hello World!", proxy.sayHello("World"));
}
+ /**
+ * This shows the usage of decoupled-endpoint for getting back response on a new http
connection.
+ * The CXF client basically creates a destination listening at the provided decoupled
endpoint address, using the
+ * configured http transport factory. The client gets back a HTTP 202 accept response
message immediately after
+ * the call to the server, then once the actual response comes back to the decoupled
endpoint, the client is
+ * notified and returns control to the application code.
+ *
+ * @throws Exception
+ */
+ public void testDecoupledEndpointForLongLastingProcessingOfInvocations() throws
Exception
+ {
+ // construct proxy
+ QName serviceName = new
QName("http://www.jboss.org/jbossws/ws-extensions/wsaddressing",
"AddressingService");
+ URL wsdlURL = new URL(serviceURL + "?wsdl");
+ Service service = Service.create(wsdlURL, serviceName);
+ ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
+
+ Client client = ClientProxy.getClient(proxy);
+ HTTPConduit conduit = (HTTPConduit)client.getConduit();
+ HTTPClientPolicy policy = conduit.getClient();
+ //set low connection and receive timeouts to ensure the http client can't keep
the connection open till the response is received
+ policy.setConnectionTimeout(5000); //5 secs
+ policy.setReceiveTimeout(10000); //10 secs
+ //please note you might want to set the synchronous timeout for long waits, as CXF
ClientImpl would simply drop waiting for the response after that (default 60 secs)
+// ((ClientImpl)client).setSynchronousTimeout(value);
+
+ try {
+ proxy.sayHello("Sleepy"); //this takes at least 30 secs
+ fail("Timeout exception expected");
+ } catch (WebServiceException e) {
+ assertTrue(e.getCause() instanceof SocketTimeoutException);
+ }
+
+
policy.setDecoupledEndpoint("http://localhost:18181/jaxws-samples-wsa/decoupled-endpoint");
+ String response = proxy.sayHello("Sleepy"); //this takes at least 30
secs... but now the client doesn't time out
+ assertEquals("Hello Sleepy!", response);
+ }
+
+
}
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/ServiceIface.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/ServiceIface.java 2010-09-30
09:27:48 UTC (rev 13048)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/ServiceIface.java 2010-09-30
16:41:01 UTC (rev 13049)
@@ -22,7 +22,11 @@
package org.jboss.test.ws.jaxws.samples.wsa;
import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebResult;
import javax.jws.WebService;
+import javax.xml.ws.RequestWrapper;
+import javax.xml.ws.ResponseWrapper;
@WebService
(
@@ -30,6 +34,10 @@
)
public interface ServiceIface
{
+ @WebResult(name = "return", targetNamespace = "")
+ @RequestWrapper(localName = "sayHello", targetNamespace =
"http://www.jboss.org/jbossws/ws-extensions/wsaddressing", className =
"org.jboss.test.ws.jaxws.samples.wsa.jaxws.SayHello")
@WebMethod
- String sayHello();
+ @ResponseWrapper(localName = "sayHelloResponse", targetNamespace =
"http://www.jboss.org/jbossws/ws-extensions/wsaddressing", className =
"org.jboss.test.ws.jaxws.samples.wsa.jaxws.SayHelloResponse")
+ public String sayHello(@WebParam(name = "name", targetNamespace =
"") String name);
+
}
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/ServiceImpl.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/ServiceImpl.java 2010-09-30
09:27:48 UTC (rev 13048)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/ServiceImpl.java 2010-09-30
16:41:01 UTC (rev 13049)
@@ -24,6 +24,8 @@
import javax.jws.WebService;
import javax.xml.ws.soap.Addressing;
+import org.apache.log4j.Logger;
+
@WebService
(
portName = "AddressingServicePort",
@@ -35,8 +37,23 @@
@Addressing(enabled=true, required=true)
public class ServiceImpl implements ServiceIface
{
- public String sayHello()
+ private Logger log = Logger.getLogger(this.getClass());
+
+ public String sayHello(String name)
{
- return "Hello World!";
+ if ("Sleepy".equals(name))
+ {
+ try
+ {
+ log.info("Sleeping...");
+ Thread.sleep(30 * 1000);
+ log.info("...end of sleeping.");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return "Hello " + name + "!";
}
}
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/jaxws/SayHello.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/jaxws/SayHello.java 2010-09-30
09:27:48 UTC (rev 13048)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsa/jaxws/SayHello.java 2010-09-30
16:41:01 UTC (rev 13049)
@@ -23,16 +23,58 @@
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
- * This class was generated by the CXF 2.0.5-incubator
- * Mon Apr 21 16:36:02 CEST 2008
- * Generated source version: 2.0.5-incubator
+ * <p>Java class for sayHello complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within
this class.
+ *
+ * <pre>
+ * <complexType name="sayHello">
+ * <complexContent>
+ * <restriction
base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="name"
type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
*/
-@XmlRootElement(name = "sayHello", namespace =
"http://www.jboss.org/jbossws/ws-extensions/wsaddressing")
@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "sayHello", namespace =
"http://www.jboss.org/jbossws/ws-extensions/wsaddressing")
+@XmlType(name = "sayHello", propOrder =
+{"name"})
+public class SayHello
+{
+ protected String name;
-public class SayHello {}
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value)
+ {
+ this.name = value;
+ }
+
+}
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsa/WEB-INF/wsdl/AddressingService.wsdl
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsa/WEB-INF/wsdl/AddressingService.wsdl 2010-09-30
09:27:48 UTC (rev 13048)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsa/WEB-INF/wsdl/AddressingService.wsdl 2010-09-30
16:41:01 UTC (rev 13049)
@@ -4,7 +4,9 @@
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.jboss.org/jbossws/ws-extensions/wsaddressing&q...
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://www.jboss.org/jbossws/ws-extensions/wsaddres...
<xsd:element name="sayHello" type="tns:sayHello"/>
<xsd:complexType name="sayHello">
-<xsd:sequence/>
+<xsd:sequence>
+<xsd:element minOccurs="0" name="name"
type="xsd:string"/>
+</xsd:sequence>
</xsd:complexType>
<xsd:element name="sayHelloResponse"
type="tns:sayHelloResponse"/>
<xsd:complexType name="sayHelloResponse">