OSGi & binding object to JNDI

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

OSGi & binding object to JNDI

Mariusz.Cwikla
This post has NOT been accepted by the mailing list yet.
Hello,
I have an issue with binding an object to JNDI.
I want to use Jetty inside an OSGi container with an JMS provider. I'm using Jetty 8.1.0.RC4, included with Eclipse RAP 1.5 runtime. For JMS provider I decided to use ActiveMQ.
According to http://docs.codehaus.org/display/JETTY/Integrating+with+ActiveMQ I have to do some configuration in jetty.xml, but Jetty included with RAP runtime is a collection of bundles without jetty.xml. BTW, it does not include jetty-jndi-8.1.0.RC4.jar, so I added it manually.
Then I tried this simple Activator:


System.getProperties().setProperty("java.naming.factory.url.pkgs", "org.eclipse.jetty.jndi");
System.getProperties().setProperty("java.naming.factory.initial",  "org.eclipse.jetty.jndi.InitialContextFactory");

ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();

InitialContext ctx = new InitialContext();
ctx.bind("myconnectionFactory", activeMQConnectionFactory);

ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("myconnectionFactory");



but I get java.lang.ClassCastException: javax.naming.Reference cannot be cast to javax.jms.ConnectionFactory. Did I messed something up with binding? Shouldn't lookup() return the same type as was used in bind()?

Here is complete list of bundles in my OSGi environment:
com.ibm.icu.base
javax.activation
javax.mail.glassfish
javax.servlet
jcl.over.slf4j
org.apache.activemq.activemq-core
org.apache.activemq.kahadb
org.apache.felix.gogo.command
org.apache.felix.gogo.runtime
org.apache.felix.gogo.shell
org.apache.geronimo.specs.geronimo-j2ee-management_1.1_spec
org.apache.geronimo.specs.geronimo-jms_1.1_spec
org.eclipse.core.commands
org.eclipse.core.contenttype
org.eclipse.core.databinding.observable
org.eclipse.core.databinding.property
org.eclipse.core.databinding
org.eclipse.core.expressions
org.eclipse.core.jobs
org.eclipse.core.runtime
org.eclipse.equinox.common
org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.registry
org.eclipse.equinox.http.servlet
org.eclipse.equinox.http.servletbridge
org.eclipse.equinox.preferences
org.eclipse.equinox.registry
org.eclipse.equinox.servletbridge.extensionbundle
org.eclipse.help
org.eclipse.jetty.continuation
org.eclipse.jetty.http
org.eclipse.jetty.io
org.eclipse.jetty.jndi
org.eclipse.jetty.security
org.eclipse.jetty.server
org.eclipse.jetty.servlet
org.eclipse.jetty.util
org.eclipse.osgi.services
org.eclipse.osgi
org.eclipse.rap.jface
org.eclipse.rap.rwt.osgi
org.eclipse.rap.rwt
org.eclipse.rap.ui.workbench
org.eclipse.rap.ui
slf4j.api
slf4j.jdk14