Author: alessio.soldano(a)jboss.com
Date: 2012-06-21 06:15:55 -0400 (Thu, 21 Jun 2012)
New Revision: 16419
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/AsynchTestCase.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/Endpoint.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/EndpointImpl.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/asynch/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/asynch/WEB-INF/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/asynch/WEB-INF/web.xml
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml
Log:
[JBWS-3523] Adding testcase for server side async with CXF @UseAsynchMethod
Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml 2012-06-21
09:14:46 UTC (rev 16418)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml 2012-06-21
10:15:55 UTC (rev 16419)
@@ -38,6 +38,18 @@
<mkdir dir="${tests.output.dir}/test-libs"/>
+ <!-- jaxws-samples-asynch -->
+ <war
+ warfile="${tests.output.dir}/test-libs/jaxws-samples-asynch.war"
+
webxml="${tests.output.dir}/test-resources/jaxws/samples/asynch/WEB-INF/web.xml">
+ <classes dir="${tests.output.dir}/test-classes">
+ <include
name="org/jboss/test/ws/jaxws/samples/asynch/EndpointImpl*.class"/>
+ </classes>
+ <manifest>
+ <attribute name="Dependencies"
value="org.apache.cxf"/>
+ </manifest>
+ </war>
+
<!-- jaxws-samples-mtom -->
<war
warfile="${tests.output.dir}/test-libs/jaxws-samples-mtom.war"
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/AsynchTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/AsynchTestCase.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/AsynchTestCase.java 2012-06-21
10:15:55 UTC (rev 16419)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.samples.asynch;
+
+import java.net.URL;
+import java.util.concurrent.Future;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+import javax.xml.ws.Service;
+
+import junit.framework.Test;
+
+import org.jboss.wsf.test.JBossWSCXFTestSetup;
+import org.jboss.wsf.test.JBossWSTest;
+
+/**
+ * Asynchronous web services test case (both client and server side async)
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 21-Jun-2012
+ */
+public class AsynchTestCase extends JBossWSTest
+{
+ private String endpointAddress = "http://" + getServerHost() +
":8080/jaxws-samples-asynch";
+
+ public static Test suite()
+ {
+ return new JBossWSCXFTestSetup(AsynchTestCase.class,
"jaxws-samples-asynch.war");
+ }
+
+ public void testAsyncEndpoint() throws Exception
+ {
+ QName serviceName = new QName("http://org.jboss.ws/cxf/samples/asynch",
"EndpointImplService");
+ URL wsdlURL = new URL(endpointAddress + "?wsdl");
+ Service service = Service.create(wsdlURL, serviceName);
+ Endpoint proxy = service.getPort(Endpoint.class);
+ final String user = "Kermit";
+ //do something... then get the result
+ assertEquals(user + " (ASYNC)", proxy.echoAsync(user).get());
+ }
+
+ public void testAsyncEndpointUsingHandler() throws Exception
+ {
+ QName serviceName = new QName("http://org.jboss.ws/cxf/samples/asynch",
"EndpointImplService");
+ URL wsdlURL = new URL(endpointAddress + "?wsdl");
+ Service service = Service.create(wsdlURL, serviceName);
+ Endpoint proxy = service.getPort(Endpoint.class);
+ final String user = "Kermit";
+ TestAsyncHandler handler = new TestAsyncHandler();
+ Future<String> future = proxy.echoAsync(user, handler);
+ //do something... then get the result when it's ready
+ while (!future.isDone()) {
+ Thread.sleep(100);
+ }
+ assertEquals(user + " (ASYNC)", handler.getResponse());
+ }
+
+ private class TestAsyncHandler implements AsyncHandler<String> {
+
+ private String res;
+
+ @Override
+ public void handleResponse(Response<String> response) {
+ try {
+ res = response.get();
+ } catch (Exception e) {
+ e.printStackTrace();
+ res = e.getMessage();
+ }
+ }
+
+ public String getResponse() {
+ return res;
+ }
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/Endpoint.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/Endpoint.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/Endpoint.java 2012-06-21
10:15:55 UTC (rev 16419)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.samples.asynch;
+
+import java.util.concurrent.Future;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Response;
+
+@WebService(name = "EndpointService", targetNamespace =
"http://org.jboss.ws/cxf/samples/asynch")
+@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL,
parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
+public interface Endpoint
+{
+ @WebMethod
+ public String echo(String user);
+
+ //The following methods are added (or generated by wsconsume) for the sake of using
asynch jaxws client only
+
+ @WebMethod(operationName = "echo")
+ public Response<String> echoAsync(String user);
+
+ @WebMethod(operationName = "echo")
+ public Future<String> echoAsync(String user, AsyncHandler<String>
handler);
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/EndpointImpl.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/EndpointImpl.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/asynch/EndpointImpl.java 2012-06-21
10:15:55 UTC (rev 16419)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.samples.asynch;
+
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.xml.ws.AsyncHandler;
+
+import org.apache.cxf.annotations.UseAsyncMethod;
+
+@WebService(name = "EndpointService", targetNamespace =
"http://org.jboss.ws/cxf/samples/asynch")
+@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL,
parameterStyle = SOAPBinding.ParameterStyle.BARE)
+public class EndpointImpl
+{
+ //be sure to add dependency on org.apache.cxf module for @UseAsyncMethod annotation to
be resolved
+ @UseAsyncMethod //.. if supported by underlying container
+ public String echo(String user)
+ {
+ System.out.println("user: " + user);
+ return user + " (SYNC)";
+ }
+
+ //this method is not actually converted into an operation in the wsdl contract, as
it's up to the
+ //Apache CXF implementation to redirect invocation to this when the @UseAsyncMethod
annotated
+ //echo method is called.
+ public Future<?> echoAsync(final String user, final AsyncHandler<String>
asyncHandler)
+ {
+ final ServerAsyncResponse<String> r = new
ServerAsyncResponse<String>();
+ //here the business method would likely enqueue the request for a long running
process;
+ //then the queue might for instance be consumed by a different thread pool...
+ new Thread() {
+ public void run() {
+ r.set(user + " (ASYNC)");
+ System.out.println("Responding on background thread...");
+ asyncHandler.handleResponse(r);
+ }
+ }.start();
+ //the web container thread proceeds further and the container is able to serve new
web requests with it
+ return r;
+ }
+
+ //helper class
+ private class ServerAsyncResponse<T> implements javax.xml.ws.Response<T>
{
+ T value;
+ boolean done;
+ Throwable throwable;
+
+ /**
+ * Currently unused
+ */
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ return false;
+ }
+ /**
+ * Currently unused
+ */
+ public boolean isCancelled() {
+ return false;
+ }
+ public boolean isDone() {
+ return done;
+ }
+ public void set(T t) {
+ value = t;
+ done = true;
+ }
+ public T get() throws InterruptedException, ExecutionException {
+ if (throwable != null) {
+ throw new ExecutionException(throwable);
+ }
+ return value;
+ }
+ public T get(long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException {
+ return value;
+ }
+ /**
+ * Currently unused
+ */
+ public Map<String, Object> getContext() {
+ return null;
+ }
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/asynch/WEB-INF/web.xml
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/asynch/WEB-INF/web.xml
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/asynch/WEB-INF/web.xml 2012-06-21
10:15:55 UTC (rev 16419)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app
+ version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+ <servlet>
+ <servlet-name>AsynchService</servlet-name>
+
<servlet-class>org.jboss.test.ws.jaxws.samples.asynch.EndpointImpl</servlet-class>
+ <async-supported>true</async-supported>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>AsynchService</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>