tag:blogger.com,1999:blog-45602716200964055542024-03-21T05:40:17.669-07:00Freeman Fang's BlogFreeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-4560271620096405554.post-12981833833795262302012-03-30T00:24:00.001-07:002012-03-30T00:37:14.294-07:00How to use JDBC driver in OSGi containerOne frequently asked question on the <a href="http://fusesource.com/">FuseSource</a> <a href="http://fusesource.com/forums/index.jspa">forum</a> and several Apache projects like Apache servicemix/Karaf/Camel/CXF which I'm working on is that how to use JDBC driver in OSGi container? why I always encounter ClassNotFoundException?<br />
<br />
Users usually use some third party libs like spring-jdbc or commons-dbcp to maintain the connection pool, so they configure it like<br />
<bean id="databaseConnection" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><br />
<property name="driverClassName" value="com.mysql.jdbc.Driver" /><br />
<property name="url" value="jdbc:mysql://localhost:3306/schema" /><br />
<property name="username" value="***" /><br />
<property name="password" value="***" /><br />
</bean><br />
<br />
or<br />
<br />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"><br />
<property name="driverClassName" value="${jdbc.driver.class}"/><br />
<property name="url" value="${jdbc.url}"/><br />
<property name="username" value="${jdbc.user}"/><br />
<property name="password" value="${jdbc.password}"/><br />
</bean><br />
<br />
Those beans always work in standalone mode, but when users deploy it in OSGi container like <a href="http://fusesource.com/products/enterprise-servicemix/">FUSE ESB</a> or Apache Servicemix/Karaf, they will see the JDBC driver ClassNotFoundException.<br />
<br />
This error actually is from how OSGi classloader works, say, if bundleA need use some package, it need explicitly import it before hand.<br />
<br />
However, if a bundle(let's say it bundle A) using some code like classForName(jdbc_driver_classname) to init a jdbc driver class, this is a big issue in OSGi world, as if BundleA not import package for jdbc_driver_classname, you'll see the problem. Unfortunately BundleA actually can't know about package name for jdbc_driver_classname beforehand, as the jdbc_driver_classname generally is passed in through configuration during runtime, it can't be determined during build time, so you can't add correct package import when you generate bundle A.<br />
<br />
Back to our original issue, spring-jdbc and commons-dbcp is Bundle A here.<br />
<br />
How to resolve it?<br />
<br />
Well, we have several options<br />
<br />
1. Put all possible necessary packages in Import-Package OSGi metadata header, this is exactly how spring-jdbc do . spring-jdbc optionally import packages like<br />
com.ibm.websphere.rsadapter;resolution:=optional;version=0,<br />
com.ibm.ws.rsadapter.jdbc;resolution:=optional;version=0,<br />
com.mchange.v2.c3p0;resolution:=optional;version="[0.9.1, 2.0.0)",<br />
oracle.jdbc;resolution:=optional;version=0,<br />
oracle.sql;resolution:=optional;version=0,<br />
org.apache.derby.impl.io;resolution:=optional;version="[10.5.0, 11.0.0)",<br />
org.apache.derby.jdbc;resolution:=optional;version="[10.5.0, 11.0.0)",<br />
org.h2;resolution:=optional;version="[1.0.0, 2.0.0)",<br />
org.hsqldb;resolution:=optional;version="[1.8.0, 2.0.0)",<br />
org.jboss.resource.adapter.jdbc;resolution:=optional;version=0,<br />
weblogic.jdbc.extensions;resolution:=optional;version=0 <br />
com.sun.rowset;resolution:=optional;version="[1.0.1, 2.0.0)",<br />
pretty much all popular used JDBC drivers is available, but not include mysql.<br />
Of course we can hack the bundleA to add any Import-Package we want, it's not a big deal as we always hack, but it's not very graceful, especially sometimes we can't hack some bundles for license reason.<br />
<br />
2. Make bundleA have DynamicImport-Package OSGi headers, this is the way how Servicemix wrapped commons-dbcp do.It works, but we all know using DynamicImport-Package isn't the best practice in OSGi world. To support JDBC out of the box, we have to do some trade-off.<br />
<br />
3. What I prefer to is the fragment bundle way, that said, you create JDBC driver as a fragment bundle, and attach it to bundle A(bundle A is host bundle now), so that all resource from fragment bundle is available for the host bundle. This way you needn't hack bundleA.<br />
<br />
Finally, I'd say the fragment bundle is very useful when you try to get around some legacy libs in OSGi, it allow you pass the classname during runtime between bundle(like the JDBC driver we discuss here), it also can allow you to pass some resource files between bundles, I hope I can find some time to elaborate this issue later one.Freeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.com15tag:blogger.com,1999:blog-4560271620096405554.post-87457432801066189482011-05-11T21:31:00.000-07:002011-05-13T13:46:18.863-07:00FuseSource Camelone 2011FuseSource CamelOne 2011[1] will be held on May 24-26 in Washington DC,<br />
We have great Keynote and sessions speakers[2], also there're 2-day hands-on ActiveMQ and ServiceMix with Camel training is available.<br />
More importantly, don't miss out the free community get-together which is open for all. Many committers and users of Apache Camel, ServiceMix, ActiveMQ and CXF including James Strachan, Rob Davies, Claus Ibsen, and Jonathan Anstey will be in the DC area for CamelOne on the week of May 23rd. My employer FuseSource is sponsoring free food and drinks the night before for a community meet and greet that is open to anyone in the community from 6:00pm – 8:00pm in the Pinzimini Restaurant at the Westin Arlington Gateway on May 23rd.<br />
Come and meet the FuseSource guys and the community!<br />
[1]http://fusesource.com/camelone2011/<br />
[2]http://fusesource.com/camelone2011/speakers/<br />
<br />
<script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script>Freeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.com29tag:blogger.com,1999:blog-4560271620096405554.post-35449452828771876692010-09-21T02:08:00.000-07:002010-09-21T02:08:43.821-07:00Why ESB server hang after runing for a while?A frequently asked question on <a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/">FuseSource</a>[1] forum or <a href="https://uroam.progress.com/f5-w-687474703a2f2f736572766963656d69782e6170616368652e6f7267$$/home.html">Apache Servicemix</a>[2] mailling list is they encounter an issue that ESB server just hang after running a while, can't handle incoming request anymore. This issue could be caused for two major reason<br />
<br />
1. customer working flow isn't correct, not all MEPs are handled correctly, especially when use sendSync, but some MessageExchange never end up with DONE/ERROR, this will cause thread lock, and threads would be used up in this case so that can't hanle incoming request anymore.<br />
2. Too many cocurrent client request message cause threadpool used up, customer usually face this problem when they do performance/load test.The solution is quite straightforward for different cases,<br />
for case1. correct your working flow, ensure that all MEPs are handled correctly, use send but not sendSync as much as possible.<br />
for case2. configure <a href="https://uroam.progress.com/f5-w-687474703a2f2f736572766963656d69782e6170616368652e6f7267$$/thread-pools.html">threadpool</a>[3] for the performance test component, ensure the threadpool big enough for your performance/load test.<br />
<br />
I saw several cases that customer use cxfbc:consumer endpoint as facade to handle performance/load test request, the typical test flow could be<br />
cxfbc:consumer==>servicemix-camel<br />
cxfbc:consumer==>cxfse<br />
cxfbc:consumer==>servicemix-bean<br />
cxfbc:consumer==>cxfbc:provider<br />
Previously By default cxfbc:consumer endpoint use sendSync(this is a block mehtod,waiting for response message) to send message to NMR, this can cause deadlock for cocurrent request with default threadpool configuration, so if you wanna support heavy cocurrent request better, you need add synchronous="false" attribute to cxfbc:consumer endpoint, this will leverage CXF continuation API(I will explain how in another blog) and use send(this is a non-block method) method to send message to NMR. Since servicemix-cxf-bc-2010.02, synchronous="false" is the default value, which means the default behavior of cxfbc is asynchronously.<br />
<br />
Btw, to configure threadpool for NMR and each component in SMX4 is different with it in SMX3[3]. In SMX4, we leverage OSGi Configuration admin service to configure properties, so customer need edit a file named org.apache.servicemix.nmr.cfg in $SMX_HOME/etc folder to configure threadpool for nmr, and edit a file named org.apache.servicemix.components.component-name(like cxfbc).cfg in $SMX_HOME/etc folder for each component. <br />
[1]http://fusesource.com/<br />
[2]http://servicemix.apache.org/home.html<br />
[3]http://servicemix.apache.org/thread-pools.html<br />
<br />
<script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script>Freeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.com2tag:blogger.com,1999:blog-4560271620096405554.post-88776504799990296662010-09-20T23:17:00.000-07:002010-09-20T23:17:02.862-07:00Wired Exception caused by Proxy.equalsWeeks ago I encountered a wired problem when I shutdown <a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/">FuseSource</a>[1] ESB4/<a href="https://uroam.progress.com/f5-w-687474703a2f2f736572766963656d69782e6170616368652e6f7267$$/home.html">Apache Servicemix</a>[2]4, I get exception like<br />
<br />
<pre>org.osgi.service.blueprint.container.ServiceUnavailableException: Service is unavailable
at org.apache.aries.blueprint.container.ReferenceListRecipe$ServiceDispatcher.call(ReferenceListRecipe.java:201)
at org.apache.aries.blueprint.container.AbstractServiceReferenceRecipe$JdkProxyFactory$1.invoke(AbstractServiceReferenceRecipe.java:632)
at $Proxy12.repositoryEvent(Unknown Source)
at org.apache.karaf.features.internal.FeaturesServiceImpl.callListeners(FeaturesServiceImpl.java:939)
at org.apache.karaf.features.internal.FeaturesServiceImpl.internalRemoveRepository(FeaturesServiceImpl.java:186)
at org.apache.karaf.features.internal.FeaturesServiceImpl.stop(FeaturesServiceImpl.java:777)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_13]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_13]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_13]
at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_13]
at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:230)[7:org.apache.aries.blueprint:0.1.0.r964701]
at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:854)[7:org.apache.aries.blueprint:0.1.0.r964701]
at org.apache.aries.blueprint.container.BeanRecipe.destroy(BeanRecipe.java:761)[7:org.apache.aries.blueprint:0.1.0.r964701]
at org.apache.aries.blueprint.container.BlueprintRepository.destroy(BlueprintRepository.java:295)[7:org.apache.aries.blueprint:0.1.0.r964701]
</pre><br />
I realize this exception is from ESB kernel, karaf FeaturesServiceImpl class. After digging into the FeaturesServiceImpl code, I found that if the FeaturesListener gone, it should invoke unregisterListener() mothed, so we shouldn't have get this exception at all. <br />
the unregisterListener() mothed is <br />
<pre>public void unregisterListener(FeaturesListener listener) {
listeners.remove(listener);
}
</pre><br />
It's quite simple, and listeners is just a List instance. To figure out what's going on underlying, I launched remote debug for ESB process and set breakpoint in unregisterListener method, but what I saw then really confused me. I do see listeners List has a FeaturesListener instance, let's say with ObjectId 155, but when unregisterListener() get invoked with argument FeaturesListener instance exactly the same object with the one listeners List containing, listeners.remove(listener) doesn't work, listeners can't remove listener it actually contain.<br />
<br />
I know List use Object.equals() method to determine if two object really equal, I guess there must be something wrong in equal method, so I then step into the List.remove method and then Object.equals method, aha, listener just not eqaul itself. Well, finally figured out that this is caused by we use aries blueprint to inject FeatureListener as OSGi servie using dynamic proxy, it's not the real FeatureListener, it's just the proxy of FeatureListenr, this can explain the wired exception, equals() method from a proxy actually will compare a proxy and the real object, which obviously will return false, so we should override equals method to handle the proxy comparasion case.<br />
<br />
I googled a little bit, there's another good article to describe this <a href="https://uroam.progress.com/f5-w-687474703a2f2f7777772e6a6176617370656369616c697374732e6575$$/archive/Issue126.html">Proxy.equals</a>()[3] issue.And the issue from Apache Karaf to track is <a href="https://uroam.progress.com/f5-w-68747470733a2f2f6973737565732e6170616368652e6f7267$$/jira/browse/KARAF-136">KARAF-136</a>[4]<br />
[1]http://fusesource.com/<br />
[2]http://servicemix.apache.org/home.html<br />
[3]http://www.javaspecialists.eu/archive/Issue126.html<br />
[4]https://issues.apache.org/jira/browse/KARAF-136<br />
<script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><br />
<script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script>Freeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.com0tag:blogger.com,1999:blog-4560271620096405554.post-5877381742658070072010-09-20T05:11:00.000-07:002010-09-20T05:11:56.283-07:00jpa-osgi example in FUSE ESB 4Since FuseSource[1] ESB 4.2.0-01-00, we introduce a new example jpa-osgi to demostrate how jpa works in OSGi based ESB container. We choose to use hibernate as JPA implementation in this demo, as hibernate is popularly used in existing system. Package hibernate jars as bundle isn't a easy job, but thanks for Spring Source's great work, we can simply reuse those Spring Source hibernate bundles in our demo.<br />
<br />
We create a jpa-hibernate feature which put all necessary bundles together,<br />
<pre osgi:start 89> <feature name="jpa-hibernate" version="4.3.0-fuse-01-00"></br>
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.java-persistence-api-1.1.1/1.5.0</bundle></br>
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.2.2_5</bundle></br>
<bundle>mvn:org.springframework/spring-jdbc/3.0.3.RELEASE</bundle></br>
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_2</bundle></br>
<bundle>mvn:org.antlr/com.springsource.antlr/2.7.7</bundle></br>
<bundle>mvn:org.objectweb.asm/com.springsource.org.objectweb.asm/1.5.3</bundle></br>
<bundle>mvn:net.sourceforge.cglib/com.springsource.net.sf.cglib/2.2.0</bundle></br>
<bundle>mvn:org.jboss.javassist/com.springsource.javassist/3.9.0.GA</bundle></br>
<bundle>mvn:org.hibernate/com.springsource.org.hibernate.annotations.common/3.3.0.ga</bundle></br>
<bundle>mvn:org.hibernate/com.springsource.org.hibernate.annotations/3.4.0.GA</bundle></br>
<bundle>mvn:org.hibernate/com.springsource.org.hibernate.ejb/3.4.0.GA</bundle></br>
<bundle>mvn:org.hibernate/com.springsource.org.hibernate/3.3.2.GA</bundle></br>
<bundle>mvn:org.springframework/spring-orm/3.0.3.RELEASE</bundle></br>
</feature>
</pre> <br />
This demo is based on the cxf-wsdl-first scenario, which you can find it from both Fuse ESB 3.x and 4.x. The workflow is <br />
cxfbc consumer====>cxfse endpoint.<br />
cxfbc consumer handle external request, and cxfse endpoint retrieve PersonEntity according to ID from underlying hsqldb. We can put all complicated configuration in xbean used for cxf se endpoint.<br />
<br />
<pre width="60">
<cxfse:endpoint></br>
<cxfse:pojo></br>
<bean class="org.apache.servicemix.samples.wsdl_first.PersonImpl"></br>
<constructor-arg></br>
<ref bean="entityManagerFactory"/></br>
</constructor-arg></br>
</bean></br>
</cxfse:pojo></br>
</cxfse:endpoint></br>
<bean class="org.apache.servicemix.common.osgi.EndpointExporter" /></br>
also configure JPA entityManagerFacotry in this file</br>
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"></br>
<property name="transactionManager"></br>
<bean class="org.springframework.orm.jpa.JpaTransactionManager"></br>
<property name="entityManagerFactory" ref="entityManagerFactory"/></br>
</bean></br>
</property></br>
</bean></br>
<bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate"></br>
<property name="entityManagerFactory" ref="entityManagerFactory"/></br>
</bean></br>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"></br>
<property name="persistenceUnitName" value="smx4"/></br>
<property name="jpaVendorAdapter" ref="jpaAdapter"/></br>
<property name="dataSource" ref="dataSource" /></br>
</bean></br>
<bean id="jpaAdapter"</br>
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"></br>
<property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect" /></br>
</bean></br>
<!-- DataSource Definition --></br>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"></br>
<property name="driverClassName" value="org.hsqldb.jdbcDriver" /></br>
<property name="url" value="jdbc:hsqldb:mem:smx4_jpa" /></br>
<property name="username" value="sa" /></br>
<property name="password" value="" /></br>
</bean></br>
</pre><br />
And there's a JPA required persistence.xml in src/main/resources/META-INF/ folder<br />
<pre width="60"> <persistence xmlns="http://java.sun.com/xml/ns/persistence"</br>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"></br>
<persistence-unit name="smx4" transaction-type="RESOURCE_LOCAL"></br>
<class>org.apache.servicemix.samples.wsdl_first.PersonEntity</class></br>
<!-- Hibernate --></br>
<properties></br>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/></br>
<property name="hibernate.hbm2ddl.auto" value="create"/></br>
</properties></br>
</persistence-unit></br>
</persistence></br>
</pre><br />
After installing jpa-hibernate feature, we can see related bundles set<br />
<pre width="60">[ 179] [Active ] [ ] [ ] [ 60] Apache ServiceMix Specs :: JAVA PERSISTENCE API 1.4 (1.5.0)
[ 180] [Active ] [ ] [ ] [ 60] Apache ServiceMix Bundles: commons-dbcp-1.2.2 (1.2.2.5)
[ 181] [Active ] [ ] [ ] [ 60] Spring JDBC (3.0.3.RELEASE)
[ 182] [Active ] [ ] [ ] [ 60] Apache ServiceMix Bundles: dom4j-1.6.1 (1.6.1.2)
[ 183] [Active ] [ ] [ ] [ 60] ANTLR (2.7.7)
[ 184] [Active ] [ ] [ ] [ 60] ObjectWeb ASM (1.5.3)
[ 185] [Active ] [ ] [ ] [ 60] CGLIB Code Generation Library (2.2.0)
[ 186] [Active ] [ ] [ ] [ 60] Javassist Java Programming Assistant (3.9.0.GA)
[ 187] [Active ] [ ] [ ] [ 60] JBoss Hibernate Common Annotations (3.3.0.ga)
[ 188] [Resolved ] [ ] [ ] [ 60] JBoss Hibernate Annotations (3.4.0.GA)
Hosts: 190
[ 189] [Resolved ] [ ] [ ] [ 60] JBoss Hibernate Entity Manager (3.4.0.GA)
Hosts: 190
[ 190] [Active ] [ ] [ ] [ 60] JBoss Hibernate Object-Relational Mapper (3.3.2.GA)
Fragments: 188,189
[ 191] [Active ] [ ] [ ] [ 60] Spring ORM (3.0.3.RELEASE)
</pre>We can see bundle 188,189 are fragment bundle, at the moment we add this demo, Apache Felix not fully support fragment bundle yet, one outstanding issue is FELIX-1919[2], so this demo only works with equinox at that time. But now it works with both felix and equinox.<br />
<br />
As hibernate is LGPL license, we can't add this demo into Apache Servicemix[3], but we do have an issue[4] on Apache Servicemix to track it, we can use OpenJPA to replace hibernate for this demo an Apache Side later on. <br />
<br />
[1]http://fusesource.com<br />
[2]https://issues.apache.org/jira/browse/FELIX-1919<br />
[3]http://servicemix.apache.org/home.html<br />
[4]https://issues.apache.org/activemq/browse/SMX4-472Freeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.com9tag:blogger.com,1999:blog-4560271620096405554.post-7444194416560060402010-09-19T19:58:00.000-07:002010-09-19T22:53:15.965-07:00How to use HTTP Basic Auth with servicemix-cxf-bcFor <a href="https://uroam.progress.com/f5-w-687474703a2f2f736572766963656d69782e6170616368652e6f7267$$/servicemix-cxf-bc.html">servicemix-cxf-bc</a>[1] component in <a href="https://uroam.progress.com/f5-w-687474703a2f2f736572766963656d69782e6170616368652e6f7267$$/home.html">Apache Servicemix</a>[2] or <a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/">FuseSource</a>[3] ESB, there are several ways to use security feature for both consumer and provider endpoint. For message level security, we can secured SOAP message itself with WS-Security, or for transport protocol level security, we can use HTTPs which provide a secured HTTP connection. <br />
Actually we have testcases domenstrating how each scenario works<br />
<a href="https://uroam.progress.com/f5-w-68747470733a2f2f73766e2e6170616368652e6f7267$$/repos/asf/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/CxfBCSecurityTest.java">cxf bc consumer with ws-security testcase</a>[4]<br />
<a href="https://uroam.progress.com/f5-w-68747470733a2f2f73766e2e6170616368652e6f7267$$/repos/asf/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/CxfBcProviderSecurityTest.java">cxf bc provider with ws-security testcase</a>[5]<br />
<a href="https://uroam.progress.com/f5-w-68747470733a2f2f73766e2e6170616368652e6f7267$$/repos/asf/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/CxfBcHttpsConsumerTest.java">cxf bc consumer with https testcase</a>[6]<br />
<a href="https://uroam.progress.com/f5-w-68747470733a2f2f73766e2e6170616368652e6f7267$$/repos/asf/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/CxfBcProviderHttpsTest.java">cxf bc provider with https testcase</a>[7]<br />
<br />
However, instead of using WS-Security or HTTPS, one straightforward way is use HTTP Basic Authentication. For cxfbc provider endpoint which play a role as a client, to enaable HTTP Basic Auth, customer need specify a busCfg which configure http:conduit, something like<br />
<br />
<pre><http:conduit name="{your_name_space}your_endpoint_name.http-conduit"></br>
<http:authorization></br>
<sec:username>Betty</sec:username></br>
<sec:password>password</sec:password></br>
</http:authorization></br>
</http:conduit></pre><br />
<br />
For cxfbc consumer which play a role as a server, to enable server side HTTP Basic Auth, we need an interceptor to do it, the basic idea is extract AuthorizationPolicy from the incoming message and compare the username/password, but it's not so complicated, here is a good <a href="https://uroam.progress.com/f5-w-687474703a2f2f63687269736461696c2e636f6d$$/2008/03/31/apache-cxf-with-http-basic-authentication/">article</a>[8] to show how to do it.<br />
<br />
Another way(as Dan Kulp pointed out) to configure server side basic auth is configure the jetty instance to handle the authentication, as Jetty has a "SecurityHandler" that can be configured into the handlers via CXF config. The SecurityHandler takes an Authenticator(they have a BasicAuthenticator) and a UserRealm Object (they have one for basic HashMap lookup things as well as a JDBC version)<br />
<br />
<br />
[1]http://servicemix.apache.org/servicemix-cxf-bc.html<br />
[2]http://servicemix.apache.org/home.html<br />
[3]http://fusesource.com/<br />
[4]https://svn.apache.org/repos/asf/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/CxfBCSecurityTest.java<br />
[5]https://svn.apache.org/repos/asf/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/CxfBcProviderSecurityTest.java<br />
[6]https://svn.apache.org/repos/asf/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/CxfBcHttpsConsumerTest.java<br />
[7]https://svn.apache.org/repos/asf/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/CxfBcProviderHttpsTest.java<br />
[8]http://chrisdail.com/2008/03/31/apache-cxf-with-http-basic-authentication/<br />
<br />
<script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script>Freeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.com0tag:blogger.com,1999:blog-4560271620096405554.post-91491657893283586102010-09-19T03:24:00.000-07:002010-09-19T03:24:55.377-07:00How to get/set properties from/to JBI NMR within cxf se endpointAs the typical way to use cxf se component in <a href="https://uroam.progress.com/f5-w-687474703a2f2f736572766963656d69782e6170616368652e6f7267$$/home.html">Apache Servicemix</a>[1] or <a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/">FuseSource</a>[2] ESB is like<br />
JBI consumer endpoint<=====> cxf se endpoint.Sometimes customer want to put extra properties during runtime in JBI NormalizedMessage with JBI consumer endpoint and retrieve it from cxf se endpoint later on.<br />
With <a href="https://uroam.progress.com/f5-w-68747470733a2f2f6973737565732e6170616368652e6f7267$$/activemq/browse/SMXCOMP-593">SMXCOMP-593</a>[3], we provide a webservice friendly and CXF-ish way to retrieve and set properties in cxf se endpoint.<br />
Customer just need add code like<br />
<br />
@Resource<br />
private WebServiceContext wsContext;<br />
to inject WebServiceContext to this CxfSeEndpoint<br />
<br />
and use<br />
javax.xml.ws.handler.MessageContext ctx = wsContext.getMessageContext();<br />
org.apache.cxf.message.Message message = ((org.apache.cxf.jaxws.context.WrappedMessageContext) ctx).getWrappedMessage();<br />
String propertyValue = (String) message.get("PROPERTY_NAME");//retrieve property<br />
message.put("PROPERTY_NAME", "newPropertyValue");//set property<br />
<br />
to get/set properties within cxf se endpoint.<br />
<br />
[1]http://servicemix.apache.org/home.html<br />
[2]http://fusesource.com/<br />
[3]https://issues.apache.org/activemq/browse/SMXCOMP-593<br />
<script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script>Freeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.com2tag:blogger.com,1999:blog-4560271620096405554.post-59920579369952460482010-09-19T01:52:00.000-07:002010-09-19T01:52:15.615-07:00How to configure cxf bus for smx-cxf-bc in SMX4?In <a href="https://uroam.progress.com/f5-w-687474703a2f2f736572766963656d69782e6170616368652e6f7267$$/home.html">Apache Servicemix</a>[1] 3.x or <a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/">FuseSource</a>[2] ESB 3.x, we use busCfg to specify cxf bus configuration file for <a href="https://uroam.progress.com/f5-w-687474703a2f2f736572766963656d69782e6170616368652e6f7267$$/servicemix-cxf-bc.html">servicemix-cxf-bc</a>[3] component, and busCfg is popularly used in serivicemix-cxf-bc for advanced features, such as ws-*, https, jms transport, etc.<br />
<br />
How ever, there's an issue for using busCfg in <a href="https://uroam.progress.com/f5-w-687474703a2f2f736572766963656d69782e6170616368652e6f7267$$/home.html">Apache Servicemix</a>[1]4.x or <a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/">FuseSource</a>[2] ESB 4.x which is based on an OSGi core container. In OSGi world, it use a very different classloader machenism with the old hierarchical one, so that the the busCfg file in customer cxfbc endpoint bundle isn't available for pre-installed cxf bundle. The way to use busCfg in SMX4 is that create a fragment bundle including the busCfg file, and attach it to cxf bundle, here cxf bundle play the role as host bundle and all resource in fragment bundle is available for host bundle. Actually we can encounter similar issue often in OSGi world, if the api is passing a configuration file, we can see the same problem, the bundle host the api code can't load the resource from the customer bundle which use the api. Here is a similar discussion from FUSE side jira(<a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/issues/browse/ESB-1245">ESB-1245</a>)[4], a problem caused by need pass WSS4J signature properties file to wss4j bundle.<br />
<br />
Besides using fragment bundle to hold configuration files, we introduce providedBus(<a href="https://uroam.progress.com/f5-w-68747470733a2f2f6973737565732e6170616368652e6f7267$$/activemq/browse/SMXCOMP-688">SMXCOMP-688</a>)[5] in smx4 which init cxf bus bean in same context with cxf bc endpoint configuration, this way avoid passing configuration file between bundles.<br />
<br />
[1]http://servicemix.apache.org/home.html<br />
[2]http://fusesource.com/<br />
[3]http://servicemix.apache.org/servicemix-cxf-bc.html<br />
[4]http://fusesource.com/issues/browse/ESB-1245<br />
[5]https://issues.apache.org/activemq/browse/SMXCOMP-688<br />
<script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script>Freeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.com0tag:blogger.com,1999:blog-4560271620096405554.post-60105727714187758832010-08-23T02:23:00.000-07:002010-09-19T05:30:09.324-07:00About Apache Asia RoadShow in ShanghaiI attended <a href="https://uroam.progress.com/f5-w-687474703a2f2f726f616473686f77617369612e353261632e636f6d$$/openconf.php">Apache Asia RoadShow in ShangHai</a> during last weekend[1], and I'm a speaker of session with subject OSGi OVERVIEW. This session is mainly cover some basic concepts of OSGi and I also go through several Apache projects which are related to OSGi, of course including <a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/">FUSE</a>[2] ESB(which is based on Apache Servicemix and the Apache Karaf) <br />
<br />
There're dozens of audiences who are interested in OSGi and related Apache projects. The Q&A period is a little bit long but my session time is out before I'm aware of it, so I have to stand in the corridor surrounded with several guys who still wanna ask questions. Those questions not only focus on the technical area, but they are also want to know What's <a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/">FUSE</a>[2], how many guys in <a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/">FUSE</a> team and where they are, how we work together and so on.<br />
<br />
<br />
This is the third time I attend Apache Asia RoadShow, last two times it's in Beijing, the city I'm living now. This time several apache commiters in China also attend, most of them work for IBM on Apache Geronimo and Harmony. There's a party after this event, where I have a good chat with Nicolas Hedhman, who created ops4j and he said he is very close with several guys from <a href="https://uroam.progress.com/f5-w-687474703a2f2f66757365736f757263652e636f6d$$/">FUSE</a>[2] team. How small the world is! :-)<br />
<br />
<br />
Here is the <a href="https://uroam.progress.com/f5-w-687474703a2f2f7777772e61736b666f726d2e636e$$/FormViewResult.aspx?Type=1&FormID=99925&UserID=40398">feedback</a>[3] about this event, I'm so glad that most audience select my speech "OSGi Overview" as favorate afternoon sessions.<br />
<br />
<br />
<br />
[1]http://roadshowasia.52ac.com/openconf.php<br />
[2]http://fusesource.com/<br />
[3]http://www.askform.cn/FormViewResult.aspx?Type=1&FormID=99925&UserID=40398 <br />
<br />
<script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><br />
<script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script>Freeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.com0tag:blogger.com,1999:blog-4560271620096405554.post-51088287117717067822010-08-06T00:22:00.000-07:002010-08-06T00:22:25.059-07:00My BlogThere will be more blogs in the near future ...<br />
<script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script>
try{F5_flush(document);}catch(e){}
</script><script id="F5_watermark">
</script><script>
try{F5_flush(document);}catch(e){}
</script>Freeman Fanghttp://www.blogger.com/profile/18112794230355349643noreply@blogger.com0