Create CXF Client

For Creating Apache CXF Client, We are using org.apache.cxf.jaxws.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 org.apache.cxf.jaxws.JaxWsProxyFactoryBean.

Required Libraries

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

  • JDK 6
  • Eclipse 3.7
  • CXF-2.7.3
  • Tomcat 7 (Deploying Web Service)

Following jar must be in classpath

  • commons-logging-1.1.1.jar
  • cxf-2.7.3.jar
  • httpasyncclient-4.0-beta3.jar
  • httpclient-4.2.1.jar
  • httpcore-4.2.2.jar
  • httpcore-nio-4.2.2.jar
  • neethi-3.0.2.jar
  • spring-aop-3.0.7.RELEASE.jar
  • spring-asm-3.0.7.RELEASE.jar
  • spring-beans-3.0.7.RELEASE.jar
  • spring-context-3.0.7.RELEASE.jar
  • spring-core-3.0.7.RELEASE.jar
  • spring-expression-3.0.7.RELEASE.jar
  • spring-web-3.0.7.RELEASE.jar
  • wsdl4j-1.6.2.jar
  • 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值