520 likes | 652 Vues
Survey about Web Services. CMP167 – Programação com Objetos Distribuídos Prof. Cláudio Geyer Gisele Pinheiro Souza 07/2009. Index. Motivation What is a Web Service? SOAP Characteristics Example: Axis REST Characteristics Example: Restlet Hessian Characteristics Example Conclusion
E N D
Survey about Web Services CMP167 – Programação com Objetos Distribuídos Prof. Cláudio Geyer Gisele Pinheiro Souza 07/2009
Index • Motivation • What is a Web Service? • SOAP • Characteristics • Example: Axis • REST • Characteristics • Example: Restlet • Hessian • Characteristics • Example • Conclusion • Bibliography
Motivation • The web services are one of the most popular approaches for making system integration • There are many specifications and implementations for developing a web service • It is hard to find a tutorial that talks about all possibilities of web services development • The goal of this presentation is to put together the different aproaches for web service development
Index • Motivation • What is a Web Service? • SOAP • Characteristics • Example: Axis • REST • Characteristics • Example: Restlet • Hessian • Characteristics • Example • Conclusion • Bibliography
What is a web service? • According to W3C: “A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards.” • But, can only frameworks, which use SOAP and WSDL, be considered web services framework?
Web Services Frameworks • There are many frameworks that uses SOAP and WSDL as the W3C definition: • Example: Axis, Metro Sun • There are many others frameworks called as “web services” frameworks, but they don’t use SOAP and WSDL: • Example: Hessian, Restlet
Index • Motivation • What is a Web Service? • SOAP • Characteristics • Example: Axis • REST • Characteristics • Example: Restlet • Hessian • Characteristics • Example • Conclusion • Bibliography
Discovery UDDI Description WSDL XML Messaging SOAP Transport HTTP Web Services with SOAP - I • Protocol Stack Layers Example
Web Services with SOAP - II • Service Discovery – is responsible for maintaning a centralized register of the services, and provides a easy way for publish/find services. • Examples • UDDI (Universal Description, Discovery, and Integration) • ebXML (electronic business XML ) - Developed by UN/CEFACT and OASIS
Web Services with SOAP - III • Service Description – is responsible for describing a public interface of the service • Example: WSDL(Web Service Description Language) <wsdl:definitions targetNamespace="uri"?> <import namespace="uri" location="uri"/> <wsdl:documentation .... /> ? <wsdl:types> ... </wsdl:types> <wsdl:message> ... </wsdl:message> <wsdl:portType> … <operation>... </operation> </wsdl:portType> <wsdl:binding > ...</wsdl:binding> <wsdl:service> ... </wsdl:service> </wsdl:definitions> a container for data type definitions an abstract description of an action supported a concrete protocol and data format specification for a port type. a collection of endpoints
Web Services with SOAP - IV • Protocol Stack: • XML Messaging – is responsible for enconding the message in XML format that can be understood by both end • Example: SOAP (Simple Object Access Protocol)
Web Services with SOAP - V • Protocol Stack: • Service Transport – is responsible for transporting message between the applications • Example: HTTP
SOAP Web Services Frameworks and APIs - I • JAX-WS (Java API for XML Web Services) is a technology for building web services and clients that communicate using XML • Implementations: Metro Sun, JBossWS
SOAP Web Services Frameworks and APIs - II • JAX-RPC (Java API for XML-based RPC) is for Web services interoperability across heterogeneous platforms and languages • Implementations: JAX-RPC Project(Part of Glassfish), Axis
SOAP Web Services Frameworks and APIs - III • JAXR (Java API for XML Registries ) - provides a uniform and standard Java API for accessing different kinds of XML Registries • Used for access UDDI and ebXML registry
SOAP Web Services Frameworks and APIs - IV • SAAJ (SOAP with Attachments API for Java) –I s an API you can use to write direct SOAP messaging applications instead of using the JAX-RPC APIs • Implementations: Sun metro
Index • Motivation • What is a Web Service? • SOAP • Characteristics • Example: Axis • REST • Characteristics • Example: Restlet • Hessian • Characteristics • Example • Conclusion • Bibliography
Axis • Available in Java and C++ versions • HTTP servlet and JMS transport
Axis Example - I • Client • public class TestClient { • public static void main(String [] args) { • try { • String endpoint = "http://ws.apache.org:5049/axis/services/echo"; • Service service = new Service(); • Call call = (Call) service.createCall(); • call.setTargetEndpointAddress(new java.net.URL(endpoint) ); • call.setOperationName(new QName("http://soapinterop.org/", • “echoString")); • String ret = (String) call.invoke( new Object[] { "Hello!" } ); • System.out.println("Sent 'Hello!', got '" + ret + "'"); • } catch (Exception e) { • System.err.println(e.toString()); • } • }
Axis Example - II • Request • <?xml version="1.0" encoding="UTF-8"?> • <SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> • <SOAP-ENV:Body> • <ns1:echoString xmlns:ns1="http://soapinterop.org/"> • <arg0 xsi:type="xsd:string">Hello!</arg0> • </ns1:echoString> • </SOAP-ENV:Body> • </SOAP-ENV:Envelope>
Index • Motivation • What is a Web Service? • SOAP • Characteristics • Example:Axis • REST • Characteristics • Example: Restlet • Hessian • Characteristics • Example • Conclusion • Bibliography
REST • REST (REpresentation State Transfer) describes an architectural style introduced in 2000 in a Ph.D dissertation by Roy Fielding • A Restful architecture has the characteristics: • Resource Identification • Uniform Interface • Self-Describing Messages • Hypermedia Driving Application State • Stateless Interactions
Resource Identification • Each “thing” (resource) has a name. Each element is defined by a URI. • Example: • http://example.com/customers/1234 (the costumer with id 12347) • http://example.com/orders/2007/10 (the orders done in 10/2007) • The application state is also a resource • Example:
Uniform Interface • There are standard methods for manipulating the resources • Safe – The is not side effect when perform the action • Idempotent – The request can be done multiple times • Cacheable – the response can be cached
Self-Describing Messages • The URI defines the resource • The method defines the operation • The format can be defined between the peers • No additional information is needed for identifying the operation
Hypermedia Driving Application State/ Stateless Interactions • Hypermedia Driving Application State • The Restful applications navigates instead of call other resources; • The URI defines the resources and state • Stateless Interactions • The client request should contain all information needed for performing the operation; • No context in the server side is needed
Restful Web Services Frameworks and APIs - I • Java-WS - Java API for XML Web Services ( JSR224) and JAXB – Java Architecture for XML Binding • Sun Reference Project: Metro Sun • The server can be called programmatically (java API) or by using browsers (XMLHttpRequest) • Uses WADL(Web Application Description Language)designed to provide a machine process-able protocol description format for use with HTTP-based Web applications
Restful Web Services Frameworks and APIs - II • JAX-RS - The JavaTM API for RESTful Web Services (JSR 311 ) - focuses on using annotations to make plain old Java objects (POJOs) and resources available through HTTP • Sun Reference Project: Jersey • Other Vendors: CXF (Apache), RESTEasy(JBoss) and Restlet
Index • Motivation • What is a Web Service? • SOAP • Characteristics • Example:Axis • REST • Characteristics • Example: Restlet • Hessian • Characteristics • Example • Conclusion • Bibliography
Restful Web Services Frameworks and APIs - III • Restlet • Available editions: • Java SE/EE, Google Web Kit, Google AppEngine and Google Androide • Some available connectors • Multiple server HTTP connectors (example Jetty) • Multiple client HTTP connectors (example Apache HTTP Client) • Client SMTP, SMTPS, POP v3,POPS v3 and JDBC • Some available representations • JAX, JibX, DOM, SAX base, JSON • Some Configuration Option • Complete configuration possible in Java via the Restlet API • Configuration possible via Restlet XML and WADL files
Restlet – Example I • Standalone server example public class FirstStepsApplication extends Application { @Override public synchronized Restlet createRoot() { Router router = new Router(getContext()); // Defines only one route router.attachDefault(HelloWorldResource.class); router.attach("/books/{autor}", BooksResource.class); return router; } }
Restlet – Example II • public class HelloWorldResource extends Resource { • public HelloWorldResource(Context context, Request request, • Response response) { • super(context, request, response); • getVariants().add(new Variant(MediaType.TEXT_PLAIN)); • } • @Override • public Representation represent(Variant variant) throws ResourceException { • Representation representation = new StringRepresentation( • "hello, world", MediaType.TEXT_PLAIN); • return representation; • } • } • Resource I
Restlet – Example III public class BooksResource extends Resource { Hashtable map = new Hashtable(); public BooksResource() { super(); map.put("Gisele", “test”); } @Override publicvoid handleGet() { String autor = (String) getRequest().getAttributes().get("autor"); Representation result = new StringRepresentation((String)map.get(autor)); getResponse().setEntity(result); } } • Resource II
Restlet – Example IV • Run Server public class FirstStepsMain { public static void main(String[] args) { try { Component component = new Component(); component.getServers().add(Protocol.HTTP, 8182); component.getDefaultHost().attach(new FirstStepsApplication()); component.start(); } catch (Exception e) { e.printStackTrace(); } } }
Restlet – Example V • Client public class RestletClient { public static void main(String [] args) throws IOException { String uri = "http://localhost:8182/books/Gisele" ; Client client = new Client(Protocol.HTTP); client.get(uri).getEntity().write(System.out); String uri2 = "http://localhost:8182" ; Client client2= new Client(Protocol.HTTP); client2.get(uri2).getEntity().write(System.out); } }
Index • Motivation • What is a Web Service? • SOAP • Characteristics • Example: Axis • REST • Characteristics • Example: Restlet • Hessian • Characteristics • Example • Conclusion • Bibliography
Hessian Web Service Protocol • Was created as a lightweight binary alternative to the XML-based web services protocols • Is a small protocol, J2ME devices can use it to connect to Resin servers • Some Hessian Implementation • Java, Python, C++, C#, Ruby,PHP • Support Synchronous and Asynchronous messages • Uses URL for identifying the services, can support object name without extra header • Example: http://localhost/hessian/my-entity-bean?ejbid=slytherin (Entity Bean Identifier)
Hessian Structure - I • Has a specific format for sending the information • Supports the following types: • Primitives: binary, boolean, date, double, int , long, null, string • Recursive type: list, map, object • Special structure: Ref for circular reference
Hessian Structure - II 37 ["hello, world", 29] {"color" : "green", "year" : 2003} • Example: • JSON • Hessian 0xb7 # int values 0-47 are encoded by 0x90 to 0xbf V x0c hello, world # string with length 0-31 start with 0x00 to 0x1f Xad # integer 0xb7 O t x00 x06 qa.Car # Class definition x92 # two fields x05 color # "color" field x04 year # "year" field o x90 # object instance, 0x90 is def #0 x05 green # color : green xcf xd3 # year : 2003
Hessian Example - I • public interface Basic { • public String hello(); • } • publicclass BasicClient { • public static void main(String []args) throws Exception { • String url = "http://www.caucho.com/hessian/test/basic"; • HessianProxyFactory factory = new HessianProxyFactory(); • Basic basic = (Basic) factory.create(Basic.class, url); • System.out.println("Hello: " + basic.hello()); • } • } • Client
Hessian Example - II • Server • public class BasicService implements Basic { • private String _greeting = "Hello, world"; • public void setGreeting(String greeting) { • _greeting = greeting; • } • public String hello(){ • return _greeting; • } • }
Hessian Example - III • Configurationfor standard web.xml • <web-app> • <servlet> • <servlet-name>hello</servlet-name> • <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class> • <init-param> <param-name>home-class</param-name> • <param-value>example.BasicService</param-value> </init-param> • <init-param> <param-name>home-api</param-name> • <param-value>example.Basic</param-value> </init-param> • </servlet> • <servlet-mapping> • <url-pattern>/hello</url-pattern> <servlet-name>hello</servlet-name> • </servlet-mapping> • </web-app>
Index • Motivation • What is a Web Service? • SOAP • Characteristics • Example: Axis • REST • Characteristics • Example: Restlet • Hessian • Characteristics • Example • Conclusion • Bibliography
What is a Web Service? (Revisited) - I • Back to the web service definition: “A Web service is a software system designed to support interoperable machine-to-machine interaction over a network.It has an interface described in a machine-processable format (specifically WSDL).Other systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards.” • The web services frameworks enumerated on this presentation follows this definition? • Sentence 1(pink) - SOAP based Restful Hessian • Sentence 2(green)- SOAP based Restful Hessian • Sentence 3(blue) - SOAP based Restful Hessian • Sentence 4(purple)- SOAP based Restful Hessian
What is a Web Service? (Revisited) - II • If the 3 approaches presented are web services, so we could say that the web services is: “A Web service is a software system designed to support interoperable machine-to-machine interaction over a network.typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards.” • This is a very vague description • There is a web service specification, but it is not really defined.
Conclusion I • SOAP based web services • Strengths • It is very used by almost projects • The same message can be transported by many middlewares • Weakness • There is a problem to link the memory structure to the XML structure • The XML schema is not powerful • RESTFul web services • Strengths • Lightweight structure • The developer can use a browser to test
Conclusion II • RESTFul web services • Weakness • It is not all firewalls that accepts all methods HTTP (normally GET and POST are accepted ) • Problems to send a large amount of input data by using get • Hessian • Strengths • It has implementation in many languages • It is possible to create graphs on the messages • Weakness • The messages are not so clear • It is not very used in projects
Bibliography I • http://www.javaworld.com/javaworld/jw-10-2008/jw-10-rest-series-1.html?page=4 • http://www.restlet.org/about/features • http://oreilly.com/catalog/pwebserperl/chapter/ch11.pdf • http://www.javaworld.com/javaworld/jw-12-2008/jw-12-rest-series-2.html?page=1 • http://www.naviquan.com/blog/restlet-handle-methods • http://java.sun.com/developer/technicalArticles/WebServices/restful/ • https://jaxb.dev.java.net/tutorial/section_1_1-Introduction.html#Introduction • http://research.sun.com/techrep/2006/smli_tr-2006-153.pdf • http://www.infoq.com/news/2008/10/jaxrs-comparison
Bibliography II • http://java.sun.com/webservices/docs/2.0/tutorial/doc/JAXWS.html • http://java.sun.com/webservices/jaxrpc/overview.html • http://ws.apache.org/axis/java/install.html • http://java.sun.com/webservices/jaxr/overview.html • http://java.sun.com/developer/technicalArticles/WebServices/jaxrws/ • http://www.ibm.com/developerworks/xml/library/x-ebxml/ • http://java.sun.com/developer/EJTechTips/2005/tt0425.html#1 • http://java.sun.com/j2ee/1.4/docs/tutorial/doc/SAAJ2.html • http://dret.net/netdret/docs/soa-rest-www2009/intro#soa • http://www.ibm.com/developerworks/webservices/library/ws-featuddi/