Author: alessio.soldano(a)jboss.com
Date: 2012-06-21 08:05:22 -0400 (Thu, 21 Jun 2012)
New Revision: 16420
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/ContinuationsTestCase.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/Endpoint.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/EndpointImpl.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/continuations/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/continuations/WEB-INF/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/continuations/WEB-INF/web.xml
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml
Log:
[JBWS-3409] Adding testcase for manual/direct usage of Apache CXF continuations api
Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml 2012-06-21
10:15:55 UTC (rev 16419)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml 2012-06-21
12:05:22 UTC (rev 16420)
@@ -84,6 +84,16 @@
prefix="WEB-INF/wsdl"/>
</war>
+ <!-- jaxws-cxf-continuations -->
+ <war warfile="${tests.output.dir}/test-libs/jaxws-cxf-continuations.war"
webxml="${tests.output.dir}/test-resources/jaxws/cxf/continuations/WEB-INF/web.xml">
+ <classes dir="${tests.output.dir}/test-classes">
+ <include
name="org/jboss/test/ws/jaxws/cxf/continuations/EndpointImpl*.class"/>
+ </classes>
+ <manifest>
+ <attribute name="Dependencies"
value="org.apache.cxf"/>
+ </manifest>
+ </war>
+
<!-- jaxws-cxf-endorse -->
<war warfile="${tests.output.dir}/test-libs/jaxws-cxf-endorse.war"
manifest="${tests.output.dir}/test-resources/jaxws/cxf/endorse/META-INF/MANIFEST.MF"
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/ContinuationsTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/ContinuationsTestCase.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/ContinuationsTestCase.java 2012-06-21
12:05:22 UTC (rev 16420)
@@ -0,0 +1,98 @@
+/*
+ * 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.cxf.continuations;
+
+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 with endpoint impl making
+ * direct use of Apache CXF continuations api
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 21-Jun-2012
+ */
+public class ContinuationsTestCase extends JBossWSTest
+{
+ private String endpointAddress = "http://" + getServerHost() +
":8080/jaxws-cxf-continuations";
+
+ public static Test suite()
+ {
+ return new JBossWSCXFTestSetup(ContinuationsTestCase.class,
"jaxws-cxf-continuations.war");
+ }
+
+ public void testAsyncEndpoint() throws Exception
+ {
+ QName serviceName = new QName("http://org.jboss.ws/cxf/continuations",
"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/continuations",
"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/cxf/continuations/Endpoint.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/Endpoint.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/Endpoint.java 2012-06-21
12:05:22 UTC (rev 16420)
@@ -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.cxf.continuations;
+
+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/continuations")
+@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/cxf/continuations/EndpointImpl.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/EndpointImpl.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/continuations/EndpointImpl.java 2012-06-21
12:05:22 UTC (rev 16420)
@@ -0,0 +1,102 @@
+/*
+ * 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.cxf.continuations;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+
+import javax.annotation.Resource;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.xml.ws.WebServiceContext;
+
+import org.apache.cxf.continuations.Continuation;
+import org.apache.cxf.continuations.ContinuationProvider;
+
+@WebService(name = "EndpointService", targetNamespace =
"http://org.jboss.ws/cxf/continuations")
+@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL,
parameterStyle = SOAPBinding.ParameterStyle.BARE)
+public class EndpointImpl
+{
+ private Executor executor = Executors.newCachedThreadPool();
+ private static final int TIMEOUT = 2000;
+
+ @Resource
+ WebServiceContext ctx;
+
+ public String echo(String user)
+ {
+ final ContinuationProvider cp = (ContinuationProvider)
ctx.getMessageContext().get(ContinuationProvider.class.getName());
+ final Continuation c = cp.getContinuation();
+ if (c.isNew())
+ {
+ FutureTask<String> task = new FutureTask<String>(new
MyCallable(user, c));
+ c.setObject(task);
+ executor.execute(task);
+ c.suspend(TIMEOUT);
+ }
+ else
+ {
+ @SuppressWarnings("unchecked")
+ FutureTask<String> task = (FutureTask<String>) c.getObject();
+ if (task.isDone())
+ {
+ try
+ {
+ return task.get();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ c.suspend(TIMEOUT);
+ }
+ return null;
+ }
+
+ private class MyCallable implements Callable<String>
+ {
+
+ private String user;
+ private Continuation c;
+
+ public MyCallable(String user, Continuation c)
+ {
+ this.user = user;
+ this.c = c;
+ }
+
+ @Override
+ public String call() throws Exception
+ {
+ try {
+ //long running process...
+ System.out.println("user: " + user);
+ return user + " (ASYNC)";
+ } finally {
+ c.resume();
+ }
+ }
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/continuations/WEB-INF/web.xml
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/continuations/WEB-INF/web.xml
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/continuations/WEB-INF/web.xml 2012-06-21
12:05:22 UTC (rev 16420)
@@ -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.cxf.continuations.EndpointImpl</servlet-class>
+ <async-supported>true</async-supported>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>AsynchService</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>