Archive for November, 2011

Apache Camel in OSGi

November 3rd, 2011 1 Comment

After writing my post about setting up Apache CXF in OSGi, I’ve had a couple people ask about how to do the same with Apache Camel. Camel is a bit more complex due to all the libraries that it may pull in depending on which components you use, but it’s not really that much more complex.

As with CXF, the easiest way to get it up and running would be to grab a distribution that has it ready to go. Again, I’d recommend either the Talend Integration Factory or Talend ESB. Both have Apache Camel, Apache CXF and Apache ActiveMQ pre setup to run and everything well configured. The more popular Camel components are pre-installed with their dependencies making it fairly easy to get started.

That said, setting up your own instance is really not that hard.

  1. Follow steps 1-3 from my post about setting up Apache CXF in OSGi. This gets Karaf setup and ready.
  2. From the Karaf command line, run:
    features:addurl mvn:org.apache.activemq/activemq-karaf/5.5.0/xml/features
    features:addurl mvn:org.apache.cxf.karaf/apache-cxf/2.5.0/xml/features
    features:addurl mvn:org.apache.camel.karaf/apache-camel/2.8.2/xml/features
    

    That will add the ActiveMQ, CXF, and Camel features into Karafs feature resolver.

  3. If you plan on using JMS, it’s recommended to install the ActiveMQ features first. From the Karaf command line, run:
    features:install activemq
    features:install activemq-spring    (if you use spring)
    
  4. Next up would be CXF if you plan on using the CXF components. Again, from the Karaf command line, run:
    features:install cxf
    
  5. Finally, install the Camel components you are interested in using:
    features:install camel-core
    features:install camel-spring
    features:install camel-jms
    features:install camel-cxf
    etc...
    

    You can get a list of the Camel features by doing a “features:list | grep camel” from the Karaf command line.

That’s pretty much all there is to it. It’s not hard. :-) It’s now all setup! To try it out, I’d once again grabbing the samples package from Talend Integration Factory. There are several examples in there on how to do various Camel things, all running in OSGi.

This morning, I sent out an announcement that Apache CXF 2.5.0 is now released! Over 6 months of work went into this release to expand the feature set, stabilize it, and get it ready for release.

There are two major categories of new “stuff” in this release:

  1. Normal “framework” features. These features expand the capabilities of CXF as a Services Framework and are more in line with the traditional CXF enhancements. In 2.5.0, these include things like:
    • Enhanced WS-RM interopability
    • WS-MetadataExchange support
    • OAuth support
    • Enhanced security options for REST
    • Enhanced JMX instrumentation
    • Enhanced OSGi and Karaf integration
  2. New “Services”. This is a brand new area for CXF. With 2.5.0, the scope of CXF now expands to include some enterprise level services that are related to CXF. At this point, they include:
    • Security Token Service
    • WS-Notification Service

I’m very excited about the second category of enhancements. Traditionally, CXF has always been “just a framework” that can be used to build your services. CXF never really provided any services “out of the box”. I’m hoping that by providing some enterprise level services out of the box, it will become even easier for people to develop and deploy CXF based applications in their enterprise. Both of the new services, while “new” for CXF, are really enterprise ready. The WS-Notification Service is a port (mostly done by Guillaume Nodet) of the ServiceMix WS-Notification service which has been deployed and used in production in many places. By removing the JBI dependencies and re-writing the communications to use pure JAX-WS API’s, the WS-Notification service is now much more usable by a wider audience. The STS was developed by Talend for some of our customers and has been deployed into production. Colm has done an amazing job with the STS to get it to meet a wide range of requirements. Definitely check out his blog for more information about the capabilities of the STS.

Anyway, this is another big release for Apache CXF. Definitely give it a spin and let us know how we’re doing!

Apache CXF in OSGi

November 1st, 2011 8 Comments

I’ve had a bunch of people asking me lately about getting Apache CXF up and running in OSGi. A lot of people have run into issues trying to find the right third party bundles, configuring things like JAX-WS and JAXB, normal “class loader” issues, etc…. Thus, I decided I need to write a blog entry. :-)

Obviously, the EASIEST way to get CXF up and running in OSGi is to grab a preconfigured OSGi container that has CXF already setup. There are a couple of good ones out there. For “pure CXF”, the best option is the Talend Service Factory. It’s pretty much Apache Karaf and Apache CXF completely setup to run in OSGi out of the box. Very simple. If you want/need a little more functionality, you could grab the Talend Integration Factory or the Talend ESB. Both of them contain Apache Karaf, Apache CXF, and Apache Camel pre-setup to run in OSGi. If you don’t mind an older version of CXF, you can also use the latest Apache ServiceMix 4.x distributions as they would have CXF ready to run as well. However, the current downloads are based on a fairly old version of CXF. They are working on a newer version that would contain a newer version of CXF, but that may not be available for a couple weeks. Also, ServiceMix contains a lot of other things that may or may not be useful for you. For the “lightest weight” option, the Talend Service Factory is the best option.

However, not everyone wants a pre-configured thing. They may want to customize things a bit. Or maybe add some of their own things. For those types of people here are some basic instructions that I would recommend:

1) Start with Apache Karaf. Karaf is an excellent general purpose OSGi container and provides a bunch of features to make life with OSGi much easier. Grab the latest (currently 2.2.4) version, download it, and unpack it.

2) In the unpacked Karaf area, edit the etc/jre.properties file. For CXF to work we need to use OSGi enabled bundles of various API’s. The versions of the API’s built into the JDK are not OSGi enabled and thus will not work properly with CXF. In the jdk-1.6 (and 1.7 if using Java7), you need to commend out the lines:

# javax.activation, \
# javax.annotation;version="1.1", \

# javax.jws, \
# javax.jws.soap, \

# javax.xml.bind, \
# javax.xml.bind.annotation, \
# javax.xml.bind.annotation.adapters, \
# javax.xml.bind.attachment, \
# javax.xml.bind.helpers, \
# javax.xml.bind.util, \

# javax.xml.soap, \
# javax.xml.stream, \
# javax.xml.stream.events, \
# javax.xml.stream.util, \

# javax.xml.ws, \
# javax.xml.ws.handler, \
# javax.xml.ws.handler.soap, \
# javax.xml.ws.http, \
# javax.xml.ws.soap, \
# javax.xml.ws.spi, \

All of those API’s use the SPI mechanism in the JDK to find implementations. That mechanism relies on Thread contextClassLoader mechanisms that don’t work reliably in OSGi. For CXF, we have specific bundled versions of those API’s that use a proper BundleActivator/Listener method to find the implementations.

I’d also recommend editing the etc/custom.properties file to add karaf.framework=equinox to set the underlying OSGi runtime to Equinox instead of Felix. Currently, CXF is a bit better tested with Equinox. Future versions of CXF will work better with Felix, but right now, the testing is more complete with Equinox.

3) Start the container by running the bin/karaf file.

4) From the Karaf command line, type:

features:addurl mvn:org.apache.cxf.karaf/apache-cxf/2.5.0/xml/features

That will install the CXF Karaf features file. After that, you can run “features:list” and see the features that CXF provides.

5) Run

features:install cxf

To install the CXF feature. Karaf will then download and install all the required dependencies, bundles, etc… and install them into the OSGi container. It will also start the bundles. If you run “list -t 0″ you should see “Apache CXF Bundle Jar” active at the bottom.

That’s really all there is to it. At that point, CXF is installed and ready to be used. Now, USING it is a subject for another blog post. :-) For now, your best option is to grab the Talend Service Factory examples and take a look at them. All of them are ready to run in OSGi.