"Apache CXF is an open source services framework. CXF helps you build and develop services using frontend programming APIs, like JAX-WS and JAX-RS. These services can speak a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP, or CORBA and work over a variety of transports such as HTTP, JMS or JBI." -- http://cxf.apache.org/
Previously CXF is known as Xfire -
"User's looking to use XFire on a new project, should use CXF instead. CXF is a continuation of the XFire project and is considered XFire 2.0. It has many new features, a ton of bug fixes, and is now JAX-WS compliant! XFire will continue to be maintained through bug fix releases, but most development will occur on CXF now" -- http://xfire.codehaus.org/
If you are looking for sample webservice application using Xfire
refer - http://atgkid.blogspot.com/2012/01/to-develop-sample-webservice.html
Below are the steps to create a sample web service "AdditionWebService" (by using CXF) which takes input 2 numbers and returns sum of those numbers as response.
As mentioned in To develop sample webservice application using Xfire - Follow same steps for creating webservice project using eclipse & Java classes.
With CXF - refer http://cxf.apache.org/docs/writing-a-service-with-spring.html for more info
No need to have In /<Project-Name>/WebContent/META-INF/xfire/services.xml
Instead we need to have /<Project-Name>/WebContent/WEB-INF/cxf-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint
id="AddService"
implementor="com.test.service.AdditionWebServiceImpl"
address="/AddService" />
</beans>
And in /<Project-Name>/WebContent/WEB-INF/web.xmlxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint
id="AddService"
implementor="com.test.service.AdditionWebServiceImpl"
address="/AddService" />
</beans>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
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_2_5.xsd">
<display-name>TestWebService</display-name>
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
dependencies & libraries needed for cxfxmlns: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_2_5.xsd">
<display-name>TestWebService</display-name>
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
Download http://www.apache.org/dyn/closer.cgi?path=/cxf/2.5.1/apache-cxf-2.5.1.zip, once you extract you will find all libs mentioned below in \apache-cxf-2.5.1\lib
Thats it once you have done above steps, build war using export functionality in eclipse (refer To develop sample webservice application using Xfire)
Once war is created deploy & to generate wsdl go to http://localhost:8080/<context>/services/<address-mentioned-in-cfx-servlet.xml>?wsdl
For example - http://localhost:8080/TestWebService/services/AddService?wsdl
To test using SOAP UI -
Follow same steps mentioned in " To develop sample webservice application using Xfire" to develop Java client.
No comments:
Post a Comment