Create CXF Client

Keywords : Generate CXF Client, How To Create A WSDL CXF Client, Generate Webservice Client With CXF, CXF Client, CXF JAX-WS Client, CXF SOAP Client, Consuming Web Services With CXF,

Create CXF Client Example explains step by step details of how to create a CXF web service client / wsdl soap client using Apache CXF WebService Framework

For Creating Apache CXF Client, We are using JaxWsProxyFactoryBean. The factory option is particular to CXF and it is non-standard. This will give you a great control over the endpoint.

The Other options like Wsimport tool available with JDK are standard but that will give you less control. For example you can add a logging interceptor in order to show the logs when accessing your service using JaxWsProxyFactoryBean.

For publishing a web service, you can follow this tutorial CXF Web Service Tutorial. This client is based on mentioned Tutorial

Note

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

Tools Needed For This Tutorial

You need to download following libraries in order to Generate 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. aopalliance-1.0.jar
  2. commons-logging-1.1.1.jar
  3. cxf-2.7.3.jar
  4. httpasyncclient-4.0-beta3.jar
  5. httpclient-4.2.1.jar
  6. httpcore-4.2.2.jar
  7. httpcore-nio-4.2.2.jar
  8. neethi-3.0.2.jar
  9. spring-aop-3.0.7.RELEASE.jar
  10. spring-asm-3.0.7.RELEASE.jar
  11. spring-beans-3.0.7.RELEASE.jar
  12. spring-context-3.0.7.RELEASE.jar
  13. spring-core-3.0.7.RELEASE.jar
  14. spring-expression-3.0.7.RELEASE.jar
  15. spring-web-3.0.7.RELEASE.jar
  16. wsdl4j-1.6.2.jar
  17. xmlschema-core-2.0.3.jar

Create CXF 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;

// CXF JAX-WS Client / Consuming Web Services With CXF

public final class StudentClient {

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

     
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

      factory.setServiceClass
(ChangeStudentDetails.class);
      factory.setAddress
("http://localhost:8080/CXFTutorial/ChangeStudent?wsdl");
      factory.getInInterceptors
().add(new LoggingInInterceptor());
      factory.getOutInterceptors
().add(new LoggingOutInterceptor());
      ChangeStudentDetails client =
(ChangeStudentDetails) factory.create();
      Student student =
new Student();
      student.setName
("Rockey");
      Student changeName = client.changeName
(student);
      System.out.println
("Server said: " + changeName.getName());
      System.exit
(0);
   
}
}
Output

Server said: Hello Rockey

 




Generate CXF Client How To Create A WSDL CXF Client Generate Webservice Client With CXF CXF Client CXF JAX-WS Client CXF SOAP Client Consuming Web Services With CXF

Comments (2)
21.10.2012 03:54:27 lacike
For all you that are wondering where to get the service class - just make a reference to server project classes folder in client project build path ;-)
23.10.2012 02:36:19 admin
Thanks for your suggestion, I have updated the post