3

I have a simple session EJB (3.0 spec) deployed on GlassFish 3.1 with a remote interface. Here is the log snippet showing deployment:

INFO: Portable JNDI names for EJB RandomNumber2Bean : [java:global/RandomNumberEJB/RandomNumber2Bean, java:global/RandomNumberEJB/RandomNumber2Bean!beans.RandomNumber2]
INFO: Glassfish-specific (Non-portable) JNDI names for EJB RandomNumber2Bean : [RandomNumber2, RandomNumber2#beans.RandomNumber2]

I am trying to invoke it from a Servlet deployed on a JBoss AS 7.1.1 instance on the same machine. Here is the relevant code from the servlet:

Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
InitialContext initialContext = new javax.naming.InitialContext(props);
RandomNumber2 randomNumber2 = (RandomNumber2) initialContext.lookup("RandomNumber2");

However, whenever I try to get the InitialContext from the servlet to look up the bean, I get the following error:

javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory com.sun.enterprise.naming.SerialInitContextFactory from classloader ModuleClassLoader for Module "deployment.RandomNumberTesterGlassfish.war:main" from Service Module Loader
at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:681)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at test.RandomNumberServlet.doGet(RandomNumberServlet.java:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
at java.lang.Thread.run(Thread.java:722)

I have added the client jars appserv-rt.jar and gf-client.jar from GlassFish into the build path of the client Servlet application (I am using Eclipse Juno to deploy it) and to the %JBOSS_HOME%\standalone\lib\ext directory.

I cannot find anything on the web that even mentions invoking EJB's deployed on GlassFish 3.1 from JBoss AS 7.1.1. I am totally at a loss at this point. I am able to invoke the EJB's deployed on GlassFish with a standalone client and I am able to invoke the same EJB's deployed on JBoss both from a standalone client and from GlassFish.

user1709829
  • 101
  • 1
  • 5

3 Answers3

2

It is written in the log: "Glassfish-specific (Non-portable) JNDI names". So, it probably won't work from JBoss. Try this one instead:

RandomNumber2 randomNumber2 = (RandomNumber2) initialContext.lookup("java:global/RandomNumberEJB/RandomNumber2Bean");
gaborsch
  • 15,408
  • 6
  • 37
  • 48
1

I think you can not load the GlassFish native libraries in Jboss AppServer. I test the props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory"); config in three AppServers: GlassFish 3, Jboss 7 and WebSphere 8. The only application server that run the application properly was Glassfish. (because of com.sun.enterprise.naming.impl.SerialInitContextFactory )

You should run your application in GlassFish. here is the full configuration:

        Properties props = new Properties();
        props.setProperty("java.naming.factory.initial",
                "com.sun.enterprise.naming.SerialInitContextFactory");

        props.setProperty("java.naming.factory.url.pkgs",
                "com.sun.enterprise.naming");

        props.setProperty("java.naming.factory.state",
                "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

        props.setProperty("org.omg.CORBA.ORBInitialHost", "IP");
        props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

        InitialContext context = new InitialContext(props);
        RandomNumber2 randomNumber2 =(RandomNumber2)context.lookup("RandomNumber2");
Mojtaba
  • 382
  • 1
  • 2
  • 26
0

Can you try setting the below properties too

props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
Abdullah Shaikh
  • 2,567
  • 6
  • 30
  • 43