2 Replies Latest reply on Mar 8, 2002 12:45 AM by jian gao

    client lookups

    garyg Novice

      I'm trying to call an entity bean from a client.

      From the JBoss docs, chpt. 7 ...
      "JBoss does not currently allow you to use the java:comp/env namespace to call your beans from your clients."

      So does that mean I can't use the following line from within my client, which currently runs on the same machine but will be running on different machines.

      Object result = ctx.lookup "java:comp/env/ejb/MyBean");

      This is currently how it's defined in ejb-jar.xml, and I'm trying to figure out what to write in jboss.xml.
      ---

      <ejb-name>MyBean</ejb-name>
      com.neuroquest.cais.ejb.entity.MyBeanHome
      com.neuroquest.cais.ejb.entity.MyBean
      <ejb-class>com.neuroquest.cais.ejb.entity.MyBeanBean</ejb-class>
      <resource-ref>
      <res-ref-name>jdbc/PostgresqlDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      <persistence-type>Bean</persistence-type>
      <prim-key-class>com.neuroquest.cais.ejb.entity.MyBeanPK</prim-key-class>
      False


      Any help much appreciated!

        • 1. Re: client lookups
          garyg Novice

          I'm currently getting errors like this:

          [AutoDeployer] org.jboss.deployment.J2eeDeploymentException: Error while starting acais-1.0.ear: Could not deploy file:/u/public/JBoss-2.4.0_Tomcat-3.2.3/jboss/tmp/deploy/Default/acais-1.0.ear, Cause: org.jboss.ejb.DeploymentException: Could not deploy file:/u/public/JBoss-2.4.0_Tomcat-3.2.3/jboss/tmp/deploy/Default/acais-1.0.ear, Cause:org.jboss.ejb.DeploymentException: Error in jboss.xml for Bean MyBean: ejb-ref MyBean found in jboss.xml but not in ejb-jar.xml

          And do I maybe have to add anything to application.xml?

          • 2. Re: client lookups
            jian gao Newbie

            About calling EJB in another JVM
            I tried , it might not what you want, but i really succeeded.
            The code:

            import javax.servlet.*;
            import javax.servlet.http.*;
            import java.io.*;
            import java.util.*;
            import javax.naming.*;
            import javax.rmi.PortableRemoteObject;
            import org.jnp.interfaces.NamingContextFactory;
            import org.jnp.interfaces.*;
            import quay.myquayHome;
            import quay.myquay;
            import quay.myquayBean;

            public class EJBClientTest extends HttpServlet {
            private static final String CONTENT_TYPE = "text/html; charset=GBK";

            public void init() throws ServletException {
            }


            public void doGet(HttpServletRequest request, HttpServletResponse

            response) throws ServletException, IOException {
            response.setContentType(CONTENT_TYPE);
            PrintWriter out = response.getWriter();
            out.println("");
            out.println("Remote EJB Test Panel");
            out.println("");
            out.println("<h1>Remote EJB Test Page.</h1>");

            /////////////////////////////
            try{

            System.out.println("Before myEJBWork");
            String tmpRst=myEJBWork();
            System.out.println("After myEJBWork");
            out.println(tmpRst);
            }catch(Exception e){
            out.print("Error when accessing EJB");
            }
            /////////////////////////////

            out.println("");
            }

            public void doPost(HttpServletRequest request, HttpServletResponse

            response) throws ServletException, IOException {
            doGet(request,response);
            }

            private String myEJBWork() throws Exception{
            try {
            myquay tmpbean = findMyBeanHome().create();
            return tmpbean.say();
            }catch(NamingException e){
            return "Error in myEJBWork";
            }
            }

            private myquayHome findMyBeanHome()
            throws NamingException {
            Context context = getInitialContext();
            Object object = context.lookup("quay/myquay");
            context.close();
            return (myquayHome)PortableRemoteObject.narrow(object,

            myquayHome.class);
            }

            public Context getInitialContext()
            throws NamingException {

            Properties env = new Properties();
            env.setProperty(Context.INITIAL_CONTEXT_FACTORY,

            getInitialContextFactoryClassName());
            env.setProperty(Context.URL_PKG_PREFIXES,

            getURLPackageInterface());
            env.setProperty(Context.PROVIDER_URL, getNameServerURL());

            InitialContext jndiContext = new InitialContext(env);
            return jndiContext;
            }

            private String getInitialContextFactoryClassName(){
            return "org.jnp.interfaces.NamingContextFactory";
            }

            private String getURLPackageInterface(){
            return "org.jnp.interfaces";
            }

            private String getNameServerURL(){
            return "localhost:1099";
            }