servicemix-osgi-cxf-wsdl-first-archetype) are really handy in that regard - nice work Ashwin Karpe! Those new archetypes have been checked in to SVN, but may not be in the release build yet so if you want them you may need to check them out and build them locally.
Because SMX4 is built on OSGi, you can deploy any Java artifact, not just JBI components. I put this to the test: my customer wanted to have a single, shared JDBC pool across all of his bundles. You can do this by creating the pool in a simple Spring file, and registering it as a service for all the other bundles to use. To do this, I installed the driver for PostgreSQL into my SMX container, using the nifty "wrap:" feature that will take a jar and osgi-ify it. Then, I created a Spring context file to intantiate the bean, like this:
<bean id="postgresPoolingDS" class="org.postgresql.ds.PGPoolingDataSource">
<property name="serverName" value="localhost"/>
<property name="databaseName" value="play"/>
<property name="portNumber" value="0"/>
<property name="user" value="play"/>
<property name="password" value="pa55w0rd"/>
<property name="dataSourceName" value="postgres"/>
<property name="initialConnections" value="1"/>
<property name="maxConnections" value="100"/>
<osgi:service id="postgresPoolingDSService" ref="postgresPoolingDS"
Here's the really neat bit: when you drop this spring file into the
deploydirectory of ServiceMix 4, the ServiceMix kernel will osgi-ify the file and deploy it as a bundle. Hey-presto: the pool is created and registered as a service in the OSGi service registry.
To access this service from one of my camel routes, I used the
<osgi:reference>to get a reference to the dataSource in my bundle's spring file. You can then inject the reference into your route and away you go.
<osgi:reference id="dataSource" interface="javax.sql.DataSource" />
The "look-up" is done by interface type: in this case I'm OK as there's only one
javax.sql.DataSourceregistered. I should really do a more explicit query, but I guess I'll leave that as an exercise for the interested reader.
For me, this kind of thing is OSGi at its best: allowing sharing and reuse of Java classes and Java objects in a really nice, modular way.