Expose CXF Service With REST And SOAP

Expose CXF Service With REST And SOAP explains step by step details of Exposing restful / SOAP services using Apache CXF and Eclipse with spring framework

Apache CXF is a free and open source project, and a fully featured Webservice framework. It helps you building webservices using different front-end API's, like as JAX-RS (restful based services) and JAX-WS (WSDL based services).

By using this configuration, We can expose both restful / JAX-RS and JAX-WS services without any code change and helps you to re-use the same business logic

You can see the below example, which is demonstrate Exposing CXF Service With REST And SOAP

Required Libraries

You need to download

  1. JDK 7
  2. Eclipse 4.2
  3. CXF-2.7.3
  4. Tomcat 7

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. jaxb-impl-2.2.6.jar
  18. javax.ws.rs-api-2.0-m10.jar
  19. jettison-1.3.2.jar (JSON library)
  20. xmlschema-core-2.0.3.jar

Expose CXF Service With REST And SOAP

I am creating a sample restful and JAX-WS service that pass Student object and return with some changes on that object. The service is using simple POJO (Plain Old Java Object) bean.

Firstly create a Dynamic Web Project (File->New->Dynamic Web Project) named "CXFRestAndSoap" according to following screenshot

CXF Service With REST And SOAP Expose CXF Service With REST And SOAP

Create a Student Object

package com.student;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "Student")
public class Student {
private String name;

public String getName() {
return name;

public void setName(String name) {
this.name = name;

Here @XmlRootElement(name = "Student"), is a JAXB convention specifies that Student is XML document.

If you are specifies that @Produces("application/json") then Jettison library converts the JAXB to json text as response

1 2 3 Next

6 Responses to "Expose CXF Service With REST And SOAP"
  1. lacike 2012-04-10 07:48:58.0
  1. admin 2012-04-11 07:48:58.0
  1. mohan kumar 2012-04-13 07:48:58.0
  1. admin 2012-04-14 07:48:58.0
  1. Vero 2012-04-15 07:48:58.0
  1. kattoor 2012-04-16 07:48:58.0

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