JAX-WS Francesco Ierna
JAX-WS JAX-WS  : is a programming model that simplifies application development through support of a standard, annotation-based model to develop Web Service applications and clients. Replace the remote procedures call programming as defined by JAX-RPC
Both servlet endpoints and EJB endpoints can have an object implementing the  WebServiceContext  interface injected using the @Resource annotation
Allows developers to write message-oriented as well as RPC-oriented web services
With JAX-WS, the developer does  not generate or parse SOAP messages
the platform independence of the Java programming language beacuse jax-ws uses techology definined by the W3C :  HTTP, SOAP and WSDL
Overview
Features Features : Better platform indipendent
Annotations  : supports the use of annotations.  Sempliies  development of web services
Much easier to expose  method as web services
Webservices.xml is optional  and  overrides  all the information in a file class java Called both  synchronously  and  asynchronously Asynchronously :  Future<?> getCreditScoreAsync(Customer customer, AsyncHandler<Score> handler); Using resource injection  : The application server also supports the usage of the  @Resource   or  @WebServiceRef  annotation to declare JAX-WS managed clients and to request injection of JAX-WS services and ports
Data Binding  : JAX-WS leverages the Java Architecture for XML Binding (JAXB) 2.1 API and tools as the binding technology for mappings between Java objects and XML documents.
Support for MTOM  : can send binary attachments such as images or files along with Web services requests
Support for SOAP 1.2  : JAX-WS supports both SOAP 1.1 and SOAP 1.2
Development tools  : JAX-WS provides the  wsgen   and  wsimport   command-line tools for generating portable artifacts for JAX-WS Web services
Support for WS-Addressing (JAX-WS 2.1) :  The new API enables you to create, transmit and use endpoint references to target a specific Web service endpoint
Support for JAX-WS 2.1 features :  JAX-WS 2.1 introduces the concept of features as a way to programmatically control certain functions or behaviors
Development MessageContext Using a  WebServiceContext  object,  the endpoint have access to basic security mechanisms of  JavaEE
Both servlet endpoints and EJB endpoints can have an object implementing the  WebServiceContext  interface injected using the @Resource annotation
Development Java Class : @WebServices on java class No @WebMethod -> all method expose to be a web services method
@WebMethod -> only the methods annotates with @WebMethod will be exposed  to be a web services method
We can exclude some methods by annotating the method with the property exclude   setted to true into the @WebMethod annotation Interface Is mapped  in portType within the WSDL file Method Is mapped to a  wsdl:operation element  in the corrisponding  wsdl:portType plus one or more  wsdl:message  elements
Development Example JAX-WS  HelloWorld  SEI: @WebService(name = &quot;HelloWorld&quot;, targetNamespace = &quot;urn:samples.ibm.com/HelloWorld&quot;) public interface HelloWorld { @WebMethod (action = &quot;urn:samples.ibm.com/HelloWorld/hello&quot;) @WebResult (name = &quot;response&quot;, targetNamespace = &quot;&quot;) @RequestWrapper (localName = &quot; hello &quot;, targetNamespace =  &quot;urn:samples.ibm.com/HelloWorld&quot;, className = &quot;com.ibm.samples.helloworld.Hello&quot;) @ResponseWrapper (localName = &quot; helloResponse &quot;, targetNamespace = &quot;urn:samples.ibm.com/HelloWorld&quot;, className =  &quot;com.ibm.samples.helloworld.HelloResponse&quot;) public String hello( @WebParam(name = &quot;name&quot;, targetNamespace = &quot;&quot;) String name);} <wsdl:types> <xsd:schema targetNamespace=&quot;urn:helloWorld/sample/ibm/com&quot;...> <xsd:element name=&quot;hello&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;helloResponse&quot; type=&quot;xsd:string&quot;/> </xsd:schema> </wsdl:types> <wsdl:message name=&quot; helloRequestMsg &quot;> <wsdl:part element=&quot;tns:hello&quot; name=&quot;helloParameters&quot; /> </wsdl:message> <wsdl:message name=&quot; helloResponseMsg &quot;> <wsdl:part element=&quot;tns:helloResponse&quot; name=&quot;helloResult&quot; /> </wsdl:message>
WSDL Services

SCDJWS 5. JAX-WS

  • 1.
  • 2.
    JAX-WS JAX-WS  :is a programming model that simplifies application development through support of a standard, annotation-based model to develop Web Service applications and clients. Replace the remote procedures call programming as defined by JAX-RPC
  • 3.
    Both servlet endpointsand EJB endpoints can have an object implementing the WebServiceContext interface injected using the @Resource annotation
  • 4.
    Allows developers towrite message-oriented as well as RPC-oriented web services
  • 5.
    With JAX-WS, thedeveloper does not generate or parse SOAP messages
  • 6.
    the platform independenceof the Java programming language beacuse jax-ws uses techology definined by the W3C : HTTP, SOAP and WSDL
  • 7.
  • 8.
    Features Features : Betterplatform indipendent
  • 9.
    Annotations  : supportsthe use of annotations. Sempliies development of web services
  • 10.
    Much easier toexpose method as web services
  • 11.
    Webservices.xml is optional and overrides all the information in a file class java Called both synchronously and asynchronously Asynchronously : Future<?> getCreditScoreAsync(Customer customer, AsyncHandler<Score> handler); Using resource injection  : The application server also supports the usage of the @Resource or @WebServiceRef annotation to declare JAX-WS managed clients and to request injection of JAX-WS services and ports
  • 12.
    Data Binding  :JAX-WS leverages the Java Architecture for XML Binding (JAXB) 2.1 API and tools as the binding technology for mappings between Java objects and XML documents.
  • 13.
    Support for MTOM : can send binary attachments such as images or files along with Web services requests
  • 14.
    Support for SOAP1.2  : JAX-WS supports both SOAP 1.1 and SOAP 1.2
  • 15.
    Development tools  :JAX-WS provides the wsgen and wsimport command-line tools for generating portable artifacts for JAX-WS Web services
  • 16.
    Support for WS-Addressing(JAX-WS 2.1) : The new API enables you to create, transmit and use endpoint references to target a specific Web service endpoint
  • 17.
    Support for JAX-WS2.1 features : JAX-WS 2.1 introduces the concept of features as a way to programmatically control certain functions or behaviors
  • 18.
    Development MessageContext Usinga WebServiceContext object, the endpoint have access to basic security mechanisms of JavaEE
  • 19.
    Both servlet endpointsand EJB endpoints can have an object implementing the WebServiceContext interface injected using the @Resource annotation
  • 20.
    Development Java Class :@WebServices on java class No @WebMethod -> all method expose to be a web services method
  • 21.
    @WebMethod -> onlythe methods annotates with @WebMethod will be exposed to be a web services method
  • 22.
    We can excludesome methods by annotating the method with the property exclude setted to true into the @WebMethod annotation Interface Is mapped in portType within the WSDL file Method Is mapped to a wsdl:operation element in the corrisponding wsdl:portType plus one or more wsdl:message elements
  • 23.
    Development Example JAX-WS HelloWorld SEI: @WebService(name = &quot;HelloWorld&quot;, targetNamespace = &quot;urn:samples.ibm.com/HelloWorld&quot;) public interface HelloWorld { @WebMethod (action = &quot;urn:samples.ibm.com/HelloWorld/hello&quot;) @WebResult (name = &quot;response&quot;, targetNamespace = &quot;&quot;) @RequestWrapper (localName = &quot; hello &quot;, targetNamespace = &quot;urn:samples.ibm.com/HelloWorld&quot;, className = &quot;com.ibm.samples.helloworld.Hello&quot;) @ResponseWrapper (localName = &quot; helloResponse &quot;, targetNamespace = &quot;urn:samples.ibm.com/HelloWorld&quot;, className = &quot;com.ibm.samples.helloworld.HelloResponse&quot;) public String hello( @WebParam(name = &quot;name&quot;, targetNamespace = &quot;&quot;) String name);} <wsdl:types> <xsd:schema targetNamespace=&quot;urn:helloWorld/sample/ibm/com&quot;...> <xsd:element name=&quot;hello&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;helloResponse&quot; type=&quot;xsd:string&quot;/> </xsd:schema> </wsdl:types> <wsdl:message name=&quot; helloRequestMsg &quot;> <wsdl:part element=&quot;tns:hello&quot; name=&quot;helloParameters&quot; /> </wsdl:message> <wsdl:message name=&quot; helloResponseMsg &quot;> <wsdl:part element=&quot;tns:helloResponse&quot; name=&quot;helloResult&quot; /> </wsdl:message>
  • 24.