7.19. JAX-WS

JAX-WS (Java API for XML-Based Web Services) is a standard for implementing WSDL interfaces in Java. Major parts of the standard are a mapping from WSDL to Java, a mapping from Java to WSDL, and the associated interfaces for publishing services and creating proxies.

In the mappings, WSDL port types correspond to Java interfaces and WSDL operations to Java methods, types are mapped using the JAXB standard.

Figure 7.39. Mapping Example Java Input

package com.example;

@WebService
public interface StockQuoteProvider {
  float getPrice (String tickerSymbol)
    throws TickerException;
}

// Example adjusted from JAX-WS 2.2 Specification.

Figure 7.40. Mapping Example WSDL Output (Document Style)

<types>
  <xsd:schema targetNamespace="...">
    <xsd:element name="getPrice" type="tns:getPriceType"/>
    <xsd:element name="getPriceResponse" type="tns:getPriceResponseType"/>
    <xsd:element name="TickerException" type="tns:TickerExceptionType"/>
    ...
  </xsd:schema>
</types>

<message name="getPrice">
  <part name="getPrice" element="tns:getPrice"/>
</message>
<message name="getPriceResponse">
  <part name="getPriceResponse" element="tns:getPriceResponse"/>
</message>
<message name="TickerException">
  <part name="TickerException" element="tns:TickerException"/>
</message>

<portType name="StockQuoteProvider">
  <operation name="getPrice">
    <input message="tns:getPrice" wsam:action="..."/>
    <output message="tns:getPriceResponse wsam:action="..."/>
    <fault message="tns:TickerException wsam:action="..."/>
  </operation>
</portType>

<!-- Example adjusted from JAX-WS 2.2 Specification. -->

Figure 7.41. Mapping Example WSDL Output (RPC Style)

<types>
  <xsd:schema targetNamespace="...">
    <xsd:element name="TickerException" type="tns:TickerExceptionType"/>
    ...
  </xsd:schema>
</types>

<message name="getPrice">
  <part name="tickerSymbol" type="xsd:string"/>
</message>
<message name="getPriceResponse">
  <part name="return" type="xsd:float"/>
</message>
<message name="TickerException">
  <part name="TickerException" element="tns:TickerException"/>
</message>

<portType name="StockQuoteProvider">
  <operation name="getPrice">
    <input message="tns:getPrice"/>
    <output message="tns:getPriceResponse"/>
    <fault message="tns:TickerException"/>
  </operation>
</portType>

<!-- Example adjusted from JAX-WS 2.2 Specification. -->