© 2010 IBM Corporation FI MU: SCA and SDO Tomáš Müller – IT Architekt tomas_muller@cz.ibm.com 22/11/2010 © 2010 IBM Corporation Building a smarter planet 2 Agenda A brief history of SOA Why SCA makes life simpler Composing and assembling SCA applications Code and other details Customer scenarios Service Data Objects Resources © 2010 IBM Corporation Building a smarter planet 3 Agenda A brief history of SOA Why SCA makes life simpler Composing and assembling SCA applications Code and other details Customer scenarios Service Data Objects Resources © 2010 IBM Corporation Building a smarter planet 4 A brief history of SOA When we started with Web services (SOAP over HTTP), we used XML to move data the idea was to send XML to a URL, invoking a service synchronously. Things have gotten more complicated since then: – Protocols other than HTTP – Document-style SOAP services instead of RPC – Asynchronous invocation with JMS – Encryption, conversations, reliable messaging, WS-* – Etc. © 2010 IBM Corporation Building a smarter planet 5 A component When dealing with a component (in an SOA or not), there are three important pieces of information: –The interface of the component –The implementation of the component –The access method to invoke the component We’ll consider how we use this information to invoke components. © 2010 IBM Corporation Building a smarter planet 6 The bad old days Originally, most components were hardwired into an application: – The application knew the details of the component’s interface at build time. – The application accessed the component’s implementation at build time. – The application knew the details of the component’s access method at build time. This worked (and still does), but the application is relatively brittle. – If the implementation or access method changes, we have to modify our code, rebuild it, retest it and redeploy it. © 2010 IBM Corporation Building a smarter planet 7 The early days of Web services SOAP introduced a way to invoke a remote service with an XML envelope. The SOAP infrastructure built the envelope and sent it to a particular URL; the SOAP service’s host invoked a service and sent XML back to us. – The application knew the details of the component’s interface at build time. – The application did not access the component’s implementation at build time; the component is invoked at run time by the SOAP infrastructure. – The application knew the details of the component’s access method at build time (usually SOAP/HTTP). © 2010 IBM Corporation Building a smarter planet 8 Next-generation SOA with SCA An SCA application is even more dynamic: –The application knows the details of the component’s interface at build time. –The application does not access the component’s implementation at build time; the component is invoked by the SCA invocation framework. –The application does not know the details of the component’s access method at build time; this is also handled by the SCA invocation framework. © 2010 IBM Corporation Building a smarter planet 9 osoa.org SCA and SDO were developed by the Open Service Oriented Architecture group (osoa.org): © 2010 IBM Corporation Building a smarter planet 10 The specifications work of osoa.org has been turned over to OASIS. The Open Composite Services Architecture group is being formed now. – See oasis-opencsa.org for more details. – Yes, the SCA work has moved to a group named CSA. – http://www.osoa.org/display/Main/Service+Component+Architecture+Specifications © 2010 IBM Corporation Building a smarter planet 11 11 A Brief History of SCA 20082007200620052004 consortiaApacheIBM Apache Tuscany enters incubation Apache Tuscany graduates OSOA Founded Open SCA submitted to OASIS Open SCA collaboration begins Open SCA 0.9 V6.1 SOA FeP Beta V7.0 SCA FeP Beta V7.0 SCA FeP GA RAD 7.5.2 SCA GA 2009 RAD 7.5.1 SCA Beta V6.0 RAD Open SCA WAS Open SCA WPS / WID Classic SCA V6.1 V6.2 V7.0 SCA v1.0.1 FeP GA V7.0 RAD 7.5.5 SCA GA First Public OASIS Drafts © 2010 IBM Corporation Building a smarter planet 12 Agenda A brief history of SOA Why SCA makes life simpler Composing and assembling SCA applications Code and other details Customer scenarios Service Data Objects Resources © 2010 IBM Corporation Building a smarter planet 13 Why SCA matters SCA gives your developers a single programming model for using services. As your SOA gets more complicated, your developers have to learn more and more interfaces. – In Java alone, you might have EJBs, RMI, JCA, JAX-WS or JAX-RPC. Similarly, SDO gives your developers a single programming model for using data sources. © 2010 IBM Corporation Building a smarter planet 14 You're committed to SOA, butYou're committed to SOA, but…… SCA solves these problems:SCA solves these problems: It's not convenient to convert everything to a Web service. You can integrate many kinds of components, not just Web services. You want to minimize the learning curve for your developers. Your developers don't have to learn the details of each component, they just connect them without learning a new API. As you have more components and data sources, you'll want to rewire your applications more often. When you integrate an SCA component or an SDO data source, you can replace the component/data source without changing your code. Your developers don't understand how to exploit the power of an SOA. Your developers focus on reusable business logic. SCA provides the SOA model and hides the middleware complexity from them. Why SCA matters © 2010 IBM Corporation Building a smarter planet 15 What SCA is An executable model for assembling services A simplified component programming model for implementing services – Write ‘em as BPEL processes, Java POJOs, EJBs, COBOL apps, PHP scripts, C++ apps… We won’t focus on this today, but an SCA composite definition includes all of the services that our composite depends upon. – Dependency management is much simpler. © 2010 IBM Corporation Building a smarter planet 16 What SCA isn’t A workflow model –Use BPEL for that Web services –Many SCA implementations will use Web services, but you can create SCA solutions with no Web services content Tied to a specific programming language, protocol, technology, runtime, etc. © 2010 IBM Corporation Building a smarter planet 17 The SCA specs There are four parts to the specs: –The Assembly Model How to define composite applications –The Client and Implementation specifications Java, C++, BPEL –Binding specifications How to use access methods – Web services, JMS, RMI-IIOP, REST… –Policy Framework How to add security, transactions, conversations, reliable messaging, etc. declaratively © 2010 IBM Corporation Building a smarter planet 18 Agenda A brief history of SOA Why SCA makes life simpler Composing and assembling SCA applications Code and other details Customer scenarios Service Data Objects Resources © 2010 IBM Corporation Building a smarter planet 19 Composition and assembly How do you package a service so it can be integrated with other services? SCA has a consistent model: –A simple service in SCA is called a componentcomponent. –Components can be grouped into compositescomposites. –Components and composites are hooked together with wireswires. We’ll use SCA diagrams to illustrate these concepts. All of the definitions and configuration are done in XML. © 2010 IBM Corporation Building a smarter planet 20 Symbols in SCA assembly diagrams Here are the symbols used in SCA assembly diagrams: – A green chevron represents a service. This is an entry point to the SCA component or composite. – A purple chevron represents a reference. This points to a service provided by something else. – A yellow rectangle represents a property. This is a value you can set when you invoke the component or composite. – A line represents a wire. This is the connection between a service reference and the service itself. © 2010 IBM Corporation Building a smarter planet 21 SCA symbols More symbols: A rounded rectangle represents a component. A component can have services, references and properties. A large rounded rectangle represents a composite. A composite contains one or more components. Like a component, it can have services, references and properties. A composite can also contain a composite. Component Composite C Component A Component B © 2010 IBM Corporation Building a smarter planet 22 Services and references A service or a reference has an interface and a binding. The interface might be a Java interface, a WSDL port type, a BPEL partner link, a C++ class, etc. The binding defines the access method. It might be SOAP/HTTP, JMS, JSON, RMI-IIOP, SCA, etc. serviceservice interface binding referencereference interface binding © 2010 IBM Corporation Building a smarter planet 23 Properties and implementations A property has a type and a value. A component has an implementation; that’s the code that actually provides the service. The implementation might be BPEL, Java, C++, Spring, etc. Component propertyproperty type value implementationimplementation © 2010 IBM Corporation Building a smarter planet 24 A component This diagram is a component with services, references and properties. servicesservices referencesreferences propertiesproperties type value type value interface binding interface binding interface binding interface binding Component A … … © 2010 IBM Corporation Building a smarter planet 25 Component A Component B Wiring wirewire … … Here are two components wired together: © 2010 IBM Corporation Building a smarter planet 26 Component A services references properties Component B A composite wire Composite C… … Here are two components grouped together in a composite: © 2010 IBM Corporation Building a smarter planet 27 Component A services references properties Component B compositecomposite referencereference compositecomposite serviceservice Promotion compositecomposite propertyproperty promotedpromoted referencereference wirepromotedpromoted serviceservice interface binding interface binding type value Composite C… … © 2010 IBM Corporation Building a smarter planet 28 A B Component D C ImplementationImplementation –– compositecomposite A composite implementation © 2010 IBM Corporation Building a smarter planet 29 A B Component D Component E C A composite using another component … … ImplementationImplementation –– compositecomposite © 2010 IBM Corporation Building a smarter planet 30 A … … B Component D Component E C Composite F A composite that includes a composite ImplementationImplementation –– compositecomposite © 2010 IBM Corporation Building a smarter planet 31 Synchronous / Asynchronous Model SCA provides the ability for services to be called synchronously or asynchronously Synchronous Model – Blocking Client waits for a response invokeAsync() Client Service further processing Asynchronous Model invoke () Client Service further processing Synchronous Model Asynchronous Model – Non-Blocking Client doesn’t wait for a response © 2010 IBM Corporation Building a smarter planet 32 Asynchronous Model There 3 types of asynchronous invocation models invokeAsync() Client Service further processing One Way invokeAsync() Client Service invokeResponse() further processing Deferred Response invokeAsync() Client Service onInvokeResponse() Request with Callback further processing © 2010 IBM Corporation Building a smarter planet 33 Asynchronous Model Synchronous vs. Pseudo Synchronous Synchronous Model – Blocking Client waits for a response invoke () Client Service further processing Synchronous Model invokeAsync() Client Service invokeResponse() further processing Deferred Response © 2010 IBM Corporation Building a smarter planet 34 34 SCA Summary Implementation ComponentService Reference • Java • Spring • BPEL • Composite … • C • C++ • COBOL … PropertyInterface • WSDL • Java … Binding Interface • WSDL • Java … Binding • SCA • WS • EJB • JMS • JCA • (JSON-RPC) • (AJAX) … • SCA • WS • EJB • JMS • JCA • (JSON-RPC) • (AJAX) … ** * Policy Set * PolicyIntent * © 2010 IBM Corporation Building a smarter planet 35 Agenda A brief history of SOA Why SCA makes life simpler Composing and assembling SCA applications Code and other details Customer scenarios Service Data Objects Resources © 2010 IBM Corporation Building a smarter planet 36 An SCA client Here’s an SCA client that uses SOAP/HTTPSOAP/HTTP: public class CalculatorClient { public static void main… { SCADomain scaDomain = SCADomain.newInstance("calc.composite"); CalculatorService calcServ = scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); System…println(calcServ.add(3,2)); scaDomain.close(); } } © 2010 IBM Corporation Building a smarter planet 37 An SCA client Here’s an SCA client that uses RMIRMI: public class CalculatorClient { public static void main… { SCADomain scaDomain = SCADomain.newInstance("calc.composite"); CalculatorService calcServ = scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); System…println(calcServ.add(3,2)); scaDomain.close(); } } © 2010 IBM Corporation Building a smarter planet 38 38 SCA Annotated Java package service; @Remotable public interface HelloService { String hello ( String message ); } package service; @Service ( HelloService.class ) public class HelloServiceImpl implements HelloService { @Reference public AnotherService anotherService; String hello ( String message ) { return anotherService.howdy(message); } } HelloComposite HelloService Component another Service Hello Service locale HelloServiceImpl © 2010 IBM Corporation Building a smarter planet 39 39 SCA Composite XML ... ... ... HelloComposite HelloService Component another Service Hello Service locale HelloServiceImpl © 2010 IBM Corporation Building a smarter planet 40 40 Qualities of Service – Intents and Policies Policies Composite Component WebService Binding Policy Policy WS-Policy Policy Set requires="authentication" requires="authentication" Lookup Interaction Intent Implementation Intent Interaction Intent © 2010 IBM Corporation Building a smarter planet 41 Bindings In SCA, a bindingbinding specifies how to access a service. – Current bindings include WSDL, JMS, JCA and EJBs. – More bindings are coming all the time at osoa.org. – Like all of SCA, the binding specification is open, so you can create your own. Add asynchronous support, conversational support, etc. declaratively: – – sca:requires="conversational" – sca:endsConversation="true" © 2010 IBM Corporation Building a smarter planet 42 Policies Previous standards efforts, WSDL in particular, didn’t include how to define general policiespolicies for services. –Nowadays is situation better due to WS-Policy, WS-PolicyAttachment SCA gives you a single declarative way to establish policies. –“This component must provide this level of QoS.” –“All traffic on this wire must be digitally signed.” © 2010 IBM Corporation Building a smarter planet 43 What’s in the WSDL file? The data structures – Defined with XML Schema The interface – There’s a method called getStockQuote, it takes a string as input and returns a string as output The binding(s) – SOAP over HTTP The endpoint(s) – http://xyz.com:8080/myService Ideally the bindings and endpoints are in a separate file. – Unfortunately, that doesn’t always happen. © 2010 IBM Corporation Building a smarter planet 44 What can I do with the WSDL file? Send a SOAP envelope to a particular service over a particular protocol. – That’s it. A Service-Oriented Architecture needs a far more sophisticated way of working with services. © 2010 IBM Corporation Building a smarter planet 45 Doing more sophisticated things “Everyone using this service must be authenticated.” – The WSDL file won’t tell you that. “Every request sent to this service must be digitally signed.” – The WSDL file won’t tell you that. “Any message sent to this service is guaranteed to be delivered.” – The WSDL file won’t tell you that. “Particular service ensures specific QoS.” – The WSDL file won’t tell you that. “Every message sent to this service must be encrypted.” – The WSDL file won’t tell you that. “Every request to this service …” – SCA tells you everything you need to know. © 2010 IBM Corporation Building a smarter planet 46 The problem with the missing stuff Without this information, nothing works. – That’s a big problem. SCA solves this problem in an elegant way.SCA solves this problem in an elegant way. – The details we just mentioned are handled by the SCA runtime. – Those details can be changed without any changes to the client application or the service. © 2010 IBM Corporation Building a smarter planet 47 Agenda A brief history of SOA Why SCA makes life simpler Composing and assembling SCA applications Code and other details Service Data Objects Resources © 2010 IBM Corporation Building a smarter planet 48 Service Data Objects SDO gives you a single API to a wide variety of data sources. You and I as developers focus on CRUD operations, we don’t know or care what the data source actually is. – Relational database – XML database or XML file – EJB – Web service – JCA © 2010 IBM Corporation Building a smarter planet 49 A disconnected interface to many kinds of data sources Client Data Access Service RDB XML DB EJB Web service JCA Data object Data graph Change summary JDBC XPath/ XQuery Local XML/HTTP CCI/ Proprietary © 2010 IBM Corporation Building a smarter planet 50 Accessing data in SDO I have some data. I use the data wherever and however it’s stored (RDBMS, XML file, LDAP, etc.) I use the most convenient language for CRUD operations on the data (SQL, XQuery, modified XPath, etc.) © 2010 IBM Corporation Building a smarter planet 51 Service Message Object ServiceMessageObject headers context body SMOHeader JMSHeader SOAPHeader correlation transient shared Mediation primitives process messages as SMOs The SMO is an extension of the Business Object (BO) structure It contains: context, message headers, fault details, an array of properties and payload information © 2010 IBM Corporation Building a smarter planet 52 Service Message Object API Accessible by API (com.ibm.websphere.sibx.smo.*) ServiceMessageObject headers context body SMOHeader JMSHeader SOAPHeader correlation transient shared ServiceMessageObject context transient ServiceMessageObject smo = (ServiceMessageObject)a_type; DataObject context = smo.getContext() DataObject transient = context.getTransientContext(); © 2010 IBM Corporation Building a smarter planet 53 SMO – some Java APIs import com.ibm.websphere.sibx.smobo.ContextType; import com.ibm.websphere.sibx.smobo.HeadersType; import commonj.sdo.DataObject; public DataObject execute(DataObject a_type) { ContextType context = (ContextType) a_type.get("/context"); HeadersType headers = (HeadersType) a_type.get("/headers"); DataObject body = (DataObject) a_type.get("/body"); return a_type; } © 2010 IBM Corporation Building a smarter planet 54 54 Open Service Component Architecture (Open SCA) An open, emerging standard programming model for assembling flexible SOA business solutions from diverse, reusable service enabled IT assets RAD 7.5.2+ SCA Tools WAS 7 SCA Feature Pack Develop interfaces and implementations. Compose and Wire. Bindings and Intents. Define, install and run contributions on WebSphere Application Server. © 2010 IBM Corporation Building a smarter planet 55 Agenda A brief history of SOA Why SCA makes life simpler Composing and assembling SCA applications Code and other details Service Data Objects Resources © 2010 IBM Corporation Building a smarter planet 56 Resources The home of everything related to SCA and SDO is osoa.org. – From here you can find the specs, white papers and tutorials. The OSOA’s work is moving to OASIS. For more information on the Open CSA project, visit oasis-opencsa.org. If you’d like to get involved in the standardization effort, a call for participation has recently been issued. The oasis-opencsa.org/specifications page is another great way to find the specifications and other technical resources. © 2010 IBM Corporation Building a smarter planet 57 Books Get Ben Margolis’ book SOA for the Business Developer: Concepts, BPEL and SCA. As of August 2007, this is the best book on SCA. It covers both the architecture and the technical details. Many of the best minds in the SCA world had a hand in this book. ISBN 1-58347-065-4 © 2010 IBM Corporation Building a smarter planet 58 developerWorks articles An overview of Service Component Architecture (2 parts): – ibm.com/developerworks/webservices/library/ ws-soa-scadev1/ and .../ws-soa- scadev2/ Building SOA solutions with SCA (4 parts): – ibm.com/developerworks/websphere/techjournal/0510_brent/0510_brent.html Java SCA invocation styles: – ibm.com/developerworks/webservices/library/ ws-soa-scajava/ Using PHP’s SCA and SDO extensions: – ibm.com/developerworks/webservices/library/ ws-soa-scasdo/ © 2010 IBM Corporation Building a smarter planet 59 developerWorks articles Introduction to Service Data Objects: – ibm.com/developerworks/java/library/j-sdo/ Build a Web service client with JSF and SDO (Flash demo): – ibm.com/developerworks/offers/lp/demos/ summary/jsfsdo.html/ SDO 2.0: Create and read an XML document based on an XML Schema: – ibm.com/developerworks/webservices/library/ ws-sdoxmlschema/ More articles on SCA and SDO are coming all the time.