Service Oriented Architecture Updated Luqman
-
Upload
guesteb791b -
Category
Documents
-
view
173 -
download
1
Transcript of Service Oriented Architecture Updated Luqman
Service Oriented Architectureand
Web services
Mohammed Luqman Shareef
2
COM, DCOM Microsoft specific
EJB, RMI Java Specific
CORBA Platform and Language Independent
2010-02-08
Popular Distributed Application Frameworks/Technologies
3
A software system is divided into highly flexible and re-usable components called services.
SOA is just an architecture blue print It is NOT a technical standard It is NOT a technology
2010-02-08
What is SOA?• SOA is an architectural
style of building software applications that promotes loose coupling between components for their reuse.
Coarse
grainedPlatform independent
Loosely coupledStandard Interface
4
Self-contained module that perform a predetermined task
Software component that have published contracts/interfaces
Black-box to the consumers
Platform-Independent
Interoperable
2010-02-08
What is Service ?
Systems today are bigger than ever before
Complexity increases exponentially with size
Systems need to be interconnected
OO solved the problems of small-medium sized systems
CO (Component Orientation) solved problems of medium-large systems
Neither OO nor CO could cope with the problems of very large systems, systems of systems, or integration between systems
Why SOA?
62010-02-08
Why SOA?
Order Manageme
nt
Provisioning
Inventory
Credit Manageme
nt
End Customer Portal Operator Portal Partner Portal
InvoicingNetwork Manageme
nt
Customer
Profiles
SalesManageme
ntBilling
Customer Info
Management
ServiceCatalog
Lets take a telecom enterprise system
72010-02-08
Why SOA?
Order Manageme
ntProvisionin
g
Inventory
Credit Manageme
nt
End Customer Portal Operator Portal Partner Portal
Invoicing
Network Manageme
ntCustome
r Profiles
SalesManageme
nt
Billing
Customer Info
Management
ServiceCatalog
Services
Towards Service-Oriented Architecture
Function oriented Build to last Prolonged
development cycles Application silos Tightly coupled Object oriented Known
implementation
Coordination oriented
Build to change Incrementally built
and deployed Enterprise solutions Loosely coupled Message oriented Abstraction
Managing services Service governance Performance Reliability security SLAs Interoperability of services
Challenges
10
Loose couplingMinimize dependencies.
Service contractServices adhere to a communications agreement.
Service abstraction Hide the service execution logic from the outside world.
Service reusabilityLogic is divided into services for reuse.
2010-02-08
SOA: Architectural Principles
11
Service composabilityServices can be assembled to form composite service.
Service autonomyServices have control over the logic they encapsulate.
Service discoverabilityServices can be found and assessed via available discovery mechanisms.
Service relevanceService presented at a granularity recognized by user a meaningful service.
2010-02-08
SOA: Architectural Principles
12
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.
Key differences between CORBA and web service are
2010-02-08
SOA Implementation
CORBA Web serviceData model Object Oriented SOAP message exchangeClient Server coupling Tightly coupled Loosely coupledTransfer Syntax CDR (binary) XML (UTF)Type System IDL XML SchemasState Stateful StatelessService Discovery CORBA Naming service UDDI
132010-02-08
Realizing SOA with
Web Services
14
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.
XML is used to tag the data, SOAP is used to transfer the data, WSDL is used for describing the services available and UDDI is used for listing what services are available.
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.
2010-02-08
What is web service ?
15
Lookup for the tomato sellersYellow Pages: contain companies that are
selling tomatoes, their location, and contact information.
2010-02-08
How to buy tomatoes ?
Find the service offered according to my needs
Where, when and how can I buy tomatoes?
Buy the tomatoesDo the transaction
16
Lookup for the Service ProviderRegistry: contain providers that are selling services, their location, and
contact information.
Find the service offered according to my needsWhere, when and how can I get the service?
Access the servicedo the transaction
2010-02-08
How to access a service?
17
XML (eXtensible Markup Language)A uniform data representation and exchange mechanism
SOAP (Simple Object Access Protocol)Lightweight (XML-based) protocol for exchange of information in a decentralized, distributed environment
WSDL (Web Service Description Language)XML format that describes the web service
UDDI (Universal Description Discovery and Integration)Like yellow pages of Web services
2010-02-08
Components of a web service
182010-02-08
3 roles of service
192010-02-08
Service Vs. Consumer
Service
describes
End Point Exposes
Messages Sends/Receives
Contracts
Binds to
Service Consumer implements
Policy governed by
Sends/Receives
Adheres to
Understands
Serves
20
1. Define the service implementation and compile it.
\WS>javac -d . HelloImpl.java
2. Use wsgen to generate the artifacts required to deploy the service.
\WS>wsgen -wsdl server.HelloImpl
3. Package the files into a WAR file and deploy it .
2010-02-08
Steps to develop a web serviceusing JAX-WS
package server;
import javax.jws.WebService;
@WebServicepublic class HelloImpl {
/** * @param name * @return Say hello to the person. */ public String sayHello(String name) { return "Hello, " + name + "!"; }}
212010-02-08
HelloImplService.wsdl
222010-02-08
HelloImplService.wsdl contd…
232010-02-08
HelloImplService_schema1.xsd
24
4. Implement Client Code
5. Use wsimport to generate and compile the web service artifacts needed to connect to the service.
\WS>wsimport HelloImplService.wsdlparsing WSDL...
generating code...
compiling code...
6. Run the client.
2010-02-08
Steps to develop a web service contd…
package myClient;
import helloservice.endpoint.HelloService;import helloservice.endpoint.Hello;
public class HelloClient {
public static void main(String[] args) { try { HelloService service = new HelloService(); Hello port = service.getHelloPort();
String response = port.sayHello(“Luqman"); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } }}
25
WSDL is a contract between service provider and the consumer
A WSDL document describes◦ What the service can do◦ Where it resides◦ How to invoke it
2010-02-08
WSDL
Types
Message
Operation
Port Type
Binding
Port
Service
WSDL
WSDL elements
26
TypesData type definition used in exchanging messages
MessageDescribes the logical content of data being communicated
OperationAn Abstract description of an action supported by the service
Port TypeA set of operations and messages involved with the service
BindingA concrete protocol and data format specification for a port type
PortA single end point defined as a combination of a binding and a network address
ServiceIdentifies which ports to group together
2010-02-08
WSDL elements
27
SOAP is a lightweight (XML-based) protocol for exchange of information in a decentralized, distributed environment.
SOAP is a format for sending messages SOAP is independent of transport
protocol
A SOAP message is an ordinary XML document containing the following elements:◦ Envelope - identifies the XML document
as a SOAP message◦ Header - contains application specific info
like authentication etc.◦ Body - contains the message in request
and response◦ Fault - contains errors and status
information
2010-02-08
SOAPSOAP EnvelopeSOAP Header
Header Block
Message Body
SOAP Body
Fault Handlers
SOAP message structure
28
<?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:Body xmlns:m="http://www.example.org/Hello"> <m:sayHello> <m:name>Luqman</m:name> </m:sayHello></soap:Body>
</soap:Envelope>
2010-02-08
SOAP Example
<?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:Body xmlns:m="http://www.example.org/stock"> <m:sayHelloResponse> <m:return>Hello Luqman</m:return> </m:sayHelloResponse></soap:Body>
</soap:Envelope>
Request
Response
29
SOAP errors are handled using a specialised envelope known as a Fault Envelope
A SOAP Fault is a special element which must appear as an immediate child of the body element
<faultcode> and <faultstring> are required.
2010-02-08
SOAP Fault
Printing SOAP MessageWite a new Class MySOAPHandlerImplement handleMessage
public class MySOAPHandler implements SOAPHandler<SOAPMessageContext>{ public boolean handleMessage(SOAPMessageContext context) { try { SOAPMessage message = context.getMessage(); if ((Boolean)context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY) == true){ System.out.println("Request Message: "); }else{ System.out.println("Response Message: "); } message.writeTo(System.out); } catch (Exception ex) { ex.printStackTrace(); } return true; }
public Set<QName> getHeaders() { return null; }
public boolean handleFault(SOAPMessageContext context) { return true; }
public void close(MessageContext context) { }}
Printing SOAP Message contd...Wite a new Class MyHandlerResolverImplement
getHandleChain
public class MyMessageHandlerResolver implements HandlerResolver { public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlerChain = new ArrayList<Handler>(); MySOAPHandler hh = new MySOAPHandler(); handlerChain.add(hh); return handlerChain; }}
Set the Handler Resolver in Client
Invoke the web methodRun the client
service.setHandlerResolver(new MyMessageHandlerResolver());
32
UDDI is a set of specifications that is used to publish information for describing and discovering web services, finding businesses, building registries.
UDDI is a directory for storing information about web services.
UDDI communicates via SOAP.
2010-02-08
UDDI
To query companies with their names and attributes
To query businesses with their categories
Contains technical info on how to interact with the services
3 levels of information in UDDI
White Pages
Yellow Pages
Green Pages
332010-02-08
UDDI Structure
342010-02-08
Registry APIs (SOAP Messages)
• Inquiry API• Find things
• find_business• find_service• find_binding• find_tModel
• Get Details about things• get_businessDetail• get_serviceDetail• get_bindingDetail• get_tModelDetail
• Publishers API• Save things
• save_business• save_service• save_binding• save_tModel
• Delete things• delete_business• delete_service• delete_binding• delete_tModel
• security…• get_authToken• discard_authToken
Write the implementation and interface Generate WSDL file>java org.apache.axis.wsdl.Java2WSDL -o AdderWSDL.wsdl -l
http://localhost:8080/axis/services/Adder luqman.AdderInterface Generate server side and client side classes>java org.apache.axis.wsdl.WSDL2Java -o . -p luqman.generated -s AdderWSDL.wsdl Bind web service with functionality provider Bundle required classesjar cfv adderServerSide.jar luqman\*.class luqman\generated\*.classCopy the jar in the server’s axis/WEB-INF/lib folder>jar cfv adderClientSide.jar luqman\generated\AdderInterface.class luqman\generated\
AdderInterfaceService.class luqman\generated\AdderInterfaceServiceLocator.class luqman\generated\AdderSoapBindingStub.class
Register web services with Axisjava org.apache.axis.client.AdminClient luqman\generated\deploy.wsdd Write Web service client
Developing a web service using Axis
Printing SOAP Message in AXIS
String requestMessage = _call.getMessageContext().getRequestMessage().getSOAPEnvelope().toString();
String responseMessage = _call.getMessageContext().getResponseMessage().getSOAPEnvelope().toString();
System.out.println(“Request SOAP Message” + requestMessage);System.out.println(“Request SOAP Message” + responseMessage);
Edit the generated code in AdderSoapBindingStub.class - In the corresponding method of the Stub class add the following lines of code after the _call.invoke(...) statement
Adding attachments to SOAP Message in AXIS
CalculatorService service = new CalculatorServiceLocator();Calculator calc = service.getcalculator();
Stub stub = (Stub) calc;FileDataSource fs = new FileDataSource(new File("E:/Code/testA.txt") );DataHandler dh = new DataHandler(fs);stub.addAttachment(dh);
Client Side Code
MessageContext message = _call.getMessageContext(); //.getRequestMessage(); Iterator it = message.getRequestMessage().getAttachments();while (it.hasNext()) { AttachmentPart part = (AttachmentPart) it.next(); try { System.out.println("File Name : " + part.getDataHandler().getDataSource().getName()); InputStream is = part.getDataHandler().getInputStream(); while (is.available() > 0) { System.out.print((char) is.read()); } } catch (Exception ex) { ex.printStackTrace(); }
Display the Attachment in StubEdit the generated code in AdderSoapBindingStub.class - In the corresponding method of the Stub class add the following lines of code after the _call.invoke(...) statement
382010-02-08
REST
39
Each unique URL is a representation of some objectEx : http://www.mycompany.com/india/hyd/employees
http://www. mycompany.com/india/hyd/employees/1234
HTTP GET Method operates on the resource.
Object state is transferred and stored at client.
Representation of the resource state in XML, JSON etc.
2010-02-08
RESTful web servicesREpresentational State Transfer
Every object has its own unique methods Methods can be remotely invoked over
the Internet A single URI represents the end-point,
and that's the only contact with the Web Data hidden behind method calls and
parameters Data is unavailable to Web applications
RPC vs REST
Every useful data object has an address Resources themselves are the targets for
method calls The list of methods is fixed for all
resources
RPC
REST
412010-02-08
RESTful web services contd…
Client side> Easy to experiment in browser> Broad programming language support> Choice of data formats> bookmarkable
Server side> Uniform Interface> Cacheable> Scalable> Easy failover
Benefits
> Resource identification through URI> Uniform interface
GET/PUT/POST/DELETE> Self-descriptive messages> Stateful interactions through hyperlinks
Principles
422010-02-08
ExampleRequestGET /india/hyd/employees/1234 HTTP/1.1Host: mycompany.comAccept: application/xml
ResponseHTTP/1.1 200 OKDate: Tue, 09 Feb 2010 11:41:20 GMTServer: Apache/1.3.6Content-Type: application/xml; charset=UTF-8
<?xml version="1.0"?><Employees xmlns="…"> <Employee name=“ABC”> … </Employee></Employees>
Method Resource
Representation
Statetransfer
432010-02-08
Developing a RESTful web service using JAX-WS
package com.sun.jersey.samples.helloworld.resources;
import javax.ws.rs.GET;import javax.ws.rs.Produces;import javax.ws.rs.Path;
@Path("/employees/{empid}")public class Employee{ @GET @Produces("text/xml") public String getEmployee(@PathParam(“empid") String empId) { ... … }}
Annotation
Description
@Path The @Path annotation's value is a relative URI path indicating where the Java class will be hosted, for example, /helloworld. You can also embed variables in the URIs to make a URI path template. For example, you could ask for the name of a user, and pass it to the application as a variable in the URI, like this, /helloworld/{username}.
@GET The @GET annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP GET requests. The behavior of a resource is determined by the HTTP method to which the resource is responding.
@POST The @POST annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP POST requests. The behavior of a resource is determined by the HTTP method to which the resource is responding.
@PUT The @PUT annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP PUT requests. The behavior of a resource is determined by the HTTP method to which the resource is responding.
@DELETE
The @DELETE annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTPDELETE requests. The behavior of a resource is determined by the HTTP method to which the resource is responding.
REST Annotations
Annotation Description
@HEAD The @HEAD annotation is a request method designator and corresponds to the similarly named HTTP method. The Java method annotated with this request method designator will process HTTP HEAD requests. The behavior of a resource is determined by the HTTP method to which the resource is responding.
@PathParam The @PathParam annotation is a type of parameter that you can extract for use in your resource class. URI path parameters are extracted from the request URI, and the parameter names correspond to the URI path template variable names specified in the @Path class-level annotation.
@QueryParam The @QueryParam annotation is a type of parameter that you can extract for use in your resource class. Query parameters are extracted from the request URI query parameters.
@Consumes The @Consumes annotation is used to specify the MIME media types of representations a resource can consume that were sent by the client.
@Produces The @Produces annotation is used to specify the MIME media types of representations a resource can produce and send back to the client, for example, "text/plain".
REST Annotations
Authentication ( Identity check ) Authorization ( Access Control ) Confidentiality ( Encryption ) Integrity ( Signature Support ) Non-repudiation ( Ability to prove that a particular transaction is performed) Accessibility ( Ensuring that the service is not impacted by
attacks)
2010-02-0846
Securing web servicesSSL is not enough
SSL provides point to point security
SSL provides security at transport level
SSL doesn’t support non-repudiation
WS needs end to end security
WS needs security at message level
Non-repudiation is critical for business WS
Web service security requirements
47
XML digital signature ( IETF and W3C) XML Encryption ( W3C) SAML (Secure Assertion Markup Language) ( OASIS) WS-Security (Web Services Security) (OASIS)
◦ WS-SecureConversation◦ WS-Federation◦ WS-Policy◦ WS-Trust◦ WS-Privacy
XACML (Extensible Access Control Markup Language) (OASIS)
2010-02-08
Web service security standards
“BPEL is an XML language for defining the composition of web services into new services”
BPEL would require that every process ◦ Either has a “center” of execution◦ A process is composed of a large set of orchestration
definitions interacting with each other
BPEL assumes that business processes can be fully captured in a single definition, including all possible exception paths◦ Not sure this is the right assumption
BPEL
Identify the partners in the process
Declare the Partners in the Process
Design the workflow of the process
Define up the workflow process
Declare the Process Using BPEL Activity Constructs
Add Business Logic Using BPELConstructs
BPEL Steps
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.
SoaML (SOA Modeling Language)
Dealer Network Architecture
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.
SOAML Example
The enterprise service bus (ESB) is a software infrastructure that facilitates application integration.
An ESB does not itself implement SOA but provides the features with which SOA can be implemented.
Examples◦ Glassfish ESB (Sun)◦ Websphere ESB (IBM)◦ Biztalk Server (Microsoft)◦ JBOSS ESB
ESB
Invocation
Routing
Mediation
Message Processing
Service Orchestration
Complex Event Processing
Management
Common ESB Characteristics
54
◦ SOAP - http://www.w3c.org/TR/soap
◦ WSDL - http://www.w3c.org/TR/wsdl
◦ UDDI - http://www.uddi.xml.org
◦ SAML - http://saml.xml.org
◦ ebXML - http://www.ebxml.org
◦ CORBA Vs. Web services - http://www2002.og/CDROM/alternate/395
◦ SoaML - http://www.omg.org/spec/SoaML
◦ BPEL - www.oasis-open.org/committees/wsbpel
2010-02-08
For more information
552010-02-08
Questions?
56
Thank You
2010-02-08