Ntg web services

650 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
650
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Ntg web services

  1. 1. Web Services Farag Zakaria ITI-JAVA 30
  2. 2. Agenda• Web services concept.• Why web services?• When to use web services• Web services architecture• SOAP• WSDL• JAX-WS• JAX-WS vs. JAX-RPC• RESTful web services
  3. 3. Web services concept• Web service is a software system identified by a URI whose public interfaces and bindings are defined ,described and discovered by XML artifacts.(W3C)• Client server application• Application to application communication• Interoperability (standard communication)• Neutral (platform & language independent).
  4. 4. Agenda• Web services concept.• Why web services?• When to use web services• Web services architecture• SOAP• WSDL• JAX-WS• JAX-WS vs. JAX-RPC• RESTful web services
  5. 5. Why web services• Interoperability (SOAP messaging).• Economical (recycled components, no installation and tight integration of software).• Accessible (applications are exposed and accessed on the web.)• Available (services are on any device, any where, anytime.)• Scalable (no limit on scope of application and their number.)
  6. 6. Example
  7. 7. Agenda• Web services concept.• Why web services?• When to use web services?• Web services architecture• SOAP• WSDL• JAX-WS• JAX-WS vs. JAX-RPC• RESTful web services
  8. 8. When to use web services ?• Applications do not have severe restrictions on reliability and speed.• Cooperation among different application.• Upgrading services independently from clients without changing the WSDL.• Services can be easily expressed with simple request/response semantics and simple state•
  9. 9. Agenda• Web services concept.• Why web services?• When to use web services?• Web services architecture• SOAP• WSDL• JAX-WS• JAX-WS vs. JAX-RPC• RESTful web services
  10. 10. Web services architecture
  11. 11. Agenda• Web services concept.• Why web services?• When to use web services?• Web services architecture• SOAP• WSDL• JAX-WS• JAX-WS vs. JAX-RPC• RESTful web services
  12. 12. SOAP messaging
  13. 13. SOAP(Simple Object Access Protocol)• Define communication format between client and web service(XML message format).• Wire protocol extension for conveying RPC calls.• SOAP is not a transport protocol. You must attach your message to a transport mechanism like HTTP.
  14. 14. SOAP structure• A SOAP message is contained in an envelop.• The envelop element in turn contain (in order) 1. An optional header with one or more child entries. (security , transaction) 2. A body element that can contain one or more child entries. These child entries may contain arbitrary XML data.(application data)• Header entries may optionally have a “mustUnderstand” attribute. mustUnderstand=1 recipient must process header mustUnderstand=0 optional header•
  15. 15. SOAP structure(cont.)• The body contains the XML message that you are transmitting.• The message format is not specified by SOAP. The <Body></Body> tag pairs are just a way to notify the recipient that the actual XML message is contained therein. The recipient decides what to do with the message.
  16. 16. Agenda• Web services concept.• Why web services?• When to use web services?• Web services architecture• SOAP• WSDL• JAX-WS• JAX-WS vs. JAX-RPC• RESTful web services
  17. 17. WSDL(Web Service DescriptionLanguage)• Defines what your service does and how it is invoked.• Guideline for constructing SOAP message.• XML language for writing APIs(generating client code to use the web service).• Verbose
  18. 18. WSDL documents parts• Data definition (in XML) for custom types.• Abstract message definitions (request, response)• Organization of messages into “ports” and “operations” (classes and methods).• Protocol bindings (to SOAP, for example)• Service point locations (URLs)
  19. 19. WSDL document parts(cont.)
  20. 20. WSDL document parts(cont.)
  21. 21. WSDL document parts(Data Definition)
  22. 22. Agenda• Web services concept.• Why web services?• When to use web services?• Web services architecture• SOAP• WSDL• JAX-WS• JAX-WS vs. JAX-RPC• RESTful web services
  23. 23. JAX-WS• Simpler way to develop/deploy web services - POJO + Annotation. - No deployment descriptor is needed. - Layered programming model• Layered programming model - Server side - Client side - Business layer
  24. 24. Programming model(server side)• Write a POJO implementing the service• Add @WebService annotation to it• Deploy the application• Point your clients at the WSDL http://mysite/myapp/service.wsdl
  25. 25. Example(Server side)@WebService(name="AddNumbers", portName="CalculatorPort", serviceName="CalculatorService")public class NumbersWebService{ @WebMethod(operationName="add") @WebResult(name="result") public int add(@WebParam(name="first") int first, @WebParam(name="second") int second) { return first + second; }}
  26. 26. Programming model(client side)• You need to know the url of WSDL• Generate service classes and interfaces.• Create object from service class• Get a proxy using a get<ServiceName>Port method.• Invoke any remote operations.
  27. 27. Example(Client side)• CalculatorService service = new CalculatorServiceLocator(); AddNumbers calc = service.getCalculatorPort(); System.out.println(calc.add(3, 4));
  28. 28. Agenda• Web services concept.• Why web services?• When to use web services?• Web services architecture• SOAP• WSDL• JAX-WS• JAX-WS vs. JAX-RPC• RESTful web services
  29. 29. JAX-WS vs. JAX-RPC JAX-WS JAX-RPCMap to JAVA 1.5 and higher Map to JAVA 1.4Support SOAP 1.1 and SOAP 1.2 Support SOAP 1.1Data mapping model (JAXB) Has its own data mapping modelSupport MTOM through (JAXB)Asynchronous communication
  30. 30. JAX-WS Demo
  31. 31. RESTful web services
  32. 32. Agenda• REST Architecture principales• RESTful web services & WADL.• REST vs. Traditional web services• RESTful advantages
  33. 33. REST Architecture principales• Representational State Transfer.• Every thing is a resource.• Resources are addressable.• Resources have an interface(operations and data types).• Protocol is client-server, stateless, cacheable, layered.
  34. 34. Agenda• REST Architecture principales• RESTful web services & WADL.• REST vs. Traditional web services• RESTful advantages
  35. 35. RESTful web services & WADL.• REST applied to web services. - web service accessible through URI. - operations are HTTP primitives(PUT,GET,..). - Web services returns a MIME type(XML, JSON, …).• More resource efficient than SOAP• RESTful web services - java class + annotations (for URI, operations, Data types).
  36. 36. RESTful web services & WADL.(cont.)• Annotations - @Path(“”) for URI of service. - @GET,@POST,.. for Http methods. - @Produces(“…”) to define format of returned data - @Consumes (“…”) to define format of accepted input data
  37. 37. RESTful web services & WADL.(cont.)<servlet> <servlet-name>ServletAdaptor</servlet-name> <servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer </servlet-class> <load-on-startup>1</load-on-startup></servlet><servlet-mapping> <servlet-name>ServletAdaptor</servlet-name> <url-pattern>/resources/*</url-pattern></servlet-mapping>
  38. 38. RESTful web services & WADL.(cont.)@Path("/hello")@Consumes("text/html")public class RESTWSTest{ @GET @Produces("text/html") public String sayHello(@QueryParam("name") String name) { return "<html><body><h1>Hello " + name + "</h1></body></html>"; }}
  39. 39. RESTful web services & WADL.(cont.)• WADL web application description language. - easy to understand. - HTTP assumed.• XML-based language.• Development language + platform neutral.• Aligned with REST terminology.• WADL elements - resources - methods - representations
  40. 40. WADL<application><doc jersey:generatedBy="Jersey: 1.1.4 11/10/2009 05:36 PM"/><resources base="http://localhost:8080/WebServicesREST/resources/"><resource path="/hello"> <method id="sayHello" name="GET"> <request> <param name="name" style="query" type="xs:string"/> </request> <response> <representation mediaType="text/html"/> </response> </method></resource></resources></application>
  41. 41. Agenda• REST Architecture principales.• RESTful web services & WADL.• REST vs. Traditional web services• RESTful advantages
  42. 42. REST vs. Traditional web services• Traditional web services - a lot of custom methods(ports according to business). - use http to transport soap• RESTful - fixed methods(Http methods). - Http is the protocol.
  43. 43. Agenda• REST Architecture principales• RESTful web services & WADL.• REST vs. Traditional web services• RESTful advantages
  44. 44. RESTful advantages• More secure over http (use web port 80)• Ease of testing (only browser needed).• Thin client.• Save memory.(no need to build xml tree in memory).
  45. 45. RESTful Demo
  46. 46. Any Questions??!
  47. 47. If time allowed• SOAP Handler Demo
  48. 48. References• JavaPassion web site• Sun Java JEE6 tutorial• Sun Java Web Services tutorial

×