Java EE provides two different APIs JAX-WS and JAX-RS to support web services.
JAX-WS - Java EE provides the JAX-WS (Java API for XML Web Services) for building web services and clients for SOAP/XML based Web Services.
JAX-RS - Java EE provides the JAX-RS (Java API for RESTful Web Services) for building web services and clients for RESTful Web Services
Java EE provides the JAX-WS API to support Web Services that use XML-based protocols such as SOAP.
The JAX-WS API hides the complexity of SOAP messages and protocol from the developer. The JAX-WS API converts the API calls or requests to the corresponding SAOP messages, hence the developer does not have to generate or parse the SOAP messages programmatically.
JAX-WS uses the standard W3C technologies HTTP, SOAP and WSDL. A JAX-WS client can access a web service that is not running on Java platform and vice versa.
A service endpoint interface is a Java interface that declares the methods that a client can invoke on the web service. A service endpoint implementation is a class that implements the methods defined in the service endpoint interface.
Following are the key annotations used in a JAX-WS service endpoint implementation.
@WebService - A Java class is annotated as a JAX-WS web service endpoint using the @WebService annotation.
@WebMethod - A Java method is exposed to Web Service clients using the @WebMethod annotation.
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService
public class OrderService {
public OrderService() { ... }
@WebMethod
public String getOrder(String orderNumber) { ... }
}
JAX-RS endpoints have to follow certain requirements.
The JAX-WS API leverages the JAXB API and tools as the binding technology for mapping between Java objects and XML documents.
JAX-RS Web Services can be developed via either of the following approaches.
1. Develop a JAX-RS Web Service from a WSDL (Top-Down Development) - In this approach the JAX-RS Web Service is created from an existing WSDL file using JavaBeans. The base Web Service endpoint classes and interfaces are generated via the 'wsimport' tool provided in the JAX-RS API.
2. Develop a JAX-WS Web service from a JavaBean (bottom-up development) - In this approach the JAX-WS Web Service endpoint interfaces and classes are created first using annotations. After the Web Service endpoint interfaces and classes are created, the WSDL file is generated by using the 'wsgen' tool provided in the JAX-RS API.