7 Replies Latest reply on Feb 29, 2012 10:05 PM by jaikiran pai

    Access EJBs in Jboss 7.1 final failed to obtain remote interface

    jnovotny Newbie

      Hi,

       

      My package structure for blast.ear is

       

      blast.ear

           lib/ (lots of third party libs)

           blob.jar (my ejbs)

           web.war (web app)

       

      When the app starts EJBs report:

       

      15:48:02,996 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-11) JNDI bindings for session bean named AlertManagerBean in deployment unit subdeployment "blob.jar" of deployment "blast.ear" are as follows:

       

          java:global/blast/blob/AlertManagerBean!com.session.web.AlertManagerRemote

          java:app/blob/AlertManagerBean!com.session.web.AlertManagerRemote

          java:module/AlertManagerBean!com.session.web.AlertManagerRemote

       

      The webapp tries to get access doing

       

      Context.lookup("java:global/blast/blob/AlertManagerBean!com.session.web.AlertManagerRemote")

       

      which fails:

      Failed to obtain remote interface to AlertManagerBean via jndi name java:global/blast/blob/AlertManagerBean!com.session.web.AlertManagerRemote

       

      Does web.war need MANIFEST info for access or is there something I am missing?

       

      I also read https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI but don'tunderstand why the context starts with "ejb:" when "java:" is being reported. Either way I couldn't get that working either.

       

      Thanks, Jason

        • 1. Re: Access EJBs in Jboss 7.1 final failed to obtain remote interface
          Ganesh Saithala Newbie

          distinctName is missing?

          Context.lookup("java:global/blast/blob//AlertManagerBean!com.session.web.AlertManagerRemote")

          observe double slash in the middle

          • 2. Re: Access EJBs in Jboss 7.1 final failed to obtain remote interface
            jnovotny Newbie

            Hi,

             

            I tried the double slash as well and it still didn't work.

             

            Jason

            • 3. Re: Access EJBs in Jboss 7.1 final failed to obtain remote interface
              jaikiran pai Master

              Please post the exact code and the entire exception stacktrace. Where are you doing the lookup from? A remote client or some component on the server?

              • 4. Re: Access EJBs in Jboss 7.1 final failed to obtain remote interface
                jnovotny Newbie

                It's a lookup from the a component on the server.

                 

                So I have mamfive.ear file containing mamfive.war and backoffice2.jar

                A webpage java class in my mamfive.war file is trying to get a service instance using my helper Bean class that is part iof the EJB jar file, backoffice2.jar, that does the following,

                 

                In LoginPage.java in mamfive.war

                 

                NewFeatureInterface nfi = Bean.lookup(NewFeatureInterface.class);

                 

                Bean#lookup method in backoffice2.jar:

                 

                private static <T> T lookup(Class<T> interfaceClassl) {

                        Object obj = null;

                        String beanName = null;

                        String jndiName = null;

                        Context context = null;

                        try {

                            String interfaceName = interfaceClass.getSimpleName();

                            beanName = interfaceName.replaceFirst("Interface$", "Bean");

                            String fullyQualifiedInterfaceClassName = interfaceClass.getName();         

                            String remoteInterfaceName = fullyQualifiedInterfaceClassName.replaceFirst("Interface$", "Remote");

                            jndiName = String.format("java:global/mamfive/backoffice2//%s!%s", beanName, remoteInterfaceName);

                            context = getContext();

                            obj = context.lookup(jndiName);

                            if (!interfaceClass.isInstance(obj)) {

                                throw new RuntimeException(String.format("Resource with JNDI name '%s' is not an instance of %s", jndiName, interfaceName));

                            }

                        } catch (NamingException ne) {

                            throw new RuntimeException(String.format("Failed to obtain %s interface to %s via jndi name %s",

                                    local ? "local" : "remote", beanName, jndiName), ne);

                        } finally {

                            if (context != null) {

                                try {

                                    context.close();

                                } catch (NamingException e) {

                                    // what could we ever do with this?!?

                                }

                            }

                        }

                        return interfaceClass.cast(obj);

                }

                 

                public static Context getContext(String host) throws NamingException {

                        Properties properties = new Properties();

                        //properties.put("java.naming.factory.initial", "org.jboss.as.naming.InitialContextFactory"); //for JBoss 7

                        properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

                        //properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

                        properties.put("java.naming.provider.url", host);

                        properties.put("java.naming.factory.url.pkgs", "org.jboss.ejb.client.naming");

                        return new InitialContext(properties);

                    }

                 

                Sure, here is the stacktrace:

                 

                10:34:31,443 ERROR [com.machenergy.web.MamRequestCycleListener] (http--127.0.0.1-8080-1) Could not take any action, as MamSession.get().getUser() returned null

                10:34:31,444 ERROR [org.apache.wicket.DefaultExceptionMapper] (http--127.0.0.1-8080-1) Unexpected error occurred: org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public com.machenergy.web.pages.LoginPage()'. Might be it doesn't exist, may be it is not visible (public).

                    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:196) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:68) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:47) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:103) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.handler.PageProvider.resolvePageInstance(PageProvider.java:264) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.handler.PageProvider.getPageInstance(PageProvider.java:165) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:105) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:224) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:167) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:781) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) [wicket-request-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:218) [wicket-core-1.5.4.jar:1.5.4]

                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.10.Final.jar:]

                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.10.Final.jar:]

                    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.10.Final.jar:]

                    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.10.Final.jar:]

                    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.0.Final.jar:7.1.0.Final]

                    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:154) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]

                    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.10.Final.jar:]

                    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.10.Final.jar:]

                    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.10.Final.jar:]

                    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.10.Final.jar:]

                    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.10.Final.jar:]

                    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.10.Final.jar:]

                    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.10.Final.jar:]

                    at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_29]

                Caused by: java.lang.reflect.InvocationTargetException

                    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [classes.jar:1.6.0_29]

                    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [classes.jar:1.6.0_29]

                    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [classes.jar:1.6.0_29]

                    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [classes.jar:1.6.0_29]

                    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:177) [wicket-core-1.5.4.jar:1.5.4]

                    ... 30 more

                Caused by: java.lang.RuntimeException: Failed to obtain remote interface to NewFeatureBean via jndi name java:global/mamfive/backoffice2//NewFeatureBean!com.machenergy.session.web.NewFeatureRemote

                    at com.machenergy.ejb.Bean.lookup(Bean.java:127) [backoffice2.jar:]

                    at com.machenergy.ejb.Bean.lookup(Bean.java:42) [backoffice2.jar:]

                    at com.machenergy.web.pages.LoginPage.init(LoginPage.java:93) [classes:]

                    at com.machenergy.web.pages.LoginPage.<init>(LoginPage.java:85) [classes:]

                    ... 35 more

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

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

                    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:664) [classes.jar:1.6.0_29]

                    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) [classes.jar:1.6.0_29]

                    at javax.naming.InitialContext.init(InitialContext.java:223) [classes.jar:1.6.0_29]

                    at javax.naming.InitialContext.<init>(InitialContext.java:197) [classes.jar:1.6.0_29]

                    at com.machenergy.ejb.Bean.getContext(Bean.java:30) [backoffice2.jar:]

                    at com.machenergy.ejb.Bean.getContext(Bean.java:20) [backoffice2.jar:]

                    at com.machenergy.ejb.Bean.lookup(Bean.java:121) [backoffice2.jar:]

                    ... 38 more

                • 5. Re: Access EJBs in Jboss 7.1 final failed to obtain remote interface
                  jnovotny Newbie

                  I was trying to use the quickstart examples to see if I could replicate my problem and I did. Using the ejb-in-ear project I modified Greeter.java to not use the @EJB dependency injection and to do the following instead:

                   

                  public void setName(String name) {

                                  message = Bean.lookup(GreeterEJB.class).sayHello(name);

                                  //reeterEJB.sayHello(name);

                          }

                   

                  where Bean.lookup creates a context using

                   

                  jndiName = "java:global/jboss-as-ejb-in-ear/jboss-as-ejb-in-ear.jar/GreeterEJB!org.jboss.as.quickstarts.ear.ejb.GreeterEJB";

                              context = getContext();

                              obj = context.lookup(jndiName);

                   

                  and I get the same error:

                   

                  Caused by: java.lang.RuntimeException: Failed to obtain remote interface to GreeterEJB via jndi name java:global/jboss-as-ejb-in-ear/jboss-as-ejb-in-ear.jar/GreeterEJB!org.jboss.as.quickstarts.ear.ejb.GreeterEJB

                      at org.jboss.as.quickstarts.ear.ejb.Bean.lookup(Bean.java:71) [jboss-as-ejb-in-ear.jar:]

                      at org.jboss.as.quickstarts.ear.ejb.Bean.lookup(Bean.java:40) [jboss-as-ejb-in-ear.jar:]

                      at org.jboss.as.quickstarts.ear.controller.Greeter.setName(Greeter.java:61) [classes:]

                      at org.jboss.as.quickstarts.ear.controller.Greeter$Proxy$_$$_WeldClientProxy.setName(Greeter$Proxy$_$$_WeldClientProxy.java) [classes:]

                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [classes.jar:1.6.0_29]

                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [classes.jar:1.6.0_29]

                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [classes.jar:1.6.0_29]

                      at java.lang.reflect.Method.invoke(Method.java:597) [classes.jar:1.6.0_29]

                      at org.apache.el.parser.AstValue.invoke(AstValue.java:262) [jbossweb-7.0.10.Final.jar:]

                      at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.10.Final.jar:]

                      at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                      at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]

                      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]

                      ... 24 more

                  Caused by: javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.jboss-as-ejb-in-ear.ear.jboss-as-ejb-in-ear.war:main" from Service Module Loader

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

                      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:664) [classes.jar:1.6.0_29]

                      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) [classes.jar:1.6.0_29]

                      at javax.naming.InitialContext.init(InitialContext.java:223) [classes.jar:1.6.0_29]

                      at javax.naming.InitialContext.<init>(InitialContext.java:197) [classes.jar:1.6.0_29]

                      at org.jboss.as.quickstarts.ear.ejb.Bean.getContext(Bean.java:28) [jboss-as-ejb-in-ear.jar:]

                      at org.jboss.as.quickstarts.ear.ejb.Bean.getContext(Bean.java:18) [jboss-as-ejb-in-ear.jar:]

                      at org.jboss.as.quickstarts.ear.ejb.Bean.lookup(Bean.java:65) [jboss-as-ejb-in-ear.jar:]

                      ... 37 more

                   

                  Any ideas?

                   

                  Thanks, Jason

                  • 6. Re: Access EJBs in Jboss 7.1 final failed to obtain remote interface
                    jnovotny Newbie

                    Ok finally got it working!!! Looks like I didn't have the folloowing line which is needed when creating a context:

                     

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

                    • 7. Re: Access EJBs in Jboss 7.1 final failed to obtain remote interface
                      jaikiran pai Master

                      By the way, this looks like an incorrect JNDI name:

                       

                      jndiName = "java:global/jboss-as-ejb-in-ear/jboss-as-ejb-in-ear.jar/GreeterEJB!org.jboss.as.quickstarts.ear.ejb.GreeterEJB";

                      The .jar suffix shouldn't be there unless someone really set the module name to that (via deployment descriptor).