{"id":332,"date":"2011-11-01T10:41:53","date_gmt":"2011-11-01T14:41:53","guid":{"rendered":"http:\/\/www.dankulp.com\/blog\/?p=332"},"modified":"2011-11-01T10:41:53","modified_gmt":"2011-11-01T14:41:53","slug":"apache-cxf-in-osgi","status":"publish","type":"post","link":"https:\/\/www.dankulp.com\/blog\/?p=332","title":{"rendered":"Apache CXF in OSGi"},"content":{"rendered":"<p>I&#8217;ve had a bunch of people asking me lately about getting <a href=\"http:\/\/cxf.apache.org\">Apache CXF<\/a> 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 &#8220;class loader&#8221; issues, etc&#8230;.    Thus, I decided I need to write a blog entry.  \ud83d\ude42<\/p>\n<p>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 &#8220;pure CXF&#8221;, the best option is the <a href=\"http:\/\/talend.com\/products\/tsf\">Talend Service Factory<\/a>.  It&#8217;s pretty much <a href=\"http:\/\/karaf.apache.org\">Apache Karaf<\/a> 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 <a href=\"http:\/\/talend.com\/products\/tif\">Talend Integration Factory<\/a> or the <a href=\"http:\/\/www.talend.com\/products-application-integration\/\">Talend ESB<\/a>.   Both of them contain Apache Karaf, Apache CXF, and <a href=\"http:\/\/camel.apache.org\">Apache Camel<\/a> pre-setup to run in OSGi.   If you don&#8217;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 &#8220;lightest weight&#8221; option, the Talend Service Factory is the best option.<\/p>\n<p>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:<\/p>\n<p>1) Start with <a href=\"http:\/\/karaf.apache.org\">Apache Karaf<\/a>.  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.  <\/p>\n<p>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&#8217;s.   The versions of the API&#8217;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:<\/p>\n<pre>\r\n# javax.activation, \\\r\n# javax.annotation;version=\"1.1\", \\\r\n\r\n# javax.jws, \\\r\n# javax.jws.soap, \\\r\n\r\n# javax.xml.bind, \\\r\n# javax.xml.bind.annotation, \\\r\n# javax.xml.bind.annotation.adapters, \\\r\n# javax.xml.bind.attachment, \\\r\n# javax.xml.bind.helpers, \\\r\n# javax.xml.bind.util, \\\r\n\r\n# javax.xml.soap, \\\r\n# javax.xml.stream, \\\r\n# javax.xml.stream.events, \\\r\n# javax.xml.stream.util, \\\r\n\r\n# javax.xml.ws, \\\r\n# javax.xml.ws.handler, \\\r\n# javax.xml.ws.handler.soap, \\\r\n# javax.xml.ws.http, \\\r\n# javax.xml.ws.soap, \\\r\n# javax.xml.ws.spi, \\\r\n<\/pre>\n<p>All of those API&#8217;s use the SPI mechanism in the JDK to find implementations.   That mechanism relies on Thread contextClassLoader mechanisms that don&#8217;t work reliably in OSGi.   For CXF, we have specific bundled versions of those API&#8217;s that use a proper BundleActivator\/Listener method to find the implementations.<\/p>\n<p>I&#8217;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.<\/p>\n<p>3) Start the container by running the bin\/karaf file.   <\/p>\n<p>4) From the Karaf command line, type:  <\/p>\n<pre>\r\nfeatures:addurl mvn:org.apache.cxf.karaf\/apache-cxf\/2.5.0\/xml\/features\r\n<\/pre>\n<p>That will install the CXF Karaf features file.   After that, you can run &#8220;features:list&#8221; and see the features that CXF provides.<\/p>\n<p>5) Run<\/p>\n<pre>\r\nfeatures:install cxf\r\n<\/pre>\n<p>To install the CXF feature.   Karaf will then download and install all the required dependencies, bundles, etc&#8230; and install them into the OSGi container.   It will also start the bundles.    If you run &#8220;list -t 0&#8221; you should see &#8220;Apache CXF Bundle Jar&#8221; active at the bottom.<\/p>\n<p>That&#8217;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.  \ud83d\ude42    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. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;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 &#8220;class loader&#8221; issues, etc&#8230;. Thus, I decided I need to write a blog entry. [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,9,13],"tags":[],"_links":{"self":[{"href":"https:\/\/www.dankulp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/332"}],"collection":[{"href":"https:\/\/www.dankulp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dankulp.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dankulp.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dankulp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=332"}],"version-history":[{"count":8,"href":"https:\/\/www.dankulp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/332\/revisions"}],"predecessor-version":[{"id":341,"href":"https:\/\/www.dankulp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/332\/revisions\/341"}],"wp:attachment":[{"href":"https:\/\/www.dankulp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dankulp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dankulp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}