You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Bengt Rodehav <be...@rodehav.com> on 2013/09/10 12:00:43 UTC

JNDI and Weblogic

I'm trying to connect to Weblogic JMS from within Karaf. I've
wrapped wlthint3client.jar Weblogic from Weblogic in an OSGi bundle. I use
the following code:

    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
    env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
    InitialContext ctx = new InitialContext(env);

This works perfectly outside OSGi but in Karaf I get:

Caused by: java.lang.ClassNotFoundException: Failed to load class
weblogic.jms.client.JMSConnectionFactory
at
weblogic.rmi.utils.WLRMIClassLoaderDelegate.loadClass(WLRMIClassLoaderDelegate.java:208)
at
weblogic.rmi.utils.WLRMIClassLoaderDelegate.loadClass(WLRMIClassLoaderDelegate.java:135)
at weblogic.rmi.utils.Utilities.loadClass(Utilities.java:305)
at
weblogic.rjvm.MsgAbbrevInputStream.resolveClass(MsgAbbrevInputStream.java:433)
at
weblogic.utils.io.ChunkedObjectInputStream$NestedObjectInputStream.resolveClass(ChunkedObjectInputStream.java:268)
at
java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)[:1.6.0_32]
at
java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)[:1.6.0_32]
at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)[:1.6.0_32]
at
java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)[:1.6.0_32]
at
java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)[:1.6.0_32]
at
weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:208)
at
weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:596)
at
weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:204)
at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:62)
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:240)
... 35 more

It looks like the the classloader being used is the frameworks classloader
(:1.6.0_32) which has not imported these packages. I have a feeling that it
is the service discovery mechanism that is failing. I know that Servicemix
has wrapped several bundles and made it possible for Java's service
discovery mechanism to work.

Am I doing this all wrong or should my code work? Also, if I want to
support service discovery the way ServiceMix bundles do - how do I do this?
Is there a good example bundle I can look at?

/Bengt

Re: JNDI and Weblogic

Posted by Bengt Rodehav <be...@rodehav.com>.
An update...

When looking further into this, it does not seem to involve service
discovery but only old fashioned classloading problems. It seems I have to
set the TCCL in order to get this to work. The following code works:

        env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
        env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
        ClassLoader orgCl = Thread.currentThread().getContextClassLoader();
        InitialContext ctx = null;
        ConnectionFactory cf = null;
        try {

Thread.currentThread().setContextClassLoader(WLInitialContextFactory.class.getClassLoader());
          ctx = new InitialContext(env);
          cf = (ConnectionFactory)ctx.lookup("Q_CONN_FACTORY");
        }
        finally {
          Thread.currentThread().setContextClassLoader(orgCl);
        }

Note that I first tried to use "this"  bundle's classloader but it didn't
work. When I do an actual lookup, I will get back an internal Weblogic
class (in this case weblogic.jms.client.JMSConnectionFactory) that cannot
be unmarshalled unless that class can be found on the classpath. Thus, I
must set the TCCL to the bundle that wraps wlthint3client.jar.

/Bengt


2013/9/10 Bengt Rodehav <be...@rodehav.com>

> I'm trying to connect to Weblogic JMS from within Karaf. I've
> wrapped wlthint3client.jar Weblogic from Weblogic in an OSGi bundle. I use
> the following code:
>
>     Hashtable<String, String> env = new Hashtable<String, String>();
>     env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
>     env.put(Context.INITIAL_CONTEXT_FACTORY,
> "weblogic.jndi.WLInitialContextFactory");
>     InitialContext ctx = new InitialContext(env);
>
> This works perfectly outside OSGi but in Karaf I get:
>
> Caused by: java.lang.ClassNotFoundException: Failed to load class
> weblogic.jms.client.JMSConnectionFactory
>  at
> weblogic.rmi.utils.WLRMIClassLoaderDelegate.loadClass(WLRMIClassLoaderDelegate.java:208)
> at
> weblogic.rmi.utils.WLRMIClassLoaderDelegate.loadClass(WLRMIClassLoaderDelegate.java:135)
>  at weblogic.rmi.utils.Utilities.loadClass(Utilities.java:305)
> at
> weblogic.rjvm.MsgAbbrevInputStream.resolveClass(MsgAbbrevInputStream.java:433)
>  at
> weblogic.utils.io.ChunkedObjectInputStream$NestedObjectInputStream.resolveClass(ChunkedObjectInputStream.java:268)
> at
> java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)[:1.6.0_32]
>  at
> java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)[:1.6.0_32]
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)[:1.6.0_32]
>  at
> java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)[:1.6.0_32]
> at
> java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)[:1.6.0_32]
>  at
> weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:208)
> at
> weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:596)
>  at
> weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:204)
> at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:62)
>  at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:240)
> ... 35 more
>
> It looks like the the classloader being used is the frameworks classloader
> (:1.6.0_32) which has not imported these packages. I have a feeling that it
> is the service discovery mechanism that is failing. I know that Servicemix
> has wrapped several bundles and made it possible for Java's service
> discovery mechanism to work.
>
> Am I doing this all wrong or should my code work? Also, if I want to
> support service discovery the way ServiceMix bundles do - how do I do this?
> Is there a good example bundle I can look at?
>
> /Bengt
>
>
>