• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

JAX-WS Basics

on

  • 2,716 views

JAX-WS is a simple way to create web services on the Java Platform

JAX-WS is a simple way to create web services on the Java Platform

Statistics

Views

Total Views
2,716
Views on SlideShare
2,681
Embed Views
35

Actions

Likes
3
Downloads
330
Comments
0

5 Embeds 35

http://wes-williams.blogspot.com 31
http://www.blogger.com 1
http://wes-williams.blogspot.com.au 1
http://wes-williams.blogspot.de 1
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    JAX-WS Basics JAX-WS Basics Presentation Transcript

    • JAX-WS Another Java Web Services Framework
    • Overview
      • Included in Java 6 Standard Edition
      • Available as download for Java 5
      • Annotation Based
      • Tools available for WSDL consumption
      • Development Approaches
        • Contract First (Top Down)
        • Code First (Bottom Up)
    • WAR Structure my.war index.jsp META-INF MANIFEST.MF WEB-INF classes com/mypackage/MyClass.class l ib some.jar web.xml sun-jaxws.xml
    • Web App Config WEB-INF/web.xml <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <web-app version=&quot;2.4&quot; xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;> <listener> <listenerclass> com.sun.xml.ws.transport.http.servlet.WSServletContextListener </listener-class> </listener> <servlet> <servlet-name>WSServlet</servlet-name> <servlet-class> com.sun.xml.ws.transport.http.servlet.WSServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>WSServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
    • Web Service Config 1 2 3 4 5 6 7 WEB-INF/sun-jaxws.xml <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'> <endpoint name=&quot;Hello&quot; implementation=&quot;com.blogspot.weswilliams.hello.ws.Hello&quot; url-pattern=&quot;/Hello&quot; /> </endpoints>
    • Minimal Service 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 package com.blogspot.weswilliams.hello.ws; import java.util.Date; import javax.jws.*; @WebService public class Hello { public Hello() { System.out.println(new Date() + &quot; - Ready to Say Hello&quot;); } public String sayHello(String name) { System.out.println(new Date() + &quot; - saying hello to &quot; + name); return &quot;Hello &quot; + name + &quot;!&quot;; } }
    • Minimal SOAP WSDL <?xml version='1.0' encoding='UTF-8'?> <definitions xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:tns=&quot;http://ws.hello.weswilliams.blogspot.com/&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;http://schemas.xmlsoap.org/wsdl/&quot; targetNamespace=&quot;http://ws.hello.weswilliams.blogspot.com/&quot; name=&quot;HelloService&quot; > <types> <xsd:schema> <xsd:import namespace=&quot;http://ws.hello.weswilliams.blogspot.com/&quot; schemaLocation=&quot;http://localhost:8080/hello/Hello?xsd=1&quot; /> </xsd:schema> </types> <message name=&quot;sayHello&quot;> <part name=&quot;parameters&quot; element=&quot;tns:sayHello&quot; /> </message> <message name=&quot;sayHelloResponse&quot;> <part name=&quot;parameters&quot; element=&quot;tns:sayHelloResponse&quot; /> </message> <portType name=&quot;Hello&quot;> <operation name=&quot;sayHello&quot;> <input message=&quot;tns:sayHello&quot; /> <output message=&quot;tns:sayHelloResponse&quot; /> </operation> </portType> <binding name=&quot;HelloPortBinding&quot; type=&quot;tns:Hello&quot;> <soap:binding transport=&quot;http://schemas.xmlsoap.org/soap/http&quot; style=&quot;document&quot; /> <operation name=&quot;sayHello&quot;> <soap:operation soapAction=&quot;&quot; /> <input> <soap:body use=&quot;literal&quot; /> </input> <output> <soap:body use=&quot;literal&quot; /> </output> </operation> </binding> <service name=&quot;HelloService&quot;> <port name=&quot;HelloPort&quot; binding=&quot;tns:HelloPortBinding&quot;> <soap:address location=&quot;http://localhost:8080/hello/Hello&quot; /> </port> </service> </definitions>
    • Minimal SOAP XSD <?xml version='1.0' encoding='UTF-8'?> <xs:schema xmlns:tns=&quot;http://ws.hello.weswilliams.blogspot.com/&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; version=&quot;1.0&quot; targetNamespace=&quot;http://ws.hello.weswilliams.blogspot.com/&quot;> <xs:element name=&quot;sayHello&quot; type=&quot;tns:sayHello&quot; /> <xs:element name=&quot;sayHelloResponse&quot; type=&quot;tns:sayHelloResponse&quot; /> <xs:complexType name=&quot;sayHello&quot;> <xs:sequence> <xs:element name=&quot;arg0&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot; /> </xs:sequence> </xs:complexType> <xs:complexType name=&quot;sayHelloResponse&quot;> <xs:sequence> <xs:element name=&quot;return&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot; /> </xs:sequence> </xs:complexType> </xs:schema> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
    • Minimal SOAP Message Request: <soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:ws=&quot;http://ws.hello.weswilliams.blogspot.com/&quot;> <soapenv:Header/> <soapenv:Body> <ws:sayHello> <!--Optional:--> <arg0>Wes</arg0> </ws:sayHello> </soapenv:Body> </soapenv:Envelope> Response: <S:Envelope xmlns:S=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;> <S:Body> <ns2:sayHelloResponse xmlns:ns2=&quot;http://ws.hello.weswilliams.blogspot.com/&quot;> <return>Hello Wes!</return> </ns2:sayHelloResponse> </S:Body> </S:Envelope> 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8
    • Customized Service Hello.java: package com.blogspot.weswilliams.hello2.ws; import javax.jws.*; @WebService(targetNamespace = &quot;http://wes-williams.blogspot.com/Hi&quot;) public interface Hello { @WebResult(name = &quot;sayHiMessage&quot;) @WebMethod(operationName = &quot;sayHi&quot;) public String sayHello(@WebParam(name = &quot;name&quot;) String name); } 1 2 3 4 5 6 7 8 9 10
    • Customized Implementation HelloImpl.java: package com.blogspot.weswilliams.hello2.ws; import javax.jws.WebService; import java.util.Date; @WebService(name = &quot;HiService&quot;, targetNamespace = &quot;http://wes-williams.blogspot.com/Hi&quot;, serviceName = &quot;HiService&quot;, endpointInterface = &quot;com.blogspot.weswilliams.hello2.ws.Hello&quot;) public class HelloImpl implements Hello { public HelloImpl() { System.out.println(new Date() + &quot; - Ready to Say Hi&quot;); } public String sayHello(String name) { System.out.println(new Date() + &quot; - saying hello to &quot; + name); return &quot;Hello &quot; + name + &quot;!&quot;; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
    • Configuration Difference WEB-INF/sun-jaxws.xml <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'> <endpoint name=&quot;Hello&quot; implementation=&quot;com.blogspot.weswilliams.hello2.ws.HelloImpl&quot; url-pattern=&quot;/Hello&quot; /> </endpoints> 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7
    • Customized WSDL <?xml version='1.0' encoding='UTF-8'?> <definitions xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:tns=&quot;http://wes-williams.blogspot.com/Hi&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;http://schemas.xmlsoap.org/wsdl/&quot; targetNamespace=&quot;http://wes-williams.blogspot.com/Hi&quot; name=&quot;HiService&quot;> <types> <xsd:schema> <xsd:import namespace=&quot;http://wes-williams.blogspot.com/Hi&quot; schemaLocation=&quot;http://localhost:8080/hello/Hello?xsd=1&quot; /> </xsd:schema> </types> <message name=&quot;sayHi&quot;> <part name=&quot;parameters&quot; element=&quot;tns:sayHi&quot; /> </message> <message name=&quot;sayHiResponse&quot;> <part name=&quot;parameters&quot; element=&quot;tns:sayHiResponse&quot; /> </message> <portType name=&quot;HiService&quot;> <operation name=&quot;sayHi&quot;> <input message=&quot;tns:sayHi&quot; /> <output message=&quot;tns:sayHiResponse&quot; /> </operation> </portType> <binding name=&quot;HiServicePortBinding&quot; type=&quot;tns:HiService&quot;> <soap:binding transport=&quot;http://schemas.xmlsoap.org/soap/http&quot; style=&quot;document&quot; /> <operation name=&quot;sayHi&quot;> <soap:operation soapAction=&quot;&quot; /> <input> <soap:body use=&quot;literal&quot; /> </input> <output> <soap:body use=&quot;literal&quot; /> </output> </operation> </binding> <service name=&quot;HiService&quot;> <port name=&quot;HiServicePort&quot; binding=&quot;tns:HiServicePortBinding&quot;> <soap:address location=&quot;http://localhost:8080/hello/Hello&quot; /> </port> </service> </definitions>
    • Customized XSD <?xml version='1.0' encoding='UTF-8'?> <xs:schema xmlns:tns=&quot;http://wes-williams.blogspot.com/Hi&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; version=&quot;1.0&quot; targetNamespace=&quot;http://wes-williams.blogspot.com/Hi&quot;> <xs:element name=&quot;sayHi&quot; type=&quot;tns:sayHi&quot; /> <xs:element name=&quot;sayHiResponse&quot; type=&quot;tns:sayHiResponse&quot; /> <xs:complexType name=&quot;sayHi&quot;> <xs:sequence> <xs:element name=&quot;name&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot; /> </xs:sequence> </xs:complexType> <xs:complexType name=&quot;sayHiResponse&quot;> <xs:sequence> <xs:element name=&quot;sayHiResult&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot; /> </xs:sequence> </xs:complexType> </xs:schema> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
    • Provide a Custom WSDL Hello.java: package com.blogspot.weswilliams.hello2.ws; import javax.jws.*; @WebService(name = &quot;HiService&quot;, targetNamespace = &quot;http://wes-williams.blogspot.com/Hi&quot;, wsdlLocation=&quot;WEB-INF/wsdl/HiService.wsdl&quot;) public interface Hello { @WebResult(name = &quot;sayHiMessage&quot;) @WebMethod(operationName = &quot;sayHi&quot;) public String sayHello(@WebParam(name = &quot;name&quot;) String name); } 1 2 3 4 5 6 7 8 9 10 11 12 13
    • Custom WSDL <?xml version='1.0' encoding='UTF-8'?> <definitions xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:tns=&quot;http://wes-williams.blogspot.com/Hi&quot; xmlns: xs =&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;http://schemas.xmlsoap.org/wsdl/&quot; targetNamespace=&quot;http://wes-williams.blogspot.com/Hi&quot; name=&quot;HiService&quot;> <types> < xs :schema xmlns:tns=&quot;http://wes-williams.blogspot.com/Hi&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; version=&quot;1.0&quot; targetNamespace=&quot;http://wes-williams.blogspot.com/Hi&quot;> <xs:element name=&quot;sayHi&quot; type=&quot;tns:sayHi&quot; /> <xs:element name=&quot;sayHiResponse&quot; type=&quot;tns:sayHiResponse&quot; /> <xs:complexType name=&quot;sayHi&quot;> <xs:sequence> <xs:element name=&quot;name&quot; type=&quot;xs:string&quot; /> </xs:sequence> </xs:complexType> <xs:complexType name=&quot;sayHiResponse&quot;> <xs:sequence> <xs:element name=&quot;sayHiMessage&quot; type=&quot;xs:string&quot; /> </xs:sequence> </xs:complexType> </ xs :schema> </types> . . . . . .
    • Customized Messages Request: <soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:hi=&quot;http://wes-williams.blogspot.com/Hi&quot;> <soapenv:Header/> <soapenv:Body> <hi:sayHi> <name>Wes</name> </hi:sayHi> </soapenv:Body> </soapenv:Envelope> Response: <S:Envelope xmlns:S=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;> <S:Body> <ns2:sayHiResponse xmlns:ns2=&quot;http://wes-williams.blogspot.com/Hi&quot;> <sayHiMessage>Hi Wes!</sayHiMessage> </ns2:sayHiResponse> </S:Body> </S:Envelope> 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7
    • Client Generation Generation: wsimport -keep -p <PACKAGE_FOR_CLIENT> -d <GENERATION_DIRECTORY> <WSDL_URL> Output: parsing WSDL... generating code... compiling code... Usage: import com.blogspot.weswilliams.hello2.ws.client.*; public class Test { public static void main(String[] args) { HiService hiClient = new HiService_Service().getHiServicePort(); System.out.println(hiClient.sayHi(&quot;Wes&quot;)); } } 1 2 3 4 5 6 7 8 9 10
    • More JAX-WS Resources General: https://jax-ws.dev.java.net/ http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/ Apache CFX: http://cfx.apache.org Related Resources: http://soapui.org Book Recommendation: O'Reily's Java Web Services: Up and Running wes-williams.blogspot.com