3 Replies Latest reply on Jan 1, 2002 1:25 PM by Kevin Tew

    how call EJB from servlet ?

    andang Newbie

      I tried call EJBean in JBoss from servlet in other machine. but failed.

      is possable call ejbean from servlet on other machine.

      i use Interest example from jboss site.
      servlet code some like this.



      Properties env = new Properties();
      env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.setProperty(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
      env.setProperty(Context.PROVIDER_URL, "openmind.ncq.co.kr:1099");

      Object ref = new InitialContext(env).lookup("jnp://openmind.ncq.co.kr:1099/interest/Interest");

      out.println( ref.getClass().getName() ) ;


      output was $Proxy. but i excepted InterestHome.



        • 1. Re: how call EJB from servlet ?
          Daniel Georges Newbie

          Hi1

          Type http://localhost:8082 in your browser.
          You can see the name under Jndi.
          The example dont't worked until I changed to
          lookup("interest/Interest")

          • 2. Re: how call EJB from servlet ?
            Dennis Chen Newbie

            > Hi1
            >
            > Type http://localhost:8082 in your browser.
            > You can see the name under Jndi.
            > The example dont't worked until I changed to
            > lookup("interest/Interest")

            how call EJB in JBOSS-2.4.1 from servlet in tomcat-4.0 ?
            1) I deploy a session ejb named "Login" in jboss, and I can found it when I type http://localhost:8082 in my browser.

            2) I copy jboss-client.jar, jboss-j2ee.jar, jnp-client.jar and my ejb jar file to tomcat-home/webapps/myapp/WEB-INF/lib.

            3) I write following lines in deployment descriptor file web.xml:
            <ejb-ref>
            This is demo ejb
            <ejb-ref-name>Login</ejb-ref-name>
            <ejb-ref-type>Session</ejb-ref-type>
            com.netup.demo.ejb.session.loginsrv.LoginHome
            com.netup.demo.ejb.session.loginsrv.LoginRemote
            </ejb-ref>

            4) In my servlet class, I call ejb like this:

            Properties env = new Properties();
            env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            env.setProperty(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
            env.setProperty(Context.PROVIDER_URL, "localhost:1099");

            try {
            Object ref = new InitialContext(env).lookup("Login");
            LoginHome home = (LoginHome) PortableRemoteObject.narrow(ref, LoginHome.class);
            out.println( "LoginHome is found: " + home.getClass().getName() ) ;
            LoginRemote bean = home.create();
            if (bean.checkUser(userId, pw))
            {
            out.println( "The user is valid" ) ;
            }
            else
            {
            out.println( "The user is invalid, the valid user is admin, password is dennis" ) ;
            }
            } catch (Exception e){
            out.println( "The EJB not FOUND: " + e.getMessage()) ;
            }

            5) When I request from servlet, my browser show following error message:

            LoginHome is found: $Proxy0


            A Servlet Exception Has Occurred
            Exception Report:
            javax.servlet.ServletException: Servlet execution threw an exception
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2366)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1005)
            at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1098)
            at java.lang.Thread.run(Thread.java:484)

            Root Cause:
            java.lang.NoClassDefFoundError: org/jboss/security/SecurityAssociation
            at org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.getPrincipal(GenericProxy.java:231)
            at org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.createMarshalledObject(GenericProxy.java:393)
            at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invokeHome(HomeProxy.java:244)
            at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java:182)
            at $Proxy0.create(Unknown Source)
            at com.netup.q2w.eaf.servlet.Login.doPost(Login.java:99)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:1145)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:1264)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2366)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1005)
            at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1098)
            at java.lang.Thread.run(Thread.java:484)

            6) anybody can tell me why goes to error even the home object is found?

            • 3. Re: how call EJB from servlet ?
              Kevin Tew Newbie


              java.lang.NoClassDefFoundError: org/jboss/security/SecurityAssociation

              need to put JBOSS_ROOT/client/jbosssx-client.jar in your WEB-INF/lib dir