Archive | tomcat-to-glassfish-call-jndi RSS feed for this section

Spiegazione-problema-classloder-serialcontext-per-call-ejbremote

4 Jan

Vedere questa spiegazione assolutamente.

http://stackoverflow.com/questions/7804357/serialinitcontextfactory-not-found-in-glassfish-naming

classloader-problema-per-serial-init-context

3 Jan

https://www.java.net//node/703676

the exception :

root cause

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.SerialInitContextFactory]
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
javax.naming.InitialContext.init(InitialContext.java:242)
javax.naming.InitialContext.<init>(InitialContext.java:216)
test.TestServlet.initTestBean(TestServlet.java:48)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:724)

the solution

I avoid the same problem by put following code:

Class clazz = Class.forName(this.getClass().getName());
Thread thread = Thread.currentThread();
ClassLoader classLoaderThread = thread.getContextClassLoader();
System.out.println(“ClassLoader for Thread : ” + classLoaderThread);
ClassLoader classLoaderClass = clazz.getClassLoader();
System.out.println(“ClassLoader for Class : ” + classLoaderClass);
thread.setContextClassLoader(classLoaderClass);

before the “context.lookup”.
This change:
ClassLoader for Thread : org.eclipse.core.runtime.internal.adaptor.ContextFinder@1970ae0
to:
ClassLoader for Class : org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@d19bc8
and works (at least in my case).

 

———————————————

My 11 day quest to connecting JMS client to remote GlassFish from Tomcat

 

http://blog.trifork.com/2010/12/02/my-11-day-quest-to-connecting-jms-client-to-remote-glassfish-from-tomcat/