camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > How to avoid importing bunch of cxf packages when start up the camel-cxf endpoint from OSGi platform ?
Date Fri, 26 Feb 2010 12:11:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="">How
to avoid importing bunch of cxf packages when start up the camel-cxf endpoint from OSGi platform
    <h4>Page  <b>added</b> by             <a href="">willem
    <div class="notificationGreySide">
         <p>If you are using camel-cxf endpoint in your OSGi bundle and want to get
full of control of CXF component loading. (eg. you just want to use the http jetty transport,
soap binding and don't want to load jms transport, jaxrs modules). You may need to tell SpringBusFactory
which module should be load, in this way you need to import bunch of cxf packages or using
the * on the DynamicImport-Package section of your application's OSGi meta information.</p>

<p>As the CXF bundle have the most cxf configuration file, here is a way to do it by
setting the right thread context class loader to load the cxf module configures, without any
additional setting. <br/>
This is the code snippet to show to create a CXF bus with soap binding and http-jetty transport.</p>

<p><b>NOTE</b>, if you have other CXF configuration which want to be load,
you need to make sure the thread context class loader can load it. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">ClassLoader</span> oldCL = <span class="code-object">Thread</span>.currentThread().getContextClassLoader();
<span class="code-keyword">try</span> {
	<span class="code-object">Thread</span>.currentThread().setContextClassLoader(
	SpringBusFactory springBusFactory = <span class="code-keyword">new</span> SpringBusFactory();
	Bus bus = springBusFactory.createBus(<span class="code-keyword">new</span> <span
		{ <span class="code-quote">"META-INF/cxf/cxf.xml"</span>, <span class="code-quote">"META-INF/cxf/cxf-extension-soap.xml"</span>,
		  <span class="code-quote">"META-INF/cxf/cxf-extension-http-jetty.xml"</span>
}, <span class="code-keyword">false</span>);
	<span class="code-comment">// The last parameter is telling CXF not to load the cxf-extension-*.xml
from META-INF/cxf
</span>	<span class="code-comment">// You can set the bus the normal CXF endpoint
or other camel-cxf endpoint
</span>} <span class="code-keyword">finally</span> {
	<span class="code-object">Thread</span>.currentThread().setContextClassLoader(oldCL);

<p>From Camel 2.2.0, we introduced a SpringBusFactoryBean which leverage the BusApplicationContext
will use the BusApplicationContext.class classloader as a fall back classloader, so you can
configure the SpringBusFactoryBean and set the bus directly into the camel-cxf endpoint without
using any java code. The Spring configuration snippet is below:<br/>
If you are using URI to specify the camel-cxf endpoint , you can set the bus with bus option
like this "cxf://ADDRESS?bus=myBus&amp;...".</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;beans xmlns=<span class="code-quote">"http:<span class="code-comment">//"</span>
</span>       xmlns:xsi=<span class="code-quote">"http:<span class="code-comment">//"</span>
</span>       xmlns:cxf=<span class="code-quote">"http:<span class="code-comment">//"</span>
</span>       xsi:schemaLocation="
       http:<span class="code-comment">//
</span>       http:<span class="code-comment">//
</span>    "&gt;

  &lt;bean id=<span class="code-quote">"myBus"</span> class=<span class="code-quote">"org.apache.camel.component.cxf.spring.SpringBusFactoryBean"</span>&gt;
     &lt;property name=<span class="code-quote">"cfgFiles"</span> value=<span
     &lt;property name=<span class="code-quote">"includeDefaultBus"</span>
value=<span class="code-quote">"<span class="code-keyword">false</span>"</span>
   &lt;cxf:cxfEndpoint id=<span class="code-quote">"routerEndpoint"</span>
address=<span class="code-quote">"http:<span class="code-comment">//localhost:9000/router"</span>
</span>    serviceClass=<span class="code-quote">"org.apache.camel.component.cxf.HelloService"</span>
bus=<span class="code-quote">"myBus"</span>/&gt;


    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message