camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
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
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="http://cwiki.apache.org/confluence/pages/viewpage.action?pageId=14483488">How
to avoid importing bunch of cxf packages when start up the camel-cxf endpoint from OSGi platform
?</a></h2>
    <h4>Page  <b>added</b> by             <a href="http://cwiki.apache.org/confluence/display/~njiang">willem
jiang</a>
    </h4>
         <br/>
    <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(
	BusFactory.class.getClassLoader());
	SpringBusFactory springBusFactory = <span class="code-keyword">new</span> SpringBusFactory();
	Bus bus = springBusFactory.createBus(<span class="code-keyword">new</span> <span
class="code-object">String</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);
}
</pre>
</div></div>

<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/>
<b>NOTE</b><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">//www.springframework.org/schema/beans"</span>
</span>       xmlns:xsi=<span class="code-quote">"http:<span class="code-comment">//www.w3.org/2001/XMLSchema-instance"</span>
</span>       xmlns:cxf=<span class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/cxf"</span>
</span>       xsi:schemaLocation="
       http:<span class="code-comment">//www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
</span>       http:<span class="code-comment">//camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
</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
class="code-quote">"META-INF/cxf/cxf.xml;META-INF/cxf/cxf-extension-soap.xml;META-INF/cxf/cxf-extension-http-jetty.xml"</span>
/&gt;
     &lt;property name=<span class="code-quote">"includeDefaultBus"</span>
value=<span class="code-quote">"<span class="code-keyword">false</span>"</span>
/&gt;
  &lt;/bean&gt;
  
   &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;

&lt;/beans&gt;
</pre>
</div></div>




    </div>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>
       <a href="http://cwiki.apache.org/confluence/pages/viewpage.action?pageId=14483488">View
Online</a>
              |
       <a href="http://cwiki.apache.org/confluence/pages/viewpage.action?pageId=14483488&showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message