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