You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/04/05 22:58:42 UTC
svn commit: r1310072 - in
/cxf/trunk/distribution/src/main/release/samples/jaxws_async: ./
src/main/java/demo/hw/client/ src/main/java/demo/hw/server/
src/main/webapp/ src/main/webapp/WEB-INF/
Author: dkulp
Date: Thu Apr 5 20:58:41 2012
New Revision: 1310072
URL: http://svn.apache.org/viewvc?rev=1310072&view=rev
Log:
Update the jaxws_async sample to also show server side async handling
and provide a war build to show the same thing in tomcat.
Added:
cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/
cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/
cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/cxf-servlet.xml (with props)
cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/web.xml (with props)
Modified:
cxf/trunk/distribution/src/main/release/samples/jaxws_async/README.txt
cxf/trunk/distribution/src/main/release/samples/jaxws_async/pom.xml
cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/java/demo/hw/client/Client.java
cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/java/demo/hw/server/GreeterImpl.java
Modified: cxf/trunk/distribution/src/main/release/samples/jaxws_async/README.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jaxws_async/README.txt?rev=1310072&r1=1310071&r2=1310072&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/jaxws_async/README.txt (original)
+++ cxf/trunk/distribution/src/main/release/samples/jaxws_async/README.txt Thu Apr 5 20:58:41 2012
@@ -6,6 +6,15 @@ invocation model. Please refer to the JA
(http://jcp.org/aboutJava/communityProcess/pfd/jsr224/index.html)
for background.
+This demo also illustrates the use of CXF specific server side
+asynchronous handling. The JAX-WS specification only addresses
+asynchronous requests on the Client side. This demo shows how to
+enable CXF to call upon the asynchronous methods to allow processing
+on separate threads.
+
+
+Client Side Asynchronous models
+===============================
The asynchronous model allows the client thread to continue after
making a two-way invocation without being blocked while awaiting a
response from the server. Once the response is available, it is
@@ -33,6 +42,31 @@ baggage. In order to enable generation o
a bindings file (wsdl/async_bindings.xml) is passed
to the wsdl2java generator.
+Server Side Asynchronous models
+===============================
+CXF provides two methods of handling requests asynchronously
+on the server side.
+- Continuations: CXF provides an API that a developer can use
+to create a Continuation, suspend the request, resume it later,
+etc... For more details, see:
+ http://sberyozkin.blogspot.com/2008/12/continuations-in-cxf.html
+
+- @UseAsyncMethod annotation: You can annotation the Impls
+synchronous method with the @UseAsyncMethod annotation. If possible,
+CXF will instead call the async method (as generated for the client
+above) with an AsyncHandler object that you can call back on when
+the response is ready.
+
+This sample uses the second method (much simpler). When using the
+-Pserver profile to run the server, it will use the embedded Jetty
+server which supports the Continuations that are needed and you will
+see logs mentioning it is responding asynchronously. When
+deploying a war, if you deploy to a Servlet 3 container (such as
+Tomcat 7), you will also see those logs. If you deploy to a
+Servlet 2.5 container, continuations are not available and the
+synchronous methods will be called.
+
+
Please review the README in the samples directory before
continuing.
@@ -48,6 +82,18 @@ Using either UNIX or Windows:
mvn -Pserver (from one command line window)
mvn -Pclient (from a second command line window)
+If you're using Tomcat for the web service provider:
+----------------------------------------------------
+You can manually copy the generated WAR file to the Tomcat webapps folder, or, if you
+have Maven and Tomcat set up to use the Tomcat Maven Plugin (http://mojo.codehaus.org/tomcat-maven-plugin/)
+you can use the mvn tomcat:redeploy command instead.
+
+To run the client against the Tomcat deployed war, run:
+
+ mvn -Pclient -Dwsdl.location='http://localhost:9000/jaxws_async-CXF_VERSION/services/SoapContext/SoapPort?wsdl'
+
+replacing the CXF_VERSION text in the URL with the version of CXF you are using.
+
To remove the code generated from the WSDL file and the .class
files, run "mvn clean".
Modified: cxf/trunk/distribution/src/main/release/samples/jaxws_async/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jaxws_async/pom.xml?rev=1310072&r1=1310071&r2=1310072&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/jaxws_async/pom.xml (original)
+++ cxf/trunk/distribution/src/main/release/samples/jaxws_async/pom.xml Thu Apr 5 20:58:41 2012
@@ -23,6 +23,7 @@
<name>JAX-WS Asynchronous Demo using Document/Literal Style</name>
<description>JAX-WS Asynchronous Demo using Document/Literal Style</description>
<version>2.6.0-SNAPSHOT</version>
+ <packaging>war</packaging>
<parent>
<groupId>org.apache.cxf.samples</groupId>
@@ -32,6 +33,7 @@
<properties>
<cxf.version>${project.version}</cxf.version>
+ <wsdl.location>${basedir}/wsdl/hello_world_async.wsdl</wsdl.location>
</properties>
<build>
<plugins>
@@ -95,6 +97,14 @@
</plugin>
</plugins>
</build>
+ <dependencies>
+ <!-- Jetty is needed if you're using the CXFServlet -->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-jetty</artifactId>
+ <version>2.6.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
</profile>
<profile>
<id>client</id>
@@ -113,7 +123,7 @@
<configuration>
<mainClass>demo.hw.client.Client</mainClass>
<arguments>
- <argument>${basedir}/wsdl/hello_world_async.wsdl</argument>
+ <argument>${wsdl.location}</argument>
</arguments>
</configuration>
</execution>
@@ -134,11 +144,10 @@
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.6.0-SNAPSHOT</version>
</dependency>
- <!-- Jetty is needed if you're using the CXFServlet -->
<dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-transports-http-jetty</artifactId>
- <version>2.6.0-SNAPSHOT</version>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>3.0.7.RELEASE</version>
</dependency>
</dependencies>
</project>
Modified: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/java/demo/hw/client/Client.java
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/java/demo/hw/client/Client.java?rev=1310072&r1=1310071&r2=1310072&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/java/demo/hw/client/Client.java (original)
+++ cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/java/demo/hw/client/Client.java Thu Apr 5 20:58:41 2012
@@ -21,6 +21,7 @@
package demo.hw.client;
import java.io.File;
+import java.net.URL;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -47,10 +48,15 @@ public final class Client {
System.out.println("please specify wsdl");
System.exit(1);
}
-
+ URL url = null;
File wsdl = new File(args[0]);
+ if (wsdl.exists() && wsdl.isFile()) {
+ url = wsdl.toURI().toURL();
+ } else {
+ url = new URL(args[0]);
+ }
- SOAPService ss = new SOAPService(wsdl.toURL(), SERVICE_NAME);
+ SOAPService ss = new SOAPService(url, SERVICE_NAME);
ExecutorService executor = Executors.newFixedThreadPool(5);
ss.setExecutor(executor);
GreeterAsync port = ss.getSoapPort();
Modified: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/java/demo/hw/server/GreeterImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/java/demo/hw/server/GreeterImpl.java?rev=1310072&r1=1310071&r2=1310072&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/java/demo/hw/server/GreeterImpl.java (original)
+++ cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/java/demo/hw/server/GreeterImpl.java Thu Apr 5 20:58:41 2012
@@ -27,6 +27,8 @@ import javax.jws.WebService;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.Response;
+import org.apache.cxf.annotations.UseAsyncMethod;
+import org.apache.cxf.jaxws.ServerAsyncResponse;
import org.apache.hello_world_async_soap_http.GreeterAsync;
import org.apache.hello_world_async_soap_http.types.GreetMeSometimeResponse;
@@ -42,16 +44,29 @@ public class GreeterImpl implements Gree
/* (non-Javadoc)
* @see org.apache.hello_world_soap_http.Greeter#greetMeSometime(java.lang.String)
*/
+ @UseAsyncMethod
public String greetMeSometime(String me) {
- LOG.info("Executing operation greetMeSometime");
- System.out.println("Executing operation greetMeSometime\n");
+ LOG.info("Executing operation greetMeSometime synchronously");
+ System.out.println("Executing operation greetMeSometime synchronously\n");
return "How are you " + me;
}
- public Future<?> greetMeSometimeAsync(String requestType,
- AsyncHandler<GreetMeSometimeResponse> asyncHandler) {
- return null;
- /*not called */
+ public Future<?> greetMeSometimeAsync(final String me,
+ final AsyncHandler<GreetMeSometimeResponse> asyncHandler) {
+ LOG.info("Executing operation greetMeSometimeAsync asynchronously");
+ System.out.println("Executing operation greetMeSometimeAsync asynchronously\n");
+ final ServerAsyncResponse<GreetMeSometimeResponse> r = new ServerAsyncResponse<GreetMeSometimeResponse>();
+ new Thread() {
+ public void run() {
+ GreetMeSometimeResponse resp = new GreetMeSometimeResponse();
+ resp.setResponseType("How are you " + me);
+ r.set(resp);
+ System.out.println("Responding on background thread\n");
+ asyncHandler.handleResponse(r);
+ }
+ } .start();
+
+ return r;
}
public Response<GreetMeSometimeResponse> greetMeSometimeAsync(String requestType) {
Added: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/cxf-servlet.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/cxf-servlet.xml?rev=1310072&view=auto
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/cxf-servlet.xml (added)
+++ cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/cxf-servlet.xml Thu Apr 5 20:58:41 2012
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:jaxws="http://cxf.apache.org/jaxws"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
+
+ <jaxws:endpoint id="SoapService" address="/SoapContext/SoapPort"
+ implementor="demo.hw.server.GreeterImpl">
+ </jaxws:endpoint>
+
+</beans>
Propchange: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/cxf-servlet.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/cxf-servlet.xml
------------------------------------------------------------------------------
svn:executable = *
Propchange: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/cxf-servlet.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/cxf-servlet.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/web.xml?rev=1310072&view=auto
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/web.xml (added)
+++ cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/web.xml Thu Apr 5 20:58:41 2012
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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">
+ <display-name>cxf</display-name>
+
+ <servlet>
+ <servlet-name>cxf</servlet-name>
+ <display-name>cxf</display-name>
+ <description>Apache CXF Endpoint</description>
+ <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ <async-supported>true</async-supported>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>cxf</servlet-name>
+ <url-pattern>/services/*</url-pattern>
+ </servlet-mapping>
+
+ <session-config>
+ <session-timeout>60</session-timeout>
+ </session-config>
+
+</web-app>
+
Propchange: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/distribution/src/main/release/samples/jaxws_async/src/main/webapp/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml