CXF Restful Tutorial

CXF Restful Tutorial explains step by step details of Creating / Developing Java rest Web services using Apache CXF, Spring and Eclipse

JAX-RS is Java API for RESTful Webservices which is very rely upon Representational State Transfer model, you can view JAX-RS specification 

JAX-RS uses annotations for simplifying the development efforts.

Now a days more & more deployment is going based on restful services compare to WSDL Webservices, due to the weights towards the simplicity of configuration

You can see the below example, which is demonstrating How to create a Restful service using CXF

Note

You can also find tutorial about CXF With Jackson

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

CXF Restful Tutorial

I am creating a sample restful service project 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 "CXFRestfulTutorial" according to following screenshot

Create CXF Project CXF Restful Tutorial

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 convension 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





27 Responses to "CXF Restful Tutorial"
  1. Yevgeny Vasilyev 2012-01-02 07:26:05.0
  1. admin 2012-01-03 07:26:05.0
  1. pep 2012-01-04 07:26:05.0
  1. admin 2012-01-05 07:26:05.0
  1. Sony 2012-01-06 07:26:05.0
  1. Julien 2012-01-07 07:26:05.0
  1. admin 2012-01-08 07:26:05.0
  1. Ruchika 2012-01-09 07:26:05.0
  1. admin 2012-01-11 07:26:05.0
  1. steve 2012-01-12 07:26:05.0
  1. steve 2012-01-13 07:26:05.0
  1. admin 2012-01-14 07:26:05.0
  1. Madusha 2012-01-15 07:26:05.0
  1. admin 2012-01-16 07:26:05.0
  1. Deepak 2012-01-17 07:26:05.0
  1. admin 2012-01-18 07:26:05.0
  1. bibhu 2012-01-19 07:26:05.0
  1. admin 2012-01-20 07:26:05.0
  1. Ram 2012-01-21 07:26:05.0
  1. admin 2012-01-22 07:26:05.0
  1. madhu 2012-01-23 07:26:05.0
  1. admin 2012-01-24 07:26:05.0
  1. madhu 2012-01-25 07:26:05.0
  1. admin 2012-01-26 07:26:05.0
  1. madhu 2012-01-27 07:26:05.0
  1. terry 2012-01-28 07:26:05.0
  1. Shailendra 2012-01-29 07:26:05.0

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