Deploying Web Services into ServiceMix with CXF Adrian Trenaman, January 27 th  2011 twitter : adrian_trenaman | LinkedIn:...
When you joined today’s session … <ul><li>Audio is broadcast from your computer   </li></ul><ul><ul><li>Submit your questi...
Our Speaker – Adrian Trenaman <ul><li>15 years IT consulting experience </li></ul><ul><ul><li>IONA Technologies, Progress ...
The goal – deploy / consume web services in ServiceMix <ul><li>Let’s assume you know about Web Services, SOA, etc., and fo...
Agenda: implementing web services with CXF and ServiceMix <ul><li>A look at the options available to you… </li></ul><ul><u...
Deploying web services using JEE web archives (WARs) <ul><li>ServiceMix supports WARs using the Jetty servlet engine. </li...
Deploying web services using OSGi bundles <ul><li>Package as an OSGi bundle with Spring-DM or ‘Blueprint’ meta-data. </li>...
Deploying web services using JBI service assemblies <ul><li>Can configure the transport using the CXF ‘binding component’ ...
Using CXF with Camel in ServiceMix <ul><li>Can use the  camel-cxf  component to create integration flows that provide and ...
All these choices… <ul><li>Apache ServiceMix thrives on innovation and experimentation. </li></ul><ul><ul><li>…  it’s not ...
Key techniques for developing CXF services with ServiceMix (Fuse ESB)
Ticklist – creating a service <ul><li>Generate JAX-WS code from WSDL </li></ul><ul><ul><li>…  using the Maven  cxf-codegen...
Using the cxf-codegen-plugin Maven-friendly location for generated code! Location of WSDL file
Creating an SEI implementation class Important – these annotations will affect the generated WSDL! …  whatever code you li...
Configuring a service implementation using Spring Framework Here’s where we define the endpoint, and tie it to your implem...
Aside: the modularity of CXF <ul><li>CXF is a modular runtime. </li></ul><ul><ul><li>By default the runtime assumes that  ...
Packaging - WAR <ul><li>For war packaging, you should place your Spring configuration in  src/main/resources/cxf-servlet.x...
Packaging – WAR (cont’) – web.xml All the services will have their address prefixed with ‘/services/’. This configures the...
Packaging – WAR (cont’) – maven-war-plugin Indicates the location of the web.xml descriptor. Includes the WSDL files in th...
Demo – deploy the WAR!
Packaging – OSGi bundles <ul><li>The Spring configuration should be placed in the  META-INF/spring  directory in  src/main...
Packaging – OSGi bundles (cont’) – maven-bundle-plugin ‘ !’ denotes  do not  export these packages. ‘ *’ says scan the cla...
Demo – deploy the OSGi bundle!
Invoking on a service – configuring a client with Spring Very easy to configure a client proxy  
Invoking on a service – Java code <ul><li>You can now invoke on the customer web service just like a local Java call. </li...
Summing up <ul><li>Fuse ESB (Apache ServiceMix) gives you a number of options on how to implement and consume web services...
Next Webinars <ul><li>See  http://fusesource.com/resources/video-archived-webinars /   </li></ul><ul><li>March 3 rd  2011:...
Useful references <ul><li>FuseSource –  http://fusesource.com </li></ul><ul><ul><li>http://fusesource.com/products/enterpr...
Learn More at http://fusesource.com
Upcoming SlideShare
Loading in …5
×

WebServices in ServiceMix with CXF

17,059 views

Published on

Instructional webinar on how to create an consume web services with Apache ServiceMix using Apache CXF. We cover code generation, JAX-WS implementation, Spring configuration and both WAR and OSGi bundle-based deployment models.

Published in: Technology
  • Be the first to comment

WebServices in ServiceMix with CXF

  1. 1. Deploying Web Services into ServiceMix with CXF Adrian Trenaman, January 27 th 2011 twitter : adrian_trenaman | LinkedIn: adrian.trenaman http://trenaman.blogspot.com
  2. 2. When you joined today’s session … <ul><li>Audio is broadcast from your computer </li></ul><ul><ul><li>Submit your questions via the Chat Window </li></ul></ul><ul><ul><li>Contact today’s Host </li></ul></ul><ul><ul><li>via the Chat Window </li></ul></ul>
  3. 3. Our Speaker – Adrian Trenaman <ul><li>15 years IT consulting experience </li></ul><ul><ul><li>IONA Technologies, Progress Software Corp, FuseSource </li></ul></ul><ul><ul><li>Committer, Apache Karaf </li></ul></ul><ul><ul><li>SOA, ESB, Open Source, BPM, Web Services, CORBA, … </li></ul></ul><ul><li>Solution focused: architecting, mentoring, speaking, engineering, doing… </li></ul><ul><li>PhD Artificial Intelligence </li></ul><ul><ul><li>Dip. Business Development </li></ul></ul><ul><ul><li>BA Mod Computer Science </li></ul></ul>http://trenaman.blogspot.com http://slideshare.net/trenaman twitter: adrian_trenaman LinkedIn: adrian.trenaman
  4. 4. The goal – deploy / consume web services in ServiceMix <ul><li>Let’s assume you know about Web Services, SOA, etc., and focus on the question ‘how do I create or use web services with ServiceMix?’ </li></ul><<servicemix>> :FuseESB <<web-service>> :MyBusinessLogic 8181 WSDL, XSD Clients in Java, .Net, C++, etc. can easily access your business logic over the network through a standards-based interface – WSDL & XSD http://frodo.mycompany.com:8181/
  5. 5. Agenda: implementing web services with CXF and ServiceMix <ul><li>A look at the options available to you… </li></ul><ul><ul><li>WARs, OSGi bundles, JBI assemblies, Camel routes, … </li></ul></ul><ul><li>Key techniques you need to know: </li></ul><ul><ul><li>Code generation: WSDL, XSD -> JAX-WS, JAX-B </li></ul></ul><ul><ul><li>Implementing services </li></ul></ul><ul><ul><li>Instantiating services and consumers using Spring </li></ul></ul><ul><ul><li>WAR-based packaging and deployment </li></ul></ul><ul><ul><li>OSGi bundle-based packaging deployment </li></ul></ul><ul><li>Useful references for your future work. </li></ul>
  6. 6. Deploying web services using JEE web archives (WARs) <ul><li>ServiceMix supports WARs using the Jetty servlet engine. </li></ul><ul><li>You must install the ServiceMix ‘war’ feature… </li></ul><ul><ul><li>… and copy the ‘war’ file to the <servicemix-base>/deploy directory. </li></ul></ul><ul><li>Benefits: </li></ul><ul><ul><li>Simple WAR deployment </li></ul></ul><ul><li>Drawbacks </li></ul><ul><ul><li>‘ Fat’ deployment, approx 8Mb per service. </li></ul></ul><<servicemix>> :FuseESB <<war>> :CXFServlet :SvcImpl 8181 <<feature>> :war
  7. 7. Deploying web services using OSGi bundles <ul><li>Package as an OSGi bundle with Spring-DM or ‘Blueprint’ meta-data. </li></ul><ul><ul><li>Service can use it’s own HTTP Jetty engine or share the OSGi HTTP service. </li></ul></ul><ul><li>Benefits: </li></ul><ul><ul><li>Adopt modular OSGi architecture with shared services and shared code. </li></ul></ul><ul><ul><li>Versioned artifacts </li></ul></ul><ul><ul><li>Lightweight deployables – approx 16k (500 times smaller than equivalent WAR!) </li></ul></ul><ul><ul><li>Allows ‘per-service’ control over HTTP port configuration </li></ul></ul><<servicemix>> :FuseESB <<bundle>> :SvcImpl 8008 <<feature>> :cxf
  8. 8. Deploying web services using JBI service assemblies <ul><li>Can configure the transport using the CXF ‘binding component’ and the implementation using the CXF ‘service engine’. </li></ul><ul><li>Benefits: </li></ul><ul><ul><li>Can integrate with other JBI components. </li></ul></ul><ul><li>Drawbacks: </li></ul><ul><ul><li>JBI packaging often overly complicated for most cases. </li></ul></ul><ul><li>Recommendation : prefer the OSGi, WAR or Camel (next slide!) approaches. </li></ul><<servicemix>> :FuseESB <<jbi-su>> :JBIEndpoint 8008 <<feature>> :jbi <<jbi-su>> :SvcImpl NMR
  9. 9. Using CXF with Camel in ServiceMix <ul><li>Can use the camel-cxf component to create integration flows that provide and consume SOAP or REST interfaces. </li></ul><ul><li>Benefits </li></ul><ul><ul><li>Easily route marshaled (JAX-B) or unmarshaled (DomSource / SoapMessage) content. </li></ul></ul><ul><ul><li>Build elegant integration flows based on Enterprise Integration Patterns (EIPs) </li></ul></ul><ul><ul><li>Can integrate with ServiceMix 4’s NMR for scalability, flexibility and clustering. </li></ul></ul><ul><li>See the next webinar for more! </li></ul><<servicemix>> :FuseESB <<bundle>> :CXFEndpont 8008 <<feature>> :camel-cxf :Route
  10. 10. All these choices… <ul><li>Apache ServiceMix thrives on innovation and experimentation. </li></ul><ul><ul><li>… it’s not surprising that ServiceMix provides many ways to implement web services. </li></ul></ul><ul><li>My recommendations: </li></ul><ul><ul><li>If you want to using/implement web services using Java programming, then use CXF’s JAX-WS support and package as OSGi bundles. </li></ul></ul><ul><ul><li>If you want to route SOAP traffic with little marshalling overhead, then use Camel’s camel-cxf component. </li></ul></ul>
  11. 11. Key techniques for developing CXF services with ServiceMix (Fuse ESB)
  12. 12. Ticklist – creating a service <ul><li>Generate JAX-WS code from WSDL </li></ul><ul><ul><li>… using the Maven cxf-codegen-plugin </li></ul></ul><ul><li>Implement the JAX-WS Service Endpoint Interface (SEI) </li></ul><ul><ul><li>… using Java ‘ implements ’ plus a few annotations </li></ul></ul><ul><li>Configure service endpoints and/or clients using Spring Framework. </li></ul><ul><ul><li>… using appropriate conventions so ServiceMix can locate your Spring contexts. </li></ul></ul><ul><li>Package your service </li></ul><ul><ul><li>… using the maven-war-plugin for WAR files </li></ul></ul><ul><ul><li>… using the maven-bundle-plugin for OSGi bundles </li></ul></ul>
  13. 13. Using the cxf-codegen-plugin Maven-friendly location for generated code! Location of WSDL file
  14. 14. Creating an SEI implementation class Important – these annotations will affect the generated WSDL! … whatever code you like goes in here – it’s all just Java…
  15. 15. Configuring a service implementation using Spring Framework Here’s where we define the endpoint, and tie it to your implementation class.
  16. 16. Aside: the modularity of CXF <ul><li>CXF is a modular runtime. </li></ul><ul><ul><li>By default the runtime assumes that your endpoint is enabled via the CXF Servlet. </li></ul></ul><ul><ul><li>If you’re not using the CXF Servlet, then you need to enable SOAP, HTTP, and Jetty extensions using Spring imports. </li></ul></ul>Note that if using your own Jetty engine, you should specify IP and port in the address.
  17. 17. Packaging - WAR <ul><li>For war packaging, you should place your Spring configuration in src/main/resources/cxf-servlet.xml . </li></ul><ul><li>You must also provide a web.xml file configuring the CXF servlet. </li></ul><ul><li>Don’t forget to set the POM’s <packaging> to be ‘ war ’. </li></ul>
  18. 18. Packaging – WAR (cont’) – web.xml All the services will have their address prefixed with ‘/services/’. This configures the CXFServlet!
  19. 19. Packaging – WAR (cont’) – maven-war-plugin Indicates the location of the web.xml descriptor. Includes the WSDL files in the WAR (optional) Adds everything in src/main/resources to the WAR.
  20. 20. Demo – deploy the WAR!
  21. 21. Packaging – OSGi bundles <ul><li>The Spring configuration should be placed in the META-INF/spring directory in src/main/resources . </li></ul><ul><li>For OSGi bundling: </li></ul><ul><ul><li>Usually keep implementation packages private. </li></ul></ul><ul><ul><li>Import META-INF.cxf to get the CXF Spring imports. </li></ul></ul><ul><ul><li>Allow some CXF/Spring packages to be dynamically imported. </li></ul></ul><ul><ul><li>See over! </li></ul></ul>
  22. 22. Packaging – OSGi bundles (cont’) – maven-bundle-plugin ‘ !’ denotes do not export these packages. ‘ *’ says scan the classes in the project and work out the imports  Dynamic imports allow runtime loading of classes
  23. 23. Demo – deploy the OSGi bundle!
  24. 24. Invoking on a service – configuring a client with Spring Very easy to configure a client proxy 
  25. 25. Invoking on a service – Java code <ul><li>You can now invoke on the customer web service just like a local Java call. </li></ul>
  26. 26. Summing up <ul><li>Fuse ESB (Apache ServiceMix) gives you a number of options on how to implement and consume web services. </li></ul><ul><ul><li>WAR, OSGi bundle, JBI, Camel routes, … </li></ul></ul><ul><li>All make use of Spring or OSGi Blueprint declarative configuration. </li></ul><ul><li>Prefer to package as OSGi bundles over WAR or JBI packaging. </li></ul><ul><li>Use JAX-WS if you want to marshal payload to Java objects. </li></ul><ul><li>Use Camel routes with camel-cxf if you want to perform unmarshaled payload-based transformation and routing. </li></ul>
  27. 27. Next Webinars <ul><li>See http://fusesource.com/resources/video-archived-webinars / </li></ul><ul><li>March 3 rd 2011: </li></ul><ul><ul><li>Using CXF with Camel in ServiceMix </li></ul></ul><ul><li>April 7 th 2011: </li></ul><ul><ul><li>How to Secure CXF Web Services with SSL/TLS and WS-Security </li></ul></ul><ul><li>See you then! </li></ul>
  28. 28. Useful references <ul><li>FuseSource – http://fusesource.com </li></ul><ul><ul><li>http://fusesource.com/products/enterprise-cxf/#documentation </li></ul></ul><ul><ul><li>http://fusesource.com/products/enterprise-servicemix/#documentation </li></ul></ul><ul><li>Maven – http://maven.apache.org </li></ul><ul><ul><li>http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html </li></ul></ul><ul><ul><li>http://maven.apache.org/plugins/maven-war-plugin/ </li></ul></ul><ul><li>Bnd - http:// www.aqute.biz/Code/Bnd </li></ul><ul><li>CXF – http://cxf.apache.org </li></ul><ul><ul><li>http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html </li></ul></ul><ul><ul><li>http://cxf.apache.org/docs/jax-ws-configuration.html </li></ul></ul>
  29. 29. Learn More at http://fusesource.com

×