users@glassfish.java.net

Re: Standalone EJB 3.1 client

From: Tim Quinn <tim.quinn_at_oracle.com>
Date: Fri, 9 Mar 2012 18:07:58 -0600

Sean, take a look at this FAQ:

http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html

One key point is that for GlassFish you do NOT want to pass in
arguments to the InitialContext constructor.

Set system properties instead of creating a Properties object to pass
in.

- Tim

On Mar 9, 2012, at 4:04 PM, Comerford, Sean wrote:

> Yeah, clearly I’m doing something wrong b/c I’m adding a whole slew
> of GF jars to my standalone client.
>
> I seem to have gotten that to stop throwing ClassNotFound errors by
> adding the jars but seeing a NamingException now.
>
> This is the code we’re using for the lookup:
>
> Properties properties = new Properties();
> properties.setProperty("java.naming.factory.initial",
>
> "com.sun.enterprise.naming.SerialInitContextFactory");
> properties.setProperty("java.naming.factory.url.pkgs",
> "com.sun.enterprise.naming");
> properties.setProperty("java.naming.factory.state",
>
> "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
>
> properties.setProperty("org.omg.CORBA.ORBInitialHost", host);
> properties.setProperty("org.omg.CORBA.ORBInitialPort",
> String.valueOf(port));
>
> InitialContext initialContext = new
> InitialContext(properties);
>
> provider = (T) initialContext.lookup(ejbName);
>
>
>
> It gives me this error when I invoke the client… the ORBInitialPort
> of 6457 and host of vwdsas02 are correct.
>
> - Error getting EJB session!
> javax.naming.NamingException: Lookup failed for 'ejb/
> CompetitionService' in
> SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=6457,
> java
> .naming
> .factory.initial=com.sun.enterprise.naming.SerialInitContextFactory,
> org.omg.CORBA.ORBInitialHost=vwdsas02.corp.espn3.com,
> java
> .naming
> .factory
> .state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,
> java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root
> exception is javax.naming.NamingException: Unable to acquire
> SerialContextProvider for
> SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=6457,
> java
> .naming
> .factory.initial=com.sun.enterprise.naming.SerialInitContextFactory,
> org.omg.CORBA.ORBInitialHost=vwdsas02.corp.espn3.com,
> java
> .naming
> .factory
> .state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,
> java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root
> exception is java.lang.NullPointerException]]
> at
> com
> .sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:
> 518)
> at
> com
> .sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:
> 455)
> at
> javax.naming.InitialContext.lookup(InitialContext.java:392)
> at
> com
> .espn
> .sports
> .ws
> .client.EJBSessionPoolFactory.makeObject(EJBSessionPoolFactory.java:
> 61)
> at
> org
> .apache
> .commons
> .pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:974)
> at
> com
> .espn.sports.ws.client.EJBSessionPool.getSession(EJBSessionPool.java:
> 115)
> at
> com.espn.sports.ws.client.EJBClient.getSession(EJBClient.java:92)
> at
> com
> .espn
> .sports
> .ws.client.CompetitionClient.getCompetition(CompetitionClient.java:60)
> at
> com
> .espn
> .sports
> .ws
> .client
> .tea.CompetitionTeaContext.getCompetition(CompetitionTeaContext.java:
> 50)
> at MergedClass$1933087151.getCompetition(Unknown
> Source)
> at com.go.teaservlet.template.test.execute(test.tea:8)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun
> .reflect
> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun
> .reflect
> .DelegatingMethodAccessorImpl
> .invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at com.go.tea.runtime.TemplateLoader
> $TemplateImpl.execute(TemplateLoader.java:270)
> at com.go.tea.engine.TemplateSourceImpl
> $TemplateImpl.execute(TemplateSourceImpl.java:1067)
> at
> com.go.teaservlet.TeaServlet.processTemplate(TeaServlet.java:662)
> at
> com.go.teaservlet.TeaServlet.doGet(TeaServlet.java:308)
> at
> go.barista.servlet.TQTeaServlet.doGet(TQTeaServlet.java:116)
> at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
> at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at go.barista.http.HttpServletDispatcher
> $ServletFilterChainTransaction.doFilter(HttpServletDispatcher.java:
> 1436)
> at
> go
> .barista
> .http.ErrorForwardingFilter.doFilter(ErrorForwardingFilter.java:81)
> at
> go.barista.http.SortableFilter.doFilter(SortableFilter.java:42)
> at go.barista.http.HttpServletDispatcher
> $ServletFilterChainTransaction.doFilter(HttpServletDispatcher.java:
> 1431)
> at go.barista.http.HttpServletDispatcher
> $ServletFilterChainTransaction.service(HttpServletDispatcher.java:
> 1409)
> at com.go.trove.util.tq.TransactionQueue
> $Worker.run(TransactionQueue.java:674)
> at com.go.trove.util.ThreadPool
> $PooledThread.run(ThreadPool.java:698)
> Caused by: javax.naming.NamingException: Unable to acquire
> SerialContextProvider for
> SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=6457,
> java
> .naming
> .factory.initial=com.sun.enterprise.naming.SerialInitContextFactory,
> org.omg.CORBA.ORBInitialHost=vwdsas02.corp.espn3.com,
> java
> .naming
> .factory
> .state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,
> java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root
> exception is java.lang.NullPointerException]
> at
> com
> .sun
> .enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:
> 352)
> at
> com
> .sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:
> 504)
> ... 28 more
> Caused by: java.lang.NullPointerException
> at
> com
> .sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:
> 365)
> at
> com
> .sun
> .enterprise
> .naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
> at
> com
> .sun
> .enterprise
> .naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
> at
> com
> .sun
> .enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:
> 347)
> ... 29 more
> - Error invoking getCompetition(int) with arguments: 131005003
>
> From: Tim Quinn [mailto:tim.quinn_at_oracle.com]
> Sent: Friday, March 09, 2012 4:42 PM
> To: users_at_glassfish.java.net
> Cc: users_at_glassfish.dev.java.net
> Subject: Re: Standalone EJB 3.1 client
>
>
> On Mar 9, 2012, at 3:24 PM, Comerford, Sean wrote:
>
>
> Never mind, found it in $GF_HOME/modules/glassfish-naming.jar
>
> Yes, depending on exactly what you're doing in your client the gf-
> client.jar and its long train might be more than you need, but be
> aware that in 3.x gf-client.jar is the equivalent to 2.x's appserv-
> rt.jar at least as far as clients are concerned. Perhaps appserv-
> rt.jar was really more than you needed previously anyway.
>
> - Tim
>
>
>
> From: Comerford, Sean [mailto:Sean.Comerford_at_espn.com]
> Sent: Friday, March 09, 2012 4:16 PM
> To: users_at_glassfish.dev.java.net
> Subject: Standalone EJB 3.1 client
>
> I am trying to run an EJB 3.1 client from a standalone process.
>
> I’m getting a no class def found on
> com.sun.enterprise.naming.SerialInitContextFactory
>
> I know in GF v2 this was in appserv-rt.jar but I’m not sure what jar
> from GF 3.1.1 installation I need to put on my standalone classpath.
>
> Any help?
>
> --
> Sean Comerford
> ESPN.com Site Architecture
>
> Please consider the environment before printing this e-mail.
>