CXF Asynchronous Client

CXF Asynchronous Client tells about creating a SOAP/WSDL asynchronous client using Apache CXF WebService Framework

There are two options available for receiving data through asynchronous calls from client with CXF.

1) Polling: the client application periodically polls a instance to check if the response is available
2) Callback: the client application implements the interface to accept notification of the response availability

Reference ->

Below we are showing examples for both approaches


For running this client you need to refer the classes created on Asynchronous Web Service Using CXF

Async client should be created after deploying the above service

Required Libraries

You need to download following libraries in order to Generate Asynchronous CXF Client

  1. JDK 6
  2. Eclipse 3.7
  3. CXF-2.7.3
  4. Tomcat 7 (Deploying Web Service)

Following jar must be in classpath

  1. commons-logging-1.1.1.jar
  2. cxf-2.7.3.jar
  3. httpasyncclient-4.0-beta3.jar
  4. httpclient-4.2.1.jar
  5. httpcore-4.2.2.jar
  6. httpcore-nio-4.2.2.jar
  7. neethi-3.0.2.jar
  8. spring-aop-3.0.7.RELEASE.jar
  9. spring-asm-3.0.7.RELEASE.jar
  10. spring-beans-3.0.7.RELEASE.jar
  11. spring-context-3.0.7.RELEASE.jar
  12. spring-core-3.0.7.RELEASE.jar
  13. spring-expression-3.0.7.RELEASE.jar
  14. spring-web-3.0.7.RELEASE.jar
  15. wsdl4j-1.6.2.jar
  16. xmlschema-core-2.0.3.jar

1. CXF Asynchronous Client Using Polling

The client application periodically checks (poll) whether response is available from the server.

package com.student.client;


import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.student.ChangeStudentDetails;
import com.student.Student;

public final class StudentClient {

public static void main(String args[]) throws Exception {

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

().add(new LoggingInInterceptor());
().add(new LoggingOutInterceptor());
        ChangeStudentDetails client =
(ChangeStudentDetails) factory.create();
// polling method
System.out.println("Invoking changeStudentAsync using polling...");
        Response<Student> changeStudentResp = client.changeStudentAsync
while (true) {
if (changeStudentResp.isDone()) {
Student reply = changeStudentResp.get();
("Server responded through polling with: "
+ reply.getName());
} else {
("Polling %%%%%%%%%%%%%%%");


Invoking changeStudentAsync using polling...
Polling %%%%%%%%%%%%%%%
Polling %%%%%%%%%%%%%%%
Polling %%%%%%%%%%%%%%%
Polling %%%%%%%%%%%%%%%
Polling %%%%%%%%%%%%%%%
Polling %%%%%%%%%%%%%%%
Polling %%%%%%%%%%%%%%%
Polling %%%%%%%%%%%%%%%
Polling %%%%%%%%%%%%%%%
Polling %%%%%%%%%%%%%%%
Polling %%%%%%%%%%%%%%%
Server responded through polling with: How are you Rockey

1 2 Next

Your email address will not be published. Required fields are marked *