Jakarta XML Web Services (formely Java API for XML Web Services) is a Jakarta EE API for creating web services, particularly SOAP services, JAX-WS is one of the Java XML programming APIs.
The JAX-WS 2.2 specification JSR 224 defines a standard Java-to-WSDL (Web Services Description Language) mapping which determines how WSDL operations are bound to Java methods when a SOAP (Simple Object Access Protocol) message invokes a WSDL operation. This Java-to-WSDL mapping determines which Java method gets invoked and how that SOAP message is mapped to the method’s parameters. This mapping also determines how the JAX-WS uses annotations, introduced in Java SE 5, to simplify the development and deployment of web service clients and endpoints. JAX-WS can be used in Java SE, starting with version 6. JAX-WS 2.0 replaced the JAX-RPC API in Java EE5.
Main JWS packages are listed in the table below :
Package | Description |
javax.xml.ws | Has the Core JAX-WS APIs |
javax.xml.ws.http | Has APIs specific to XML/HTTP Binding |
javax.xml.ws.soap | Has APIs specific to SOAP/HTTP Binding |
javax.xml.ws.handler | Has APIs for message handlers |
javax.xml.ws.spi | Defines SPIs for JAX-WS |
javax.xml.ws.spi.http | Provides HTTP SPI that is used for portable deployment of JAX-WS in containers |
javax.xml.ws.wsaddressing | Has APIs related to WS-Addressing |
javax.jws | Has APIs specific to Java to WSDL mapping annotations |
javax.jws.soap | Has APIs for mapping the Web Service onto the SOAP protocol |
As it was mentioned above, SOAP is an XML specification for sending messages over a network. SOAP messages are independent of any operating system and can use a variety of communication protocols, including HTTP and SMTP. SOAP is XML heavy, hence best used with tools/frameworks.
There are two ways of building SOAP web services : top-down approach or bottom-up approach. In a top-down (contract-first) approach a WSDL document is created, and the necessary Java classes are generated from the WSDL. In a bottom-up (contract-last) approach the Java classes are written and the WSDL is generated from the Java classes.
WSDL is a contract definition of the available services. It is a specification of input/output messages, and how to invoke the web service. It is language neutral and is defined in XML.
Major elements of a WSDL document are :
Definitions : the definitions element is the root element of all WSDL documents. It defines the name, the namespace, etc. of the service, it is rather spacious. For example :
<definitions xmlns:wsu=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd“
xmlns:wsp=”http://www.w3.org/ns/ws-policy“
xmlns:wsp1_2=”http://schemas.xmlsoap.org/ws/2004/09/policy“
xmlns:wsam=”http://www.w3.org/2007/05/addressing/metadata“
xmlns:soap=”http://schemas.xmlsoap.org/wsdl/soap/“
xmlns:tns=”http://jaxwsexample.company.com/“
xmlns:xsd=”http://www.w3.org/2001/XMLSchema“
xmlns=”http://schemas.xmlsoap.org/wsdl/“
targetNamespace=”http://jaxwsexample.company.com/“
name=”HelloManService“>
…
</definitions>
Types : the types element defines the data types used by the web service. WSDL uses XSD (XML Schema Definition) as the type system which helps with interoperability.
Messages : the message element provides an abstract definition of the data being transmitted. Each message element describes the input or output of a service method and the possible exceptions. For example :