CXF SOAP Without Spring

Create a Service Interface

This service interface will defines which methods of web service, to be invoked by the client

package com.student;

import javax.jws.WebService;

@WebService
public interface ChangeStudentDetails {
 
Student changeName(Student student);
}

Implement the Service Interface

Here we implement the service interface created on the previous step

package com.student;

import javax.jws.WebService;

@WebService(endpointInterface = "com.student.ChangeStudentDetails")
public class ChangeStudentDetailsImpl implements ChangeStudentDetails {
   
public Student changeName(Student student) {
     
student.setName("Hello "+student.getName());
     
return student;
   
}
}

Create a SimpleCXFNonSpringServlet

Here we are using SimpleCXFNonSpringServlet class in order to add service implementation class(ChangeStudentDetailsImpl)

package com.student;

import javax.servlet.ServletConfig;
import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.transport.servlet.CXFNonSpringServlet;

public class SimpleCXFNonSpringServlet extends CXFNonSpringServlet {

 
private static final long serialVersionUID = 1L;

 
@Override
 
public void loadBus(ServletConfig servletConfig) {
   
super.loadBus(servletConfig);
    Bus bus = getBus
();
    BusFactory.setDefaultBus
(bus);
    Endpoint.publish
("/ChangeStudent", new ChangeStudentDetailsImpl());
 
}
}

web.xml

<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
	<servlet>
		<display-name>SimpleCXFNonSpringServlet</display-name>
		<servlet-name>SimpleCXFNonSpringServlet</servlet-name>
		<servlet-class>com.student.SimpleCXFNonSpringServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>SimpleCXFNonSpringServlet</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>
</web-app>




Previous 1 2 3 Next








5 Responses to "CXF SOAP Without Spring"
  1. Roman 2012-10-04 10:10:47.0
  1. admin 2012-10-05 10:10:47.0
  1. Roman 2012-10-06 10:10:47.0
  1. Roman 2012-10-07 10:10:47.0
  1. sanjeev 2012-10-08 10:10:47.0

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