Published on

Published in: Technology
  • Be the first to comment


  1. 1. Integration of Apache Servicemix &Cxf
  2. 2. About Auther  Fang Yue (Freeman Fang freeman.fang@gmail.com)  Apache Cxf commiter and PMC member  Apache Servicemix commiter and PMC member
  3. 3. useful link  http://servicemix.apache.org  http://cxf.apache.org
  4. 4. Agenda  What is JBI?  JBI 1.0 & Apache Servicemix 3.x  CXF-BC & CXF-SE  Apache Servicemix 4.0
  5. 5. What is JBI?  JBI defines an architecture that allows the construction of integration systems from plug-in components, that interoperate through the method of mediated message exchange. (JBI 1.0 spec, JSR 208)  Keywords: plugin, MEPS, NMR
  6. 6. What is JBI?
  7. 7. JBI 1.0: Architecture
  8. 8. JBI 1.0  WSDL Messaging Model  Component  Normalized Message Router (NMR)  Management  Package  Deployment  Monitoring
  9. 9. JBI 1.0: WSDL messaging model  Abstract model  Concrete model  Service providers  Service consumers
  10. 10. JBI 1.0: WSDL messaging model Message type Normal Faults Operation Qualified name Message Exchange Pattern Message types Interface Qualified name Operations Extended interfaces
  11. 11. JBI 1.0: WSDL messaging model  Binding type  Endpoint Endpoint name Binding type  Service Qualified name Interface name Endpoints
  12. 12. a real wsdl-part 1 <wsdl:definitions name=quot;wsdl-firstquot; xmlns:wsdl=quot;http://schemas.xmlsoap.org/wsdl/quot; xmlns:soap=quot;http://schemas.xmlsoap.org/wsdl/soap/quot; xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xmlns:tns=quot;http://servicemix.apache.org/samples/wsdl-firstquot; xmlns:typens=quot;http://servicemix.apache.org/samples/wsdl-first/typesquot; targetNamespace=quot;http://servicemix.apache.org/samples/wsdl-firstquot;> <wsdl:types> <xsd:schema targetNamespace=quot;http://servicemix.apache.org/samples/wsdl-first/typesquot; elementFormDefault=quot;qualifiedquot;> <xsd:element name=quot;GetPersonquot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;personIdquot; type=quot;xsd:stringquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name=quot;GetPersonResponsequot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;personIdquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;ssnquot; type=quot;xsd:stringquot;/> <xsd:element name=quot;namequot; type=quot;xsd:stringquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name=quot;UnknownPersonFaultquot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;personIdquot; type=quot;xsd:stringquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types>
  13. 13. a real wsdl – part 2 <wsdl:message name=quot;GetPersonRequestquot;> <wsdl:part name=quot;payloadquot; element=quot;typens:GetPersonquot;/> </wsdl:message> <wsdl:message name=quot;GetPersonResponsequot;> <wsdl:part name=quot;payloadquot; element=quot;typens:GetPersonResponsequot;/> </wsdl:message> <wsdl:message name=quot;UnknownPersonFaultquot;> <wsdl:part name=quot;payloadquot; element=quot;typens:UnknownPersonFaultquot;/> </wsdl:message> <wsdl:portType name=quot;Personquot;> <wsdl:operation name=quot;GetPersonquot;> <wsdl:input message=quot;tns:GetPersonRequestquot;/> <wsdl:output message=quot;tns:GetPersonResponsequot;/> <wsdl:fault name=quot;UnknownPersonquot; message=quot;tns:UnknownPersonFaultquot;/> </wsdl:operation> </wsdl:portType> <wsdl:binding name=quot;PersonSOAPBindingquot; type=quot;tns:Personquot;> <soap:binding style=quot;documentquot; transport=quot;http://schemas.xmlsoap.org/soap/httpquot; /> <wsdl:operation name=quot;GetPersonquot;> <wsdl:input> <soap:body use=quot;literalquot; /> </wsdl:input> <wsdl:output> <soap:body use=quot;literalquot; /> </wsdl:output> <wsdl:fault name=quot;UnknownPersonquot;> <soap:fault use=quot;literalquot; name=quot;UnknownPersonquot; /> </wsdl:fault> </wsdl:operation> </wsdl:binding> <wsdl:service name=quot;PersonServicequot;> <wsdl:port binding=quot;tns:PersonSOAPBindingquot; name=quot;soapquot;> <soap:address location=quot;http://localhost:8092/PersonService/quot; /> </wsdl:port> </wsdl:service> </wsdl:definitions>
  14. 14. Java interface @WebService(targetNamespace = quot;http://servicemix.apache.org/samples/wsdl-firstquot;, name = quot;Personquot;) public interface Person { @ResponseWrapper(localName = quot;GetPersonResponsequot;, targetNamespace = quot;http://servicemix.apache.org/samples/wsdl- first/typesquot;, className = quot;org.apache.servicemix.samples.wsdl_first.types.GetPersonResponsequot;) @RequestWrapper(localName = quot;GetPersonquot;, targetNamespace = quot;http://servicemix.apache.org/samples/wsdl-first/typesquot;, className = quot;org.apache.servicemix.samples.wsdl_first.types.GetPersonquot;) @WebMethod(operationName = quot;GetPersonquot;) public void getPerson( @WebParam(mode = WebParam.Mode.INOUT, name = quot;personIdquot;, targetNamespace = quot;http://servicemix.apache.org/samples/ wsdl-first/typesquot;) javax.xml.ws.Holder<java.lang.String> personId, @WebParam(mode = WebParam.Mode.OUT, name = quot;ssnquot;, targetNamespace = quot;http://servicemix.apache.org/samples/wsdl- first/typesquot;) javax.xml.ws.Holder<java.lang.String> ssn, @WebParam(mode = WebParam.Mode.OUT, name = quot;namequot;, targetNamespace = quot;http://servicemix.apache.org/samples/wsdl- first/typesquot;) javax.xml.ws.Holder<java.lang.String> name ) throws UnknownPersonFault; }
  15. 15. Component  Binding Component  To communicate using remote protocols  To normalize/denormalize messages it receives  Examples:  servicemix-file  servicemix-ftp  servicemix-cxf-bc  Service Engine  A service engine (SE) provides some type of logic inside the JBI environment and only communicates with the NMR.  Examples:  servicemix-bean  servicemix-camel  servicemix-cxf-se
  16. 16. Nomarlized Message Router  Consumer & Provider  Normalized Message  Delivery Channel  Message Exchange Pattern (MEP)  Endpoints  Run-time Endpoint Activation
  17. 17. Normalized Message Router The Normalized Message Router (or NMR) receives message exchanges from JBI components and routes them to the appropriate component for processing. This decouples the service producers from consumers and enable additional processing.
  18. 18. Provider & Consumer  WSDL Description  Abstract Model  Decoupled
  19. 19. Message Normalization  Message normalization/denormalization is the act of converting a message from/ to a protocol-specific format into a format for the JBI environment. This normalization is performed by BCs involves converting all messages into a NormalizedMessage.  A Normalized Message consist of following:  The “payload”, or bare message: an XML document that conforms to an abstract WSDL message type.  Message properties (sometime called metadata). These hold extra data associated with the message, key-value  Attachments: Extra (generally binary) attachments to the main message object.
  20. 20. what NMR looks like id: ID: status: Active role: provider service: {http://apache.org/cxf/calculator}CalculatorService endpoint: CalculatorPort operation: {http://apache.org/cxf/calculator}add in: <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?><message xmlns=quot;http://java.sun.com/xml/ns/jbi/wsdl-11-wrapperquot;> <part> <add xmlns=quot;http://apache.org/cxf/calculator/typesquot;> <arg0>1</arg0> <arg1>2</arg1> </add> </part></message>
  21. 21. Delivery Channel A Delivery Channel is a bidirectional asynchronous communication pipes between a component and the NMR. A service consumer uses its delivery channel to initiate a service invocation, while the provider uses its delivery channel to receive such invocations. Each component is provided with a single delivery channel, so the same channel is used for both inbound and outbound communications.
  22. 22. Message Exchange Pattern  In-Only: consumer issues a request to provider with no error (fault) path provided  Robust In-Only: consumer issues a request to provider. Provider may respond with a fault if it fails to process request.  In-Out: consumer issues a request to provider, with expectation of response. Provider may respond with a fault if it fails to process request.  In-Optional-Out: consumer issues a request to provider, which may result in a response. Consumer and provider both have the option of generating a fault in response to a message received during the interaction
  23. 23. In-Only MEP
  24. 24. Robust In-Only MEP
  25. 25. In-Out MEP
  26. 26. In-Optional-Out MEP
  27. 27. Endpoints JBI uses the same concept of endpoints as defined in WSDL 2.0. Endpoints refers to a particular address, accessible by a particular protocol, used to access a particular service. Endpoints have two distinct types:  External  External endpoints are endpoints outside the JBI environment. They are endpoints exposed by binding component acting as service consumers to expose an internal endpoint for the use of external service consumers  Internal  Internal endpoints are exposed by service providers inside the JBI environment. They are accessed using the NMR APIs.
  28. 28. Addressing In JBI, endpoints are referred to (or addressed) in three distinct ways: ● Implicitly: the NMR selects the endpoint based on the service type required. ● Explicitly: a consumer chooses the endpoint based on its own logic and configuration. ● Dynamically: an endpoint reference (EPR) is used within a message exchange to provide a “ call-back” address that the service provider should use to send further message exchanges. EPRs are xml fragment created and resolved by JBI components.
  29. 29. JBI Management It is JMX-based.  JBI Package.  Install & Deploy  ClassLoader
  30. 30. JBI Package  JBI defines a standard packaging for installing new components and deploying artifacts onto these components that can function as quot;containersquot;.All these artifacts contain a JBI descriptor in the META-INF directory called jbi.xml.  There are four types of artifacts, all packaged as zip or jar files:  Components installers contain the libraries and resources needed to run the component. Components can references Shared Libraries.  Shared Libraries are collection of jars that can be shared by several components  Service Units are artifacts meant to be deployed to a specific component. Aside from the JBI descriptor, the service unit packaging is specific to a component and can take various forms: a single XSLT style sheet, a BPEL process, or some java classes ...  Service assemblies are collections of Service Units. Service units can not be deployed directly and must be packaged in a service assembly which contains the service units and associated metadata.
  31. 31. Shared Lib <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <jbi xmlns=quot;http://java.sun.com/xml/ns/jbiquot; version=quot;1.0quot;> <shared-library class-loader-delegation=quot;parent-firstquot; version=quot;3.2.4-SNAPSHOTquot;> <identification> <name>servicemix-shared</name> <description>ServiceMix :: Shared</description> </identification> <shared-library-class-path> <path-element>lib/servicemix-shared-3.2.4-SNAPSHOT.jar</path-element> <path-element>lib/servicemix-common-3.2.4-SNAPSHOT.jar</path-element> <path-element>lib/servicemix-soap-3.2.4-SNAPSHOT.jar</path-element> <path-element>lib/bcprov-jdk14-136.jar</path-element> <path-element>lib/opensaml-1.1.jar</path-element> <path-element>lib/xmlsec-1.3.0.jar</path-element> <path-element>lib/servicemix-soap2-3.2.4-SNAPSHOT.jar</path-element> <path-element>lib/wss4j-1.5.4.jar</path-element> <path-element>lib/commons-logging-1.1.jar</path-element> <path-element>lib/xmlsec-1.4.0.jar</path-element> <path-element>lib/opensaml-1.1.jar</path-element> <path-element>lib/axis-ant-1.4.jar</path-element> <path-element>lib/xml-apis-1.3.04.jar</path-element> <path-element>lib/xercesImpl-2.8.1.jar</path-element> <path-element>lib/bcprov-jdk15-132.jar</path-element> <path-element>lib/XmlSchema-1.3.2.jar</path-element> <path-element>lib/woden-1.0.0M6.jar</path-element> </shared-library-class-path> </shared-library> </jbi>
  32. 32. component <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <jbi xmlns=quot;http://java.sun.com/xml/ns/jbiquot; version=quot;1.0quot;> <component type=quot;binding-componentquot; component-class-loader-delegation=quot;parent-firstquot; bootstrap-class-loader-delegation=quot;parent-firstquot;> <identification> <name>servicemix-file</name> <description>ServiceMix :: File</description> </identification> <component-class-name>org.apache.servicemix.file.FileComponent</component-class-name> <component-class-path> <path-element>lib/servicemix-file-3.2.4-SNAPSHOT.jar</path-element> <path-element>lib/commons-logging-1.1.jar</path-element> <path-element>lib/xercesImpl-2.8.1.jar</path-element> <path-element>lib/xml-apis-1.3.04.jar</path-element> <path-element>lib/log4j-1.2.13.jar</path-element> </component-class-path> <bootstrap-class-name>org.apache.servicemix.common.DefaultBootstrap</bootstrap-class-name> <bootstrap-class-path> <path-element>lib/servicemix-file-3.2.4-SNAPSHOT.jar</path-element> <path-element>lib/commons-logging-1.1.jar</path-element> <path-element>lib/xercesImpl-2.8.1.jar</path-element> <path-element>lib/xml-apis-1.3.04.jar</path-element> <path-element>lib/log4j-1.2.13.jar</path-element> </bootstrap-class-path> <shared-library version=quot;3.2.4-SNAPSHOTquot;>servicemix-shared</shared-library> </component> </jbi>
  33. 33. service assembly <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <jbi xmlns=quot;http://java.sun.com/xml/ns/jbiquot; version=quot;1.0quot;> <service-assembly> <identification> <name>wsdl-first-cxf-sa</name> <description>ServiceMix :: Samples :: WSDL first :: SA</description> </identification> <service-unit> <identification> <name>wsdl-first-cxfse-su</name> <description>ServiceMix is an open source ESB based on the Java Business Integration framework - JSR-208</description> </identification> <target> <artifacts-zip>wsdl-first-cxfse-su-3.3.zip</artifacts-zip> <component-name>servicemix-cxf-se</component-name> </target> </service-unit> <service-unit> <identification> <name>wsdl-first-cxfbc-su</name> <description>ServiceMix is an open source ESB based on the Java Business Integration framework - JSR-208</description> </identification> <target> <artifacts-zip>wsdl-first-cxfbc-su-3.3.zip</artifacts-zip> <component-name>servicemix-cxf-bc</component-name> </target> </service-unit> </service-assembly> </jbi>
  34. 34. Package Install & Deploy  For the shared library & component, it is called installation  For the service assembly, it is called deployment  In general, Container Developer (like us) write the component, Application Developer write the serivce unit and service assembly.
  35. 35. ClassLoader  There are several classloaders involved in ServiceMix:  the container class loader.  shared library class loader: the parent is the container class loader.  component class loader: parents are container class loader + any referenced SL class loader.  service unit class loader: parent is the component class loader.  Two kinds of classloader algorithm.  parent-first. (by default)  self-first.
  36. 36. CXF-BC & CXF-SE  why we integrate cxf into servicemix?  what's the key components for this integration?
  37. 37. Cxf BC  cxf bc consumer  cxf bc provider  http support  https support  jms support  ws-* support
  38. 38. cxf bc endpoint configuration <cxfbc:consumer wsdl=quot;/wsdl/calculator.wsdlquot; service=quot;calculator:CalculatorServicequot; endpoint=quot;CalculatorPortquot; targetEndpoint=quot;CalculatorPortProxyquot; targetService=quot;calculator:CalculatorServicequot; targetInterface=quot;calculator:CalculatorPortTypequot;> </cxfbc:consumer> <cxfbc:provider wsdl=quot;/wsdl/calculator.wsdlquot; locationURI=quot;http://localhost:9001/bridgetestquot; service=quot;calculator:CalculatorServicequot; endpoint=quot;CalculatorPortProxyquot; interfaceName=quot;calculator:CalculatorPortTypequot; > </cxfbc:provider>
  39. 39. Cxf SE  jax-ws frontend  simple frontend  jaxb databinding  aegis databinding  MTOM support  client proxy
  40. 40. Cxf SE configuration <cxfse:endpoint> <cxfse:pojo> <bean class=quot;org.apache.cxf.calculator.CalculatorImplquot;> </bean> </cxfse:pojo> <cxfse:inInterceptors> <bean class=quot;org.apache.cxf.interceptor.LoggingInInterceptorquot;/> </cxfse:inInterceptors> <cxfse:outInterceptors> <bean class=quot;org.apache.cxf.interceptor.LoggingOutInterceptorquot;/> </cxfse:outInterceptors> </cxfse:endpoint> <cxfse:endpoint> <cxfse:pojo> <bean class=quot;org.apache.servicemix.cxfse.GreeterImplForClientProxyquot;> <property name=quot;calculatorquot;> <cxfse:proxy service=quot;calculator:CalculatorServicequot; context=quot;#contextquot; type=quot;org.apache.cxf.calculator.CalculatorPortTypequot; /> </property> </bean> </cxfse:pojo> </cxfse:endpoint>
  41. 41. typical scenario external client<==>cxf bc cosumer<==NMR==>cxf se endpoint or client proxy in cxf se<==NMR==>cxf bc provider<===>external server
  42. 42. JBI binding & JBI transport  src code is in cxf code base  JBI binding is responsible for the Marshalling/Unmarshalling  JBI transport is reponsible for receiving and sending message using JBI api
  43. 43. Soap Message VS JBI Message <soap:Envelope xmlns:soap=quot;http://www.w3.org/2003/05/soap-envelopequot;> <soap:Body> <add xmlns=quot;http://apache.org/cxf/calculator/typesquot;> <arg0>1</arg0> <arg1>2</arg1> </add> </soap:Body> </soap:Envelope> <jbi:message xmlns:jbi=quot;http://java.sun.com/xml/ns/jbi/wsdl-11-wrapperquot; xmlns:msg=quot;http://apache.org/cxf/calculatorquot; name=quot;addquot; type=quot;msg:addquot; version=quot;1.0quot;> <jbi:part> <add xmlns=quot;http://apache.org/cxf/calculator/typesquot;> <arg0>1</arg0> <arg1>2</arg1> </add> </jbi:part> </jbi:message>
  44. 44. JBI 1.0: Lesson Learned  Pros  Normalized exchanges  Normalized Message Router  Cons  Classloader architecture. (jar version conflict issue)  JBI packaging. (too complicated)  Writing components is complex.
  45. 45. Servicemix 4.0  Goal  runtime  building blocks
  46. 46. Servicemix 4.0 : Goal  Enterprise OSGi Container  Lightweight  ESB and SOA container  Ease of use
  47. 47. SMX4.0: Ease of Use  No more components.  Deployment / Classloader is delegated to OSGi.  Bundles as the packaging and extension mechanism.  Leverage OSGi architecture.  Leverage spring-osgi (optionally)  Endpoints as first-class citizens  Endpoint are activated when registered in the OSGi registry.  Channel is now on the Endpoint.  Endpoints use push delivery rather than pulling the channel.
  48. 48. SMX4.0: Runtime  Hot deployment of OSGi bundles.  Dynamic reloadable configuration.  Extensible Shell console(Gshell).  Remote access.  Running multiple instances.
  49. 49. building blocks  avoid reinventing the wheel Framework: OSGi (Apache Felix) SOAP support: Apache CXF JMS broker: Apache ActiveMQ Routing Engine: Apache Camel
  50. 50. Moreover Any kind of contribution is welcome!!!
  51. 51. More on Camel??  please refer to Willem's Ride on Camel
  52. 52. Questions?