Step-1
create a web project with maven support!!!!!!!!!!!!!!!!!!!
Step2-
pom.xml
<dependency>
<groupId>org.apache.cxf</groupId >
<artifactId>cxf-rt-frontend-jaxws </artifactId>
<version>${cxf.version}</version >
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId >
<artifactId>cxf-rt-frontend-jaxrs </artifactId>
<version>${cxf.version}</version >
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId >
<artifactId>cxf-rt-transports-http </artifactId>
<version>${cxf.version}</version >
</dependency>
Step-3
Create Endpoint/Provider/SEI
import com.frog.controller.model.Frog;
@WebService
public interface FrogSoapService {
@WebMethod
public String uploadFrog(Frog frog);
@WebMethod
public Frog findFrogId(String fid);
@WebMethod
public List<Frog> findFrogs();
}
Step-4
Writting the implementation
@WebService(endpointInterface = "com.frog.cxf.soap.web.service.FrogSoapService" )
//FrogSoapService = SEI
public class FrogSoapWebProvider implements FrogSoapService {
@Override
public String uploadFrog(Frog frog) {
// TODO Auto-generated method stub
return null;
}
}
Step-5
create on spring based xml
where define /register the web service to url-pattern
/WEB-INF/cxf-soap.xml
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
xmlns:jaxws="http://cxf.apache.org/jaxws "
xmlns:jaxrs="http://cxf.apache.org/jaxrs "
xsi:schemaLocation="
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint
id="bookShelfService"
implementor="com.aranin.weblog4j.services.BookShelfServiceImpl"
address="/bookshelfservice" />
</beans>
Step-6
Register web service inside the spring root web container which is manage by ContextLoaderListener
<!-- classpath:frogs-store.xml => src/main/resources/frogs-store.xml -->
<context-param>
<param-name>contextConfigLocation </param-name>
<param-value>classpath:frogs-store.xml /WEB-INF/cxf-soap.xml </param-value >
</context-param>
<!-- ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/WEB-INF/applicationContext.xml"); -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener </listener-class >
</listener>
Step-7
Define Front Controller which will forward web service request to web service container which is manage by spring container
<servlet>
<servlet-name>CXFServlet</servlet-name >
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>2</load-on-startup >
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name >
<url-pattern>/cxf/*</url-pattern >
</servlet-mapping>
Step-8
Accessing web service...................
http://localhost:8090/mobile-app-mvc/cxf
consuming soap web service
we need only wsdl URL
D:\NEW_WORKSPACE\workspace_java\mobile-app-consume-client-soap\src>
wsimport -keep -verbose http://localhost:8090/mobile-app-mvc/cxf/frogSoapProvider?wsdl -Xnocompile
No comments:
Post a Comment