JAX-WS (Java API for XML - Web Services) represents a Java API for implementing of webservices. The following example describes a basic usage based on Apache CXF and the Spring Framework.
First you implement the interface and the implementation class with JAX WS annotations:
@WebService(targetNamespace = "http://org.developers.blog.examples.jaxws")
//@XmlSeeAlso({TShirt.class, ...}) - map to WSDL Product.class derived subclasses
public interface IOrderService {
@WebMethod
void orderProducts(Long customerId, List products) throws OrderException;
}
@WebService (targetNamespace = "http://org.developers.blog.examples.jaxws",
endpointInterface =
"org.developers.blog.examples.jaxws.IOrderService")
public class OrderService implements IOrderService {
void orderProducts(Long customerId, List products) throws OrderException; {
//do ordering
}
}
Instrumentalisation code:
1. WEB-INF/webservices.xml:
<bean id="orderService" class="org.developers.blog.examples.jaxws.OrderService"/> <jaxws:endpoint id="orderEndpoint" implementor="#orderService" address="/OrderService"/>web.xml configuration:
2. WEB-INF/web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/webservices-ctx.xml
</param-value>
</context-param>
...
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
...
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/wsservices/*</url-pattern>
</servlet-mapping>
RegardsRafael Sobek
Technorati Tags: Java JAX-WS Apache CXF Spring
