1 2 Previous Next 20 Replies Latest reply on Dec 20, 2012 2:54 AM by nickarls

    Jboss 7.1 error on new InitialContext();

    alisissa

      I have been struggling with this error for almost 8 hours and it is becoming really frustrating, so any help here would be really appreciated:

       

       

      Here is what I am trying:

       

       

          final Properties jndiProperties = new Properties();

          jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

          // create the context

          final Context jndiContext = new InitialContext(jndiProperties);

          Object ref = jndiContext.lookup("ejb:MYApp/MYEjb//gss.myejb.sessions.MySecurityRemote");

       

       

      and here is my error:

       

       

          javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.MyApp.war:main" from Service Module Loader

                    org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)

                    javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:681)

                    javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)

                    javax.naming.InitialContext.init(InitialContext.java:240)

                    javax.naming.InitialContext.<init>(InitialContext.java:214)

                    utils.ResourceCenter.lookupMySecurityBean(ResourceCenter.java:62)

                    mynamespace.MyBean.<init>(MyBean.java:39)

                    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

                    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

                    java.lang.reflect.Constructor.newInstance(Constructor.java:532)

                    java.lang.Class.newInstance0(Class.java:372)

                    java.lang.Class.newInstance(Class.java:325)

                    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:121)

                    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:152)

                    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:141)

                    com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:111)

                    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:270)

                    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:360)

                    com.opensymphony.xwork2.DefaultActionInvocation.access$000(DefaultActionInvocation.java:38)

                    com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:78)

                    com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

                    com.opensymphony.xwork2.DefaultActionInvocation.<init>(DefaultActionInvocation.java:70)

                    com.opensymphony.xwork2.DefaultActionInvocation.<init>(DefaultActionInvocation.java:66)

                    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)

                    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)

                    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:497)

                    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421)

        • 1. Re: Jboss 7.1 error on new InitialContext();
          ctomc

          Hi,

           

          your InitialContext is picking up "org.jnp.interfaces.NamingContextFactory" setting/property somewhere.

          that was for versions before AS7. check where this is coming in and it will probably solve your problem.

           

           

           

          --

          tomaz

          • 2. Re: Jboss 7.1 error on new InitialContext();
            alisissa

            Thanks, I fixed th error using this:

             

            Hashtable jndiProps = new Hashtable();

                        jndiProps.put("java.naming.factory.initial", "org.jboss.as.naming.InitialContextFactory");

                        InitialContext jndiContext = new InitialContext(jndiProps);

             

            now I got this error:

            java.lang.ClassCastException: org.jboss.ejb.client.naming.ejb.EjbNamingContext cannot be cast to org.omg.CORBA.Object

            • 3. Re: Jboss 7.1 error on new InitialContext();
              nickarls

              What are you trying to lookup from where? Remote EJB from standalone client? Show all code and stacktrace you can.

              • 4. Re: Jboss 7.1 error on new InitialContext();
                alisissa

                Hashtable jndiProps = new Hashtable();

                jndiProps.put("java.naming.factory.initial", "org.jboss.as.naming.InitialContextFactory");

                InitialContext jndiContext = new InitialContext(jndiProps);

                Object ref = jndiContext.lookup("ejb:MyApp/MySecurityBean!tpg.myapp.sessions.MySecurityRemote");

                MySecurityRemote dao = (MySecurityRemote) PortableRemoteObject.narrow(ref, MySecurityRemote.class);

                • 5. Re: Jboss 7.1 error on new InitialContext();
                  nickarls

                  Have you compared your attempts with https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

                  First guess would be something like the stuff being looked up isn't really a remote interface.

                  • 6. Re: Jboss 7.1 error on new InitialContext();
                    alisissa

                    the stuff being looked up (the beams) are beams from my project, how should i look them up?

                    • 7. Re: Jboss 7.1 error on new InitialContext();
                      nickarls

                      The doc mentions a ?stateful end for the lookup URL for stateful beans. And the remote is @Remote annotated (or otherwise defined as a remote interface)?

                      • 8. Re: Jboss 7.1 error on new InitialContext();
                        alisissa

                        i put this now: Object ref = context.lookup("ejb:myapp//MYbean!gss.myapp.sessions.MySecurityRemote?stateful");

                        and i am getting this error: java.lang.IllegalStateException: No EJB receiver available for handling [appName:myapp,modulename:,distinctname:] combination

                        Can you please help

                        • 9. Re: Jboss 7.1 error on new InitialContext();
                          nickarls

                          How is it deployed? WAR? JAR? Check the URL against the app-name and module-name mentioned in the article. Check output of JNDI names at deployment. Then try the code in the lookupRemoteStatelessCalculator in the article

                          • 10. Re: Jboss 7.1 error on new InitialContext();
                            alisissa

                            the file throwing the error is in the war file, and the bean being lookud up is in the jar file.

                            This is my code now:

                             

                            final Hashtable jndiProperties = new Hashtable();

                            jndiProperties.put("java.naming.factory.initial", "org.jboss.as.naming.InitialContextFactory");

                            jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

                            jndiProperties.put("jboss.naming.client.ejb.context", true);

                            final Context context = new InitialContext(jndiProperties);

                            Object ref = context.lookup("ejb:myapp//MYbean!gss.myapp.sessions.MySecurityRemote?stateful");

                            • 11. Re: Jboss 7.1 error on new InitialContext();
                              nickarls

                              I checked out the example at

                               

                              https://github.com/jboss-jdf/jboss-as-quickstart/tree/master/ejb-remote and deployed the jboss-as-ejb-remote-app.jar, resulting in the output

                               

                               

                              14:38:27,598 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named CalculatorBean in deployment unit deployment "jboss-as-ejb-remote-app.jar" are as follows:

                               

                               

                                        java:global/jboss-as-ejb-remote-app/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator

                                        java:app/jboss-as-ejb-remote-app/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator

                                        java:module/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator

                                        java:jboss/exported/jboss-as-ejb-remote-app/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator

                                        java:global/jboss-as-ejb-remote-app/CalculatorBean

                                        java:app/jboss-as-ejb-remote-app/CalculatorBean

                                        java:module/CalculatorBean

                               

                               

                              14:38:27,600 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named CounterBean in deployment unit deployment "jboss-as-ejb-remote-app.jar" are as follows:

                               

                               

                                        java:global/jboss-as-ejb-remote-app/CounterBean!org.jboss.as.quickstarts.ejb.remote.stateful.RemoteCounter

                                        java:app/jboss-as-ejb-remote-app/CounterBean!org.jboss.as.quickstarts.ejb.remote.stateful.RemoteCounter

                                        java:module/CounterBean!org.jboss.as.quickstarts.ejb.remote.stateful.RemoteCounter

                                        java:jboss/exported/jboss-as-ejb-remote-app/CounterBean!org.jboss.as.quickstarts.ejb.remote.stateful.RemoteCounter

                                        java:global/jboss-as-ejb-remote-app/CounterBean

                                        java:app/jboss-as-ejb-remote-app/CounterBean

                                        java:module/CounterBean

                               

                               

                              Then I imported the client into eclipse and run it. The stateless bean is looked up with

                               

                               

                                  private static RemoteCalculator lookupRemoteStatelessCalculator() throws NamingException {

                                      final Hashtable jndiProperties = new Hashtable();

                                      jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

                                      final Context context = new InitialContext(jndiProperties);

                                     return (RemoteCalculator) context.lookup(

                                       "ejb:/jboss-as-ejb-remote-app/CalculatorBean!" + RemoteCalculator.class.getName()

                                    );

                                  }

                               

                               

                              and the stateful with

                               

                               

                                  private static RemoteCounter lookupRemoteStatefulCounter() throws NamingException {

                                      final Hashtable jndiProperties = new Hashtable();

                                      jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

                                      final Context context = new InitialContext(jndiProperties);

                                    return (RemoteCounter) context.lookup(

                                       "ejb:/jboss-as-ejb-remote-app/CounterBean!" + RemoteCounter.class.getName()+"?stateful"

                                    );

                                  }

                               

                               

                              That was from SE -> EJB JAR. Perhaps there is a simpler way from WAR -> EJB JAR but perhaps that's a starting point.

                              • 12. Re: Jboss 7.1 error on new InitialContext();
                                nickarls

                                For a WAR, you might try injecting a

                                 

                                @EJB(lookup = "ejb:/jboss-as-ejb-remote-app/CounterBean!org.jboss.as.quickstarts.ejb.remote.stateful.RemoteCounter?stateful")

                                private RemoteCounter;

                                 

                                I didn't set up my test completely but I think I got a hit on the lookup...

                                • 13. Re: Jboss 7.1 error on new InitialContext();
                                  alisissa

                                  jboss-as-ejb-remote-app should be replaced by myapp (the jar file)?

                                  and this should be left the same org.jboss.as.quickstarts.ejb.remote.stateful?

                                  • 14. Re: Jboss 7.1 error on new InitialContext();
                                    nickarls

                                    "ejb:/myapp/MYbean!gss.myapp.sessions.MySecurityRemote?stateful"

                                     

                                    if MySecurityRemote is the remote interface for MYbean.

                                    I verified the remote EJB injection into a Servlet and saw

                                     

                                    15:07:49,359 INFO  [stdout] (http--0.0.0.0-80-1) Proxy for remote EJB StatefulEJBLocator{appName='', moduleName='jboss-as-ejb-remote-app', distinctName='', beanName='CounterBean', view='interface org.jboss.as.quickstarts.ejb.remote.stateful.RemoteCounter', sessionId='{[-47, -72, -11, -44, 125, 28, 68, 110, -96, 58, -50, 124, 86, 99, -90, 50]}'}

                                    1 2 Previous Next