8. Sun’s Web Services Stack Metro: JAX-WS , WSIT JAXB = Java Architecture for XML Binding | JAX-WS = Java APIs for XML Web Services NetBeans JAX-WS Tooling Transactions Reliable- Messaging Security Metadata WSDL Policy Core Web Services HTTP TCP SMTP JAXB, JAXP, StaX JAX-WS WSIT tools transport xml
9.
10.
11.
12. Developing a Web Service Starting with a Java class war or ear @WebService POJO Implementation class Servlet-based or Stateless Session EJB Optional handler classes Packaged application (war/ear file) You develop Service contract WSDL Deployment creates JAXB and JAX-WS files needed for the service
13.
14.
15. Customizability via Annotations @WebService( name= "Calculator", portName= "CalculatorPort", serviceName= "CalculatorService", targetNamespace= "http://calculator.org" ) public class CalculatorWS { @WebMethod (operationName=”addCalc”) public int add ( @WebParam (name=”param1”) int a, int b) { return a+b; } }
16.
17. Developing a Web Service Starting with a WSDL wsimport tool @WebService SEI Interface @WebService( endpointInterface ="generated Service") Implementation class Servlet-based or Stateless Session EJB endpoint model Packaged application (war/ear file) Service contract WSDL Generates You develop
18.
19. Implementing a Web Service for a Generated Interface @WebService( endpointInterface =" generated.BankService ", serviceName =" BankService ") public class BankServiceImpl implements BankService { ... public float getBalance (String acctID, String acctName) throws AccountException { // code to get the account balance return theAccount.getBalance(); } }
20. Server Side CalculatorWS Web Service E ndpoint Listener Soap binding @Web Service Soap request publish 1 2 3 4 5 6 7 8
25. Client-Side Programming wsimport tool @WebService Dynamic Proxy Service contract WSDL Generates You develop Client which calls proxy
26.
27.
28.
29. Example: Java EE Servlet Client No Java Naming and Directory Interface™ API ! public class ClientServlet extends HttpServlet { @WebServiceRef (wsdlLocation = "http://.../CalculatorWSService?wsdl") private CalculatorWSService service; protected void processRequest( HttpServletRequest req, HttpServletResponse resp) { CalculatorWS proxy = service.getCalculatorWSPort(); int i = 3; j = 4; int result = proxy.add (i, j); . . . } } Get Proxy Class Business Interface Factory Class
31. Client Side CalculatorWS Web Service extends Dynamic Proxy S ervice E ndpoint I nterface Invocation Handler JAXB JAXB return value parameters getPort 1 2 3 6 Soap request Soap response 4 5
32.
33.
34.
35.
36. Client-side Messaging API: Dispatch Interface one-way and asynch calls available: // T is the type of the message public interface Dispatch < T > { // synchronous request-response T invoke(T msg); // async request-response ( polled for completion) Response<T> invokeAsync(T msg); Future<?> invokeAsync(T msg, AsyncHandler<T> h); // one-way void invokeOneWay(T msg); }
39. Server-sideExample: Payload Mode, No JAXB @ServiceMode(Service.Mode. PAYLOAD ) public class MyProvider implements Provider < Source > { public Source invoke( Source request, Map<String,Object> context) { // process the request using XML APIs, e.g. DOM Source response = ... // return the response message payload return response; } }
64. request data response data authentication data SAML assertions https/ssl (optional) digital certificate Security Architecture Message Level Security (signature and encryption) web services client SOAP client signed & encrypted data web services server SOAP server SOAP service security server authentication authorization signature validation data encryption digital certificate request data data decryption/ encryption signature validation
65.
66.
67.
68.
69.
70. .NET Trust Authority Trust Authority Sun Managed Microsoft Managed Project GlassFish ™ Retail Quote Service Project GlassFish Wholesale Quote Service .Net Wholesale Service Java EE Platform With Project Tango WCF Client Java Client WS-Trust WS-T Trust QOS Security Interop.
80. WSIT Client Programming Model 109 Service Wsimport Client Artifacts WSIT Config File wsit-*.xml WSIT NetBean Module By Hand Other IDEs MEX/ GET WDSL MEX/ GET
87. Verb Noun Create POST Collection URI Read GET Collection URI Read GET Entry URI Update PUT Entry URI Delete DELETE Entry URI CRUD to HTTP method mapping 4 main HTTP methods CRUD methods
88.
89. Customer Resource Using Servlet API public class Artist extends HttpServlet { public enum SupportedOutputFormat {XML, JSON}; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String accept = request.getHeader("accept").toLowerCase(); String acceptableTypes[] = accept.split(","); SupportedOutputFormat outputType = null; for (String acceptableType: acceptableTypes) { if (acceptableType.contains("*/*") || acceptableType.contains("application/*") || acceptableType.contains("application/xml")) { outputType=SupportedOutputFormat.XML; break; } else if (acceptableType.contains("application/json")) { outputType=SupportedOutputFormat.JSON; break; } } if (outputType==null) response.sendError(415); String path = request.getPathInfo(); String pathSegments[] = path.split("/"); String artist = pathSegments[1]; if (pathSegments.length < 2 && pathSegments.length > 3) response.sendError(404); else if (pathSegments.length == 3 && pathSegments[2].equals("recordings")) { if (outputType == SupportedOutputFormat.XML) writeRecordingsForArtistAsXml(response, artist); else writeRecordingsForArtistAsJson(response, artist); } else { if (outputType == SupportedOutputFormat.XML) writeArtistAsXml(response, artist); else writeArtistAsJson(response, artist); } } private void writeRecordingsForArtistAsXml(HttpServletResponse response, String artist) { ... } private void writeRecordingsForArtistAsJson(HttpServletResponse response, String artist) { ... } private void writeArtistAsXml(HttpServletResponse response, String artist) { ... } private void writeArtistAsJson(HttpServletResponse response, String artist) { ... } } Don't try to read this, this is just to show the complexity :)
90.
91.
92. POJO @Path("/customers/") public class Customers { @ProduceMime("application/xml") @GET Customers get() { // return list of artists } @Path("{id}/") @GET public Customer getCustomer(@PathParam("id") Integer id) { // return artist } } responds to the URI http://host/customers/ responds with XML responds to HTTP GET URI http://host/customers/id
93. Customer Service Overview Customer Database Web container (GlassFish™) + REST API Browser (Firefox) HTTP