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.

This past week, there was a discussion on the Apache CXF developer list about adding an enterprise grade Security Token Service (STS) into CXF. Talend has been developing an STS internally for some of our customers for a while now and we’re pretty excited to be able to contribute the results of that work back to the community. CXF 2.4.0 had a very basic “framework” for developing an STS built into it along with a simple example that showed how to use the framework to setup a very simple STS. However, most of the details of creating and verifying tokens and such was completely left to the user/developer. The new STS, while built on that same framework, has a lot more capabilities “built in” and requires significantly less work to setup.

Colm’s blog definitely covers most of the details about the functionality of the new STS. Over the upcoming weeks, he should be adding more details about how to configure and leverage many of the features he mentions. Keep an eye out on his blog for details.

I’m quite excited about this. One of my personal goals in developing Open Source software is making that software more approachable and usable in enterprise environments. Over the years, CXF has done a great job become the defacto open source services framework by trying to meet the needs of enterprise deployments. This takes it even a step further by providing the first ready made service based on CXF. Hopefully, there will be more to come. Stay tuned!

In the last week or so, there’s been a bit of work going on in CXF to improve the OSGi experience with CXF as well as make it easier to manage.

First off, Glen Mazza has done quite a bit of testing with JMX and wrote a very good blog entry about how to JMX enable your CXF services (and Metro). As part of that, he’s been testing it with various app servers and updating the documentation and such. All great work.

On the OSGi side, CXF will now register the Bus objects into the OSGi service registry. Thus, other OSGi services can query them and pull information out of them. The primary driver for this is the new Karaf WebConsole. It’s very very early (just added to the WebConsole yesterday), but you can see some of the stuff that can be queried here. Also, to make this more useful, the Bus ID now defaults to the bundle SymbolicName+”cxf” when running in OSGi. This makes it much easier in the WebConsole and in JMX to find the endpoints of interest when there are many deployed.

Combining both of the above, when running in OSGi, CXF will now lookup an MBeanServer from the container and register its MBeans automatically. With previous versions of CXF, the user would need to add a bunch of configuration into their blueprint or spring-dm configs to enable the JMX management. That will be done automatically now.

I’m quite happy with the above changes. It will really make the administrators job easier when using CXF, particularly in OSGi based ESB’s like Talend’s ESB.

One of the important differentiators between Apache CXF and some of it’s competitors has been it’s support for standards, both “on the wire” standards like SOAP and API standards like JAX-WS and JAX-RS. When Apache resigned from the JCP last year, there was a lot of concern about whether CXF would be able to continue to be involved with the defining and implementing the standards. As an Apache member, I fully support the actions that Apache took as there really wasn’t a good alternative. However, it did leave a gap in some of the projects abilities to participate in the specifications.

I’m happy to announce that Talend has joined the JCP to allow some of our contributors like myself and Sergey to continue being involved and help shape the future of the standards that CXF implements. The immediate benefit is that Sergey can jump into the JAX-RS 2.0 discussions and help make sure that JAX-RS 2.0 can meet the needs of CXF users. The combination of the JAX-WS and JAX-RS programming models in CXF is a great combination of technologies and making sure the CXF users needs are well represented is important.

For a more complete discussion of Talends thoughts, see Fabrice’s blog entry on Talends site. From my standpoint, the most important piece to understand is that this shows Talend is not just committed to supporting CXF and the other Apache projects we are involved in, but also in investing in making sure the projects continue to innovate and move forward to solve users needs and problems. That is one of the unique points that makes Talend special.

On July 22, 2005, I did my first commit into the Apache subversion repository. That commit was the first part of bringing Apache CXF (was called CeltixFire at the time) to Apache.

This morning, according to svnsearch, I committed my 7000th change. That’s a lot of changes. Kind of silly milestone, but I’m proud of it. I’m certainly happy to have had jobs that allow me to spend a lot of time working on the Apache projects as part of my job.

Off to starting working on some more commits…… :-)

Talend is conducting a survey to help prioritize various topics people might be interesting in learning about relating to the Apache projects that we support and participate in. This is a great opportunity for people to let us know where you think we need to provide better documentation, official training, webinars, etc… to help people become more proficient with the technologies.

Part of this information will also be used to help me determine what people are interested in hearing me (and my other team members) talk about in Webinars. We’re going to be starting a series of recorded Webinars on various topics and finding out what people would like to see is important in making sure they are relevant and interesting.

The survey is very short. It shouldn’t take more than a few minutes. I highly encourage folks interested in Apache CXF, Apache Camel, Apache Karaf, etc…. to take the survey and provide valuable feedback.

Thanks!

While I was on vacation last week, one of my “side projects” at Talend actually finished as Talend is now a Sponsor of the Apache Software Foundation.

This has been something I’ve been trying to push through for quite a while. Talend (and a lot of companies) get a lot of value from the projects produced at Apache. Becoming a sponsor and supporting the Foundation financially is something I really think is a great way to acknowledge that value and help the keep the projects and the Foundation moving forward.

Anyway, I’m really glad this finally happened.

After 6 months of development, the Apache CXF team is proud to announce that 2.4.0 is now released. (official announcement) This version was a fairly large undertaking and has a bunch of significant new features.

  • Security: WS-Security enhancements were a major theme for this release. It mostly started as work to get a new version of Apache WSS4J (version 1.6) integrated into CXF but really turned into a bunch of major updates to WSS4J and even larger enhancements to CXF. The primary “driving feature” was support for SAML2 tokens. In the end, we support SAML2 tokens, but also have much better configurability of the keystores, more consistent callback handling, much better token validation API’s and capabilities, the ability to “fail fast” in many cases when security issues are encountered, etc… I HIGHLY recommend reading through Colm’s blog to discover all the new features in WSS4J that were developered to support CXF.
  • Performance and memory footprint: A significant amount of work was put into the startup procedures in CXF to reduce startup time and lower the memory footprint. As part of this, the dependency on Spring to wire together CXF has been greatly reduced. Now, almost all features of CXF can be used without Spring. Previously, many of the advanced features like WS-SecurityPolicy and WS-RM and such required Spring. In all, a particular test case I have that deploys over 200 services within over 75 wars can now deploy and run with MUCH less memory than before (required -Xmx drops from 192M to 96M and startup time in tomcat drops from about 50 seconds to 20). Note: with this change came the removal of almost all the META-INF/cxf/cxf-extension-*.xml files. MUCH easier to configure now as well.
  • HTTP transport refactoring Related to the Spring stuff, the HTTP transport was refactored to remove the requirement of Spring to select “which” http transport. Previously, the user really need to select (by importing the appropriate spring file) either the servlet version, the embedded jetty version, or the OSGi version. There is now a single http transport that handles all three cases. You can even mix/match with some some services that deploy on the servlet provided context, but others that spin up an embedded jetty instance on a different port.
  • JiBX databinding: a Google Summer of Code project from last year, CXF now supports using JiBX in addition to JAXB, XMLBeans, and SDO.
  • Log browser: another Google Summer of Code project resulted in a very nice web/rest based frontend to the logs produced by CXF. It’s a starting point for future admin related tasks, but is quite useful right now.
  • Transformation feature: provides for a fast and effective way to transform inbound and/or outbound XML messages. There is a nice introduction to this on Sergey’s blog.
  • OSGi improvements: A lot of stuff was done to make working with CXF in OSGi much better. The OSGi HTTP transport was already mentioned. We also added an Apache Karaf features file to help setup CXF in Karaf a lot quicker and easier. Finally, work was started (it’s a work in progress) to add Blueprint/Aries namespace handlers to allow deployment of services using Blueprint instead of Spring DM. Currently, the basic creation of clients and services works in Blueprint. Some of the more advanced configuration (most notable is the HTTPs configuration) is still being worked on.
  • Work with Apache WebServices community: along with working closely with WSS4J as mentioned above, CXF developers also worked to drive changes in Neethi and XmlSchema. The result is much better collaboration between CXF and the WebServices communities and many hacks and workaround in CXF being removed as the fixes and changes were made in the underlying libraries.

As you can see, there was definitely a lot of exciting work put into 2.4.0. I definitley encourage forlks to read the migration guide for more information about the changes and the potential impact it has on users.

Another interesting thing I’d like to point out is how much this was a COMMUNITY effort. The features above were developed by a bunch of people in the community, not just a single person or company. While the security and performance work was primarily done by Talend employees, we also had major contributions from the GSoC students (2 students became committers), Benson Margulies did a lot of work getting XmlSchema 2.0 released and integrated, much of the Blueprint work is being done by Johan Edstrom as part of his work with Savoir Technologies, etc…

Of equal interest is who was NOT a driving force for this release: IONA/Progress/Fuse. Since CXF was started at Apache way back in 2006, the IONA/Progress/Fuse developers have been a primary driving force for new features and development in CXF. 2.4.0 really marks a major change from that. It’s not to say they haven’t been contributing to CXF, they definitely have. However, most of their contributions are more in the form of bug fixes and minor tweaks, not major new feature development. In my opinion, this a good thing for CXF and shows the value in the way Apache values the diversity of the community. In many cases, open source is about “scratching your own itch.” Basically, if you need something done or fixed, you do it and submit it to the project. Over time, in a healthy community, many of the original itches get scratched and those people move on, but new people come in with new ideas and requirements and drive furthur work. The mark of a healthy community is how open they are to such changes and how well the community adapts. CXF has adapted quite well.

Anyway, I definitely encourage everyone to upgrade to CXF 2.4.0 and experience the new features. All of this “goodness” will soon be available in Talend Service Factory and the other Talend offerings. Keep an eye out for it.

Back in December, I talked about the release of the Talend Service Factory as being the first step in the new product plans coming out of Talend. The second step occured today with the release of the Talend Integration Factory. (Click here for the official press release if you are interested.)

Talend Integration Factory is very similar to Talend Service Factory in that it builds upon one of the most successful Apache projects, in this case Apache Camel, and enhances it to meet the needs of enterprise users. For Talend Integration Factory, the major enhancements to Apache Camel are:

  • OSGi container – a “container” directory is added which is a full OSGi container, including Equinox and Karaf, preconfigured with all the dependencies and bundles required for the most popular use cases of Camel in OSGi.
  • Camel component for Talend Open Studio which allows jobs created from TOS to be part of a Camel route

From an enterprise standpoint, the first item is very important. Having a preconfigured, supported OSGi container setup and optimized for Camel makes it a lot easier to get started with Camel.

The second item is interesting in that it’s the first piece that really starts bridging the the Talend Data technologies with the Application Integration technologies. At this point, it’s in a very early state, but it’s a starting point to build from.

Like the Talend Service Factory release, for Talend Integration Factory we again worked very hard on creating some new documented examples that demonstrate some of the advanced features of Apache Camel. The really cool thing is that several of the examples build off of the examples from Talend Service Factory, extending them to participate in Camel routes. This is very similar to how enterprises end up using Camel. They start off with existing services or have services being developed by a particular group. Those services then need to be integrated into various EIP style routes or used from other pieces of logic. The other nice thing about building up the examples like that is it really shows how well Apache CXF and Apache Camel work together seamlessly.

Anyway, I’m definitely excited about this release. As mentioned, it’s just “Step 2″ and we have a lot of other exciting ideas and products that will be coming out this year. Stay tuned!

A month ago, it was announced that Talend had acquired Sopera. At the time, many people wondered what that really meant as Talend specialized in Data Integration and Mangement technologies and Sopera was more of an Application Integration company. Over the last couple months, I’ve defintely been involved in a lot of meetings and con calls and such to start flushing out ideas and roadmaps and such.

The first step in plan occured today with the release of Talend Service Factory. TSF is primarily a repackaged distribution of Apache CXF that is optimized more for Enterprise level use. There are two major changes from the Apache distributions:

  1. Java 6 optimized – Talend is only committing to supporting Java 6 so the lib directory has been optimized for Java 6, removing a bunch of things that are already provided by the JDK.
  2. OSGi container – a “container” directory is added which is a full OSGi container, including Equinox and Karaf, preconfigured with everything needed to use CXF in OSGi.

I’m actually quite excited about the second item for a few reasons. For one, it actually made me start looking at and using OSGi. I guess I’m a little behind the curve on that. Second, it fills a void between the lightweight services and samples that Apache CXF provides and supports and a full, heavyweight ESB like ServiceMix. We’ve had quite a few people ask about OSGi containers and such on the CXF lists. I’ve always felt a bit guilty about pointing them at something as huge and complex as ServiceMix when they don’t need it or want it. You can download the release here.

The OTHER thing that we worked hard on is a new set of documented examples that show off some of the more advanced features of CXF, ALL of them designed to be run standalone (like all the Apache CXF samples) or in the OSGi container. We all learned a lot writing the examples. We had to fix some bugs in CXF to get some of them to work in the OSGi container, but that’s part of the process. I think Sergey, Glen, and I may talk more about these examples in the upcoming days. Until then, feel free to download them and give them a run through. We have more in the works as well.

The important thing to remember is that this is just a start. Step 1. We have a lot of stuff in progress for 2011 that I’m quite excited about.