Problem with Classloader switch and narrow Object [message #44186] |
Tue, 29 June 2004 08:15 |
Eclipse User |
|
|
|
We are using different plugins in our application. The main one depends on a library plugin containing the weblogic jar. To get the InitialContext from the weblogic jar we need to switch the Classloader (without we get an javax.naming.NoInitialContextException). If we wan't to get the RemoteHomeObject of another plugin we get an ClassCastException, Cannot narrow....
Can anyone help me on this subject? Is the Classloader switch still needing? If yes how does it work if I have to switch between different plugins?
code
==========
public ServiceLocator() throws ServiceLocatorException
{
try
{
ClassloaderSwitch.switch2CL();
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://myhost:8880");
ic = new InitialContext(env);
}
catch (NamingException ne)
{
throw new ServiceLocatorException(ne);
}
catch (Exception e)
{
throw new ServiceLocatorException(e);
}
finally
{
ClassloaderSwitch.switch2Normal();
}
}
...
public EJBHome getRemoteHome(String jndiHomeName, Class className)
throws ServiceLocatorException
{
EJBHome home = null;
try
{
Object objref = ic.lookup(jndiHomeName);
Object obj = PortableRemoteObject.narrow(objref, className);
home = (EJBHome) obj;
}
catch (NamingException ne)
{
throw new ServiceLocatorException(ne);
}
catch (Exception e)
{
throw new ServiceLocatorException(e);
}
return home;
}
===========
Beat
|
|
|
Powered by
FUDForum. Page generated in 0.02534 seconds