Successfully reported this slideshow.

Service Oriented Architecture Luqman

4,117 views

Published on

Published in: Technology

Service Oriented Architecture Luqman

  1. 1. Service Oriented Architectureand Web services<br />Mohammed LuqmanShareef<br />me@luqmanshareef.com<br />
  2. 2. 2010-02-08<br />www.luqmanshareef.com<br />2<br />Popular Distributed Application Frameworks/Technologies<br />
  3. 3. COM, DCOM Microsoft specific<br />EJB, RMI Java Specific<br />CORBA Platform and Language Independent<br />2010-02-08<br />www.luqmanshareef.com<br />3<br />Popular Distributed Application Frameworks/Technologies<br />
  4. 4. A software system is divided into highly flexible and re-usable components called services. <br />SOA is just an architecture blue print <br />It is NOT a technical standard<br />It is NOT a technology<br />2010-02-08<br />www.luqmanshareef.com<br />4<br />What is SOA?<br /><ul><li>SOA is an architectural style of building software applications that promotes loose coupling between components for their reuse.</li></ul>Coarse grained<br />Loosely coupled<br />Platform independent<br />Standard Interface<br />
  5. 5. Self-contained module that perform a predetermined task<br />Software component that have published contracts/interfaces<br />Black-box to the consumers<br />Platform-Independent<br />Interoperable<br />2010-02-08<br />www.luqmanshareef.com<br />5<br />What is Service ?<br />
  6. 6. Systems today are bigger than ever before<br />Complexity increases exponentially with size<br />Systems need to be interconnected<br />OO solved the problems of small-medium sized systems<br />CO (Component Orientation) solved problems of medium-large systems<br />Neither OO nor CO could cope with the problems of very large systems, systems of systems, or integration between systems<br />Why SOA?<br />2010-02-08<br />6<br />www.luqmanshareef.com<br />
  7. 7. 2010-02-08<br />www.luqmanshareef.com<br />7<br />Why SOA?<br />End Customer Portal<br />Operator Portal<br />Partner Portal<br />Customer Info<br />Management<br />Order Management<br />Credit Management<br />Sales<br />Management<br />Billing<br />Invoicing<br />Provisioning<br />Network Management<br />Inventory<br />Service<br />Catalog<br />Customer Profiles<br />
  8. 8. 2010-02-08<br />www.luqmanshareef.com<br />8<br />Why SOA?<br />End Customer Portal<br />Operator Portal<br />Partner Portal<br />Services<br />Credit Management<br />Sales<br />Management<br />Customer Info<br />Management<br />Order Management<br />Provisioning<br />Invoicing<br />Inventory<br />Network Management<br />Customer Profiles<br />Billing<br />Service<br />Catalog<br />
  9. 9. Towards Service-Oriented Architecture<br /><ul><li>Coordination oriented
  10. 10. Build to change
  11. 11. Incrementally built and deployed
  12. 12. Enterprise solutions
  13. 13. Loosely coupled
  14. 14. Message oriented
  15. 15. Abstraction
  16. 16. Function oriented
  17. 17. Build to last
  18. 18. Prolonged development cycles
  19. 19. Application silos
  20. 20. Tightly coupled
  21. 21. Object oriented
  22. 22. Known implementation</li></ul>2010-02-08<br />9<br />www.luqmanshareef.com<br />
  23. 23. Managing services<br />Service governance<br />Performance<br />Reliability<br />security<br />SLAs<br />Interoperability of services<br />Challenges<br />2010-02-08<br />10<br />www.luqmanshareef.com<br />
  24. 24. Loose coupling<br />Minimize dependencies.<br />Service contract<br />Services adhere to a communications agreement.<br />Service abstraction <br />Hide the service execution logic from the outside world.<br />Service reusability<br />Logic is divided into services for reuse.<br />2010-02-08<br />www.luqmanshareef.com<br />11<br />SOA: Architectural Principles<br />
  25. 25. Service composability<br />Services can be assembled to form composite service.<br />Service autonomy<br />Services have control over the logic they encapsulate.<br />Service discoverability<br />Services can be found and assessed via available discovery mechanisms.<br />Service relevance<br /> Service presented at a granularity recognized by user a meaningful service.<br />2010-02-08<br />www.luqmanshareef.com<br />12<br />SOA: Architectural Principles<br />
  26. 26. SOA can be implemented using any service based technology such as CORBA, but the SOAP based web services standard implementation has gained wide industry acceptance, because these standards provide greater interoperability.<br /> Key differences between CORBA and web service are<br />2010-02-08<br />www.luqmanshareef.com<br />13<br />SOA Implementation<br />
  27. 27. 2010-02-08<br />www.luqmanshareef.com<br />14<br />Realizing SOA with Web Services<br />
  28. 28. Web service is a standard way of integrating Web-based applications using the XML, SOAP, WSDL and UDDI open standards over an Internet protocol backbone. <br /> XML is used to tag the data, <br /> SOAP is used to transfer the data, <br /> WSDL is used for describing the services available and <br /> UDDI is used for listing what services are available. <br /> Web services are loosely coupled computing services that can reduce the complexity of building business applications, save costs, and enable new business models. Services running on an arbitrary machine can be accessed in a platform- and language-independent fashion.<br />2010-02-08<br />www.luqmanshareef.com<br />15<br />What is web service ?<br />
  29. 29. Lookup for the tomato sellers<br />Yellow Pages: contain companies that are selling tomatoes, their location, and contact information. <br />2010-02-08<br />www.luqmanshareef.com<br />16<br />How to buy tomatoes ?<br /><ul><li>Find the service offered according to my needs</li></ul>Where, when and how can I buy tomatoes? <br /><ul><li>Buy the tomatoes</li></ul>Do the transaction<br />
  30. 30. Lookup for the Service Provider<br />Registry: contain providers that are selling services, their location, and contact information. <br />Find the service offered according to my needs<br />Where, when and how can I get the service? <br />Access the servicedo the transaction <br />2010-02-08<br />www.luqmanshareef.com<br />17<br />How to access a service?<br />
  31. 31. XML (eXtensibleMarkup Language)<br />A uniform data representation and exchange mechanism<br />SOAP (Simple Object Access Protocol)<br />Lightweight (XML-based) protocol for exchange <br /> of information in a decentralized, distributed environment<br />WSDL (Web Service Description Language)<br />XML format that describes the web service<br />UDDI (Universal Description Discovery and Integration)<br />Like yellow pages of Web services<br />2010-02-08<br />www.luqmanshareef.com<br />18<br />Components of a web service<br />
  32. 32. 2010-02-08<br />www.luqmanshareef.com<br />19<br />3 roles of service<br />
  33. 33. 2010-02-08<br />www.luqmanshareef.com<br />20<br />Service Vs. Consumer<br />Policy<br />Adheres to<br />governed by<br />End Point<br />Binds to<br />Exposes<br />Serves<br />Service <br />Consumer<br />Service<br />Contracts<br />implements<br />Understands<br />describes<br />Messages<br />Sends/Receives<br />Sends/Receives<br />
  34. 34. Define the service implementation and compile it.<br /> WS>javac -d . HelloImpl.java<br />Use wsgen to generate the artifacts required to deploy the service.<br /> WS>wsgen -wsdlserver.HelloImpl<br />3. Package the files into a WAR file and deploy it .<br />2010-02-08<br />www.luqmanshareef.com<br />21<br />Steps to develop a web serviceusing JAX-WS<br />package server;<br />import javax.jws.WebService;<br />@WebService<br />public class HelloImpl {<br /> /**<br /> * @param name<br /> * @return Say hello to the person.<br /> */<br /> public String sayHello(String name) {<br /> return "Hello, " + name + "!";<br /> }<br />}<br />
  35. 35. 2010-02-08<br />www.luqmanshareef.com<br />22<br />HelloImplService.wsdl<br />
  36. 36. 2010-02-08<br />www.luqmanshareef.com<br />23<br />HelloImplService.wsdl contd…<br />
  37. 37. 2010-02-08<br />www.luqmanshareef.com<br />24<br />HelloImplService_schema1.xsd<br />
  38. 38. Implement Client Code<br />5. Use wsimport to generate and compile the web service artifacts needed to connect to the service.<br /> WS>wsimportHelloImplService.wsdl<br /> parsing WSDL...<br /> generating code...<br /> compiling code...<br />6. Run the client.<br />2010-02-08<br />www.luqmanshareef.com<br />25<br />Steps to develop a web service contd…<br />package myClient;<br />import helloservice.endpoint.HelloService;<br />import helloservice.endpoint.Hello;<br />public class HelloClient {<br /> public static void main(String[] args) {<br /> try {<br />HelloService service = new HelloService();<br /> Hello port = service.getHelloPort();<br /> String response = port.sayHello(“Luqman");<br />System.out.println(response);<br /> } catch (Exception e) {<br />e.printStackTrace();<br /> }<br /> }<br />}<br />
  39. 39. WSDL is a contract between service provider and the consumer<br />A WSDL document describes<br />What the service can do<br />Where it resides<br />How to invoke it<br />2010-02-08<br />www.luqmanshareef.com<br />26<br />WSDL<br />WSDL elements<br />Types<br />Message<br />Operation<br />Port Type<br />WSDL<br />Binding<br />Port<br />Service<br />
  40. 40. Types<br /> Data type definition used in exchanging messages<br />Message<br /> Describes the logical content of data being communicated<br />Operation<br /> An Abstract description of an action supported by the service<br />Port Type<br /> A set of operations and messages involved with the service<br />Binding<br /> A concrete protocol and data format specification for a port type<br />Port<br /> A single end point defined as a combination of a binding and a network address<br />Service<br /> Identifies which ports to group together<br />2010-02-08<br />www.luqmanshareef.com<br />27<br />WSDL elements<br />
  41. 41. 2010-02-08<br />www.luqmanshareef.com<br />28<br />SOAP<br />SOAP Envelope<br />SOAP Header<br />Header Block<br />SOAP Body<br />Message Body<br />Fault Handlers<br />SOAP message structure<br />SOAP is a lightweight (XML-based) protocol for exchange of information in a decentralized, distributed environment. <br />SOAP is a format for sending messages<br />SOAP is independent of transport protocol<br />A SOAP message is an ordinary XML document containing the following elements:<br />Envelope - identifies the XML document as a SOAP message<br />Header - contains application specific info like authentication etc.<br />Body - contains the message in request and response<br />Fault - contains errors and status information<br />
  42. 42. <?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Bodyxmlns:m="http://www.example.org/Hello">  <m:sayHello>    <m:name>Luqman</m:name>  </m:sayHello></soap:Body></soap:Envelope> <br />2010-02-08<br />www.luqmanshareef.com<br />29<br />SOAP Example<br />Request<br />Response<br /><?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Bodyxmlns:m="http://www.example.org/stock">  <m:sayHelloResponse>    <m:return>Hello Luqman</m:return>  </m:sayHelloResponse></soap:Body></soap:Envelope> <br />
  43. 43. SOAP errors are handled using a specialised envelope known as a Fault Envelope<br />A SOAP Fault is a special element which must appear as an immediate child of the body element<br /><faultcode> and <faultstring> are required.<br />2010-02-08<br />www.luqmanshareef.com<br />30<br />SOAP Fault<br />
  44. 44. Printing SOAP Message<br />public class MySOAPHandler implements SOAPHandler<SOAPMessageContext>{<br /> public booleanhandleMessage(SOAPMessageContext context) {<br /> try {<br />SOAPMessage message = context.getMessage();<br /> if ((Boolean)context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY) == true){<br />System.out.println("Request Message: ");<br /> }else{<br />System.out.println("Response Message: ");<br /> }<br />message.writeTo(System.out);<br /> } catch (Exception ex) {<br />ex.printStackTrace();<br /> }<br /> return true;<br /> }<br /> public Set<QName> getHeaders() { return null; }<br /> public booleanhandleFault(SOAPMessageContext context) { return true; }<br /> public void close(MessageContext context) { }<br />}<br />Wite a new Class <br />MySOAPHandler<br />Implement handleMessage<br />2010-02-08<br />31<br />www.luqmanshareef.com<br />
  45. 45. Printing SOAP Message contd...<br />public class MyMessageHandlerResolver implements HandlerResolver {<br /> public List<Handler> getHandlerChain(PortInfoportInfo) {<br /> List<Handler> handlerChain = new ArrayList<Handler>();<br />MySOAPHandlerhh = new MySOAPHandler();<br />handlerChain.add(hh);<br /> return handlerChain;<br /> }<br />}<br />Wite a new Class <br />MyHandlerResolver<br />Implement getHandleChain<br />Set the Handler Resolver in Client<br />Invoke the web method<br />Run the client<br />service.setHandlerResolver(new MyMessageHandlerResolver());<br />2010-02-08<br />32<br />www.luqmanshareef.com<br />
  46. 46. UDDI is a set of specifications that is used to publish information for describing and discovering web services, finding businesses, building registries. <br />UDDI is a directory for storing information about web services.<br />UDDI communicates via SOAP.<br />2010-02-08<br />www.luqmanshareef.com<br />33<br />UDDI<br />3 levels of information in UDDI<br />White Pages<br />To query companies with their names and attributes<br />Yellow Pages<br />To query businesses with their categories<br />Green Pages<br />Contains technical info on how to interact with the services<br />
  47. 47. 2010-02-08<br />www.luqmanshareef.com<br />34<br />UDDI Structure<br />
  48. 48. 2010-02-08<br />www.luqmanshareef.com<br />35<br />Registry APIs (SOAP Messages)<br /><ul><li>Publishers API
  49. 49. Save things
  50. 50. save_business
  51. 51. save_service
  52. 52. save_binding
  53. 53. save_tModel
  54. 54. Delete things
  55. 55. delete_business
  56. 56. delete_service
  57. 57. delete_binding
  58. 58. delete_tModel
  59. 59. security…
  60. 60. get_authToken
  61. 61. discard_authToken
  62. 62. Inquiry API
  63. 63. Find things
  64. 64. find_business
  65. 65. find_service
  66. 66. find_binding
  67. 67. find_tModel
  68. 68. Get Details about things
  69. 69. get_businessDetail
  70. 70. get_serviceDetail
  71. 71. get_bindingDetail
  72. 72. get_tModelDetail</li></li></ul><li>Write the implementation and interface<br />Generate WSDL file<br />>java org.apache.axis.wsdl.Java2WSDL -o AdderWSDL.wsdl -l http://localhost:8080/axis/services/Adder luqman.AdderInterface<br />Generate server side and client side classes<br />>java org.apache.axis.wsdl.WSDL2Java -o . -p luqman.generated -s AdderWSDL.wsdl<br />Bind web service with functionality provider<br />Bundle required classes<br />jar cfv adderServerSide.jar luqman*.class luqmangenerated*.class<br />Copy the jar in the server’s axis/WEB-INF/lib folder<br />>jar cfv adderClientSide.jar luqmangeneratedAdderInterface.classluqmangeneratedAdderInterfaceService.classluqmangeneratedAdderInterfaceServiceLocator.classluqmangeneratedAdderSoapBindingStub.class<br />Register web services with Axis<br />java org.apache.axis.client.AdminClientluqmangenerateddeploy.wsdd<br />Write Web service client<br />Developing a web service using Axis<br />2010-02-08<br />36<br />www.luqmanshareef.com<br />
  73. 73. Printing SOAP Message in AXIS<br />Edit the generated code in AdderSoapBindingStub.class<br /> - In the corresponding method of the Stub class add the following lines of code after the _call.invoke(...) statement<br />String requestMessage = _call.getMessageContext().getRequestMessage().getSOAPEnvelope().toString(); <br />String responseMessage = <br />_call.getMessageContext().getResponseMessage().getSOAPEnvelope().toString(); <br />System.out.println(“Request SOAP Message” + requestMessage);<br />System.out.println(“Request SOAP Message” + responseMessage);<br />2010-02-08<br />37<br />www.luqmanshareef.com<br />
  74. 74. Adding attachments to SOAP Message in AXIS<br />Client Side Code<br />CalculatorService service = new CalculatorServiceLocator();<br />Calculator calc = service.getcalculator();<br />Stub stub = (Stub) calc;<br />FileDataSourcefs = new FileDataSource(new File("E:/Code/testA.txt") );<br />DataHandler dh = new DataHandler(fs);<br />stub.addAttachment(dh);<br />Display the Attachment in Stub<br />Edit the generated code in AdderSoapBindingStub.class<br /> - In the corresponding method of the Stub class add the following lines of code after the _call.invoke(...) statement<br />MessageContext message = _call.getMessageContext(); //.getRequestMessage(); <br />Iterator it = message.getRequestMessage().getAttachments();<br />while (it.hasNext()) {<br />AttachmentPart part = (AttachmentPart) it.next();<br /> try {<br />System.out.println("File Name : " + part.getDataHandler().getDataSource().getName());<br />InputStream is = part.getDataHandler().getInputStream();<br /> while (is.available() > 0) {<br />System.out.print((char) is.read());<br /> }<br /> } catch (Exception ex) {<br />ex.printStackTrace();<br /> }<br />2010-02-08<br />38<br />www.luqmanshareef.com<br />
  75. 75. 2010-02-08<br />www.luqmanshareef.com<br />39<br />REST<br />
  76. 76. Each unique URL is a representation of some object<br />Ex : http://www.mycompany.com/india/hyd/employees<br /> http://www. mycompany.com/india/hyd/employees/1234<br />HTTP GET Method operates on the resource.<br />Object state is transferred and stored at client.<br />Representation of the resource state in XML, JSON etc.<br />2010-02-08<br />www.luqmanshareef.com<br />40<br />RESTful web services<br />REpresentationalState Transfer<br />
  77. 77. RPC vs REST<br />RPC<br />Every object has its own unique methods<br />Methods can be remotely invoked over the Internet<br />A single URI represents the end-point, and that's the only contact with the Web<br />Data hidden behind method calls and parameters<br />Data is unavailable to Web applications<br />REST<br /><ul><li>Every useful data object has an address
  78. 78. Resources themselves are the targets for method calls
  79. 79. The list of methods is fixed for all resources</li></ul>2010-02-08<br />41<br />www.luqmanshareef.com<br />
  80. 80. 2010-02-08<br />www.luqmanshareef.com<br />42<br />RESTful web services contd…<br />Principles<br /><ul><li>Resource identification through URI
  81. 81. Uniform interface</li></ul> GET/PUT/POST/DELETE<br /><ul><li>Self-descriptive messages
  82. 82. Stateful interactions through hyperlinks</li></ul>Benefits<br />Client side<br />Easy to experiment in browser<br />Broad programming language support<br />Choice of data formats<br />bookmarkable<br />Server side<br /><ul><li>Uniform Interface
  83. 83. Cacheable
  84. 84. Scalable
  85. 85. Easy failover</li></li></ul><li>www.luqmanshareef.com<br />43<br />Example<br />Request<br />GET/india/hyd/employees/1234 HTTP/1.1<br />Host: mycompany.com<br />Accept: application/xml<br />Response<br />HTTP/1.1 200 OK<br />Date: Tue, 09 Feb 2010 11:41:20 GMT<br />Server: Apache/1.3.6<br />Content-Type: application/xml; charset=UTF-8<br /><?xml version="1.0"?><br /><Employees xmlns="…"><br /> <Employee name=“ABC”><br /> …<br /> </Employee><br /></Employees><br />Resource<br />Method<br />State<br />transfer<br />Representation<br />2010-02-08<br />
  86. 86. 2010-02-08<br />www.luqmanshareef.com<br />44<br />Developing a RESTful web service using JAX-WS<br />package com.sun.jersey.samples.helloworld.resources;<br />import javax.ws.rs.GET;<br />import javax.ws.rs.Produces;<br />import javax.ws.rs.Path;<br />@Path("/employees/{empid}")<br />public class Employee{<br />@GET<br /> @Produces("text/xml")<br /> public String getEmployee(@PathParam(“empid") String empId) {<br /> ...<br /> …<br /> }<br />}<br />
  87. 87. REST Annotations<br />2010-02-08<br />45<br />www.luqmanshareef.com<br />
  88. 88. REST Annotations<br />2010-02-08<br />46<br />www.luqmanshareef.com<br />
  89. 89. Securing web services<br />SSL is not enough<br />SSL provides point to point security<br />WS needs end to end security<br />SSL provides security at transport level<br />WS needs security at message level<br />SSL doesn’t support non-repudiation<br />Non-repudiation is critical for business WS<br />Web service security requirements<br />Authentication ( Identity check )<br />Authorization ( Access Control )<br />Confidentiality ( Encryption )<br />Integrity ( Signature Support )<br />Non-repudiation ( Ability to prove that a particular transaction is performed)<br />Accessibility ( Ensuring that the service is not impacted by attacks)<br />2010-02-08<br />www.luqmanshareef.com<br />47<br />
  90. 90. XML digital signature ( IETF and W3C)<br />XML Encryption ( W3C)<br />SAML (Secure Assertion Markup Language) ( OASIS)<br />WS-Security (Web Services Security) (OASIS)<br />WS-SecureConversation<br />WS-Federation<br />WS-Policy<br />WS-Trust<br />WS-Privacy<br />XACML (Extensible Access Control Markup Language) (OASIS)<br />2010-02-08<br />www.luqmanshareef.com<br />48<br />Web service security standards<br />
  91. 91. “BPEL is an XML language for defining the composition of web services into new services”<br />BPEL would require that every process <br />Either has a “center” of execution<br />A process is composed of a large set of orchestration definitions interacting with each other<br />BPEL assumes that business processes can be fully captured in a single definition, including all possible exception paths<br />Not sure this is the right assumption<br />BPEL<br />2010-02-08<br />49<br />www.luqmanshareef.com<br />
  92. 92. Identify the partners in the process<br />Declare the Partners in the Process<br />Design the workflow of the process<br />Define up the workflow process<br />Declare the Process Using BPEL Activity Constructs<br />Add Business Logic Using BPELConstructs<br />BPEL Steps<br />2010-02-08<br />50<br />www.luqmanshareef.com<br />
  93. 93. Open source specification project from the Object Management Group (OMG), describing a UML profile and metamodel for the modeling and design of services within a service-oriented architecture.<br />SoaML(SOA Modeling Language) <br />2010-02-08<br />51<br />www.luqmanshareef.com<br />
  94. 94. Dealer Network Architecture<br />The dealer network is defined as a community “collaboration” involving three primary roles for participants in this community: the dealer, manufacturer, and shipper. The following diagram illustrates these roles and services in the dealer network architecture. <br />SOAML Example<br />2010-02-08<br />52<br />www.luqmanshareef.com<br />
  95. 95. The enterprise service bus (ESB) is a software infrastructure that facilitates application integration. <br />An ESB does not itself implement SOA but provides the features with which SOA can be implemented.<br />Examples<br />Glassfish ESB (Sun)<br />Websphere ESB (IBM)<br />Biztalk Server (Microsoft)<br />JBOSS ESB<br />ESB<br />2010-02-08<br />53<br />www.luqmanshareef.com<br />
  96. 96. Invocation<br />Routing<br />Mediation<br />Message Processing<br />Service Orchestration<br />Complex Event Processing<br />Management<br />Common ESB Characteristics<br />2010-02-08<br />54<br />www.luqmanshareef.com<br />
  97. 97. SOAP - http://www.w3c.org/TR/soap<br />WSDL - http://www.w3c.org/TR/wsdl<br />UDDI - http://www.uddi.xml.org<br />SAML - http://saml.xml.org<br />ebXML - http://www.ebxml.org<br />CORBA Vs. Web services - http://www2002.og/CDROM/alternate/395<br />SoaML - http://www.omg.org/spec/SoaML<br />BPEL - www.oasis-open.org/committees/wsbpel<br />2010-02-08<br />www.luqmanshareef.com<br />55<br />For more information<br />
  98. 98. 2010-02-08<br />www.luqmanshareef.com<br />56<br />Questions?<br />
  99. 99. Thank You<br />www.luqmanshareef.com<br />2010-02-08<br />www.luqmanshareef.com<br />57<br />

×