6 Replies Latest reply on Jan 14, 2003 7:34 AM by dummyjim

    Could you give me an example which a java client access EJB

    dcming

      Could you give me an example which a java client access EJB by RMI/IIOP!
      Thank you very much!

        • 1. Re: Could you give me an example which a java client access
          dummyjim

          Hi!

          It's not complete example (no imports and so on).
          Ah and don't forget to change jboss.xml for IIOP

          public class SCTest
          {
          private final static String factory = "com.sun.jndi.cosnaming.CNCtxFactory";
          private final static String provider = "IOR:"; // JBoss ns IOR

          public SCTest()
          {
          Properties env = new Properties();

          env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
          env.put(Context.PROVIDER_URL, provider);

          try
          {
          InitialContext ctx = new InitialContext(env);

          m.getMunicipioList();

          java.lang.Object obj = ctx.lookup("MyEJB");
          MyEJBHome home = (MyEJBHome)PortableRemoteObject.narrow(obj, MyEJBHome.class);

          MyEJB my = (MyEJB)home.create();

          my.hello();
          }
          catch (Exception ex) {System.out.println(ex);}

          }
          public static void main(String[] args)
          {
          new SCTest();
          }
          }

          Cheers,

          Hem...

          • 2. Re: Could you give me an example which a java client access
            dcming

            Thank you Jim,but when I run my test program like yours it throw exception

            Corba name:org.jacorb.orb.ORB
            java.lang.ClassCastException
            at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
            at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
            at newejb.Enterprise1TestClient1.(Enterprise1TestClient1.java:50)
            at newejb.Enterprise1TestClient1.main(Enterprise1TestClient1.java:192)-- Failed initializing bean access.

            I find the object which I get from "ctx.lookup" is a "_EJBHome_stub" it cann't be casted to MyEJBHome .

            I feel very worry about it,please help me!

            • 3. Re: Could you give me an example which a java client access
              dcming

              Thank you Jim,but when I run my test program like yours it throw exception

              Corba name:org.jacorb.orb.ORB
              java.lang.ClassCastException
              at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
              at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
              at newejb.Enterprise1TestClient1.(Enterprise1TestClient1.java:50)
              at newejb.Enterprise1TestClient1.main(Enterprise1TestClient1.java:192)-- Failed initializing bean access.

              I find the object which I get from "ctx.lookup" is a "_EJBHome_stub" it cann't be casted to MyEJBHome .

              I feel very worry about it,please help me!

              • 4. Re: Could you give me an example which a java client access
                dcming

                Thank you Jim,but when I run my test program like yours it throw exception

                Corba name:org.jacorb.orb.ORB
                java.lang.ClassCastException
                at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
                at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
                at newejb.Enterprise1TestClient1.(Enterprise1TestClient1.java:50)
                at newejb.Enterprise1TestClient1.main(Enterprise1TestClient1.java:192)-- Failed initializing bean access.

                I find the object which I get from "ctx.lookup" is a "_EJBHome_stub" it cann't be casted to MyEJBHome .

                I feel very worry about it,please help me!

                • 5. Re: Could you give me an example which a java client access
                  dummyjim

                  Hola!

                  Something wrong with the forum...

                  Well, I think you just forgot to include your RMI/IIOP stubs into the classpath (compile your interfaces with rmic -iiop). Regarding the '_EJBHome_stub' - it's OK you need to narrow it to get a 'home' object.

                  cheers,

                  dummy

                  • 6. Re: Could you give me an example which a java client access
                    dummyjim

                    Hi!

                    It is no so simple... I think the problem exists, but have no idea where... :-(

                    take a look:

                    http://www.mail-archive.com/jboss-user@lists.sourceforge.net/msg19004.html//www.mail-archive.com/jboss-user@lists.sourceforge.net/msg19004.html

                    Cheers,

                    dum.