3 Replies Latest reply on Aug 2, 2006 11:03 AM by one_special_user

    RMI-IIOP

    one_special_user Newbie

      Hello,

      I have a stateful SessionBean (EJB 2.x) called "MySession" being accessed via IIOP and having a Property "MySessionID".

      Within it's ejbCreate() it should register itself within the JNDI under "mysessions/" + its "MySessionID", just like "mysessions/mysessionid_123", from where it can be looked up again by a client and invoked (via IIOP).

      The reason for this is a C#-Client (talking IIOP via the "IIOP.Net" - Tool) doing some jobs and a Web-Application acting as "Client" to the C#-Client again by invoking its methods. Therefore all the Communication has to be IIOP.

      Within the ejbCreate() i bind the MySession-Instance to the JNDI via

      Context ctx = new InitialContext();
      Object mysession_ref = this.context.getEJBObject();
      MySessionRemote ms = (MySessionRemote)
       PortableRemoteObject.narrow(
       mysession_ref,
       MySessionRemote.class );
      String jndi = "mysessions/" + mysessionid;
      try {
       ctx.rebind( jndi, ms );
      } catch (NameNotFoundException nnfe) {
       // create subcontext and try rebinding
       ctx.createSubContext( "mysessions" );
       ctx.rebind( jndi, ms );
      }
      



      This works fine, the Instance is bound to JNDI (says the JNDIView-MBean),
      BUT the problem is:
      The MySessionHome is bound to "iiop/MySession", as the DeploymentDescriptor states it should be accessible via JRMP AND IIOP,
      whereas the Instances are bound to mysessions/mysessionid_123", and therefore cannot be looked up via the IIOP-Client.

      How do i tell JBoss to bind them as "iiop/mysessions/mysessionid_123" ?
      I don't want to put the "common iiop-necessary" properties like "corbaloc::hostname:port/JBoss/Naming/root" to the Constructor of the InitialContext (I think this spoils clustering??)


      Please help me, it's my diploma-thesis and I'm running out of time (like every college-student I think ... ), I really appreciate any help ;) !

        • 1. Re: RMI-IIOP
          one_special_user Newbie

          Hm propbably I should rephrase it:

          Binding the current Instance of MySession seems to bind a RMI-Stub to the JNDI: "mypackage.mysession._MySession_Stub"...
          And it's basically bound to "mysessions/mysessionid_123".
          If I state context.rebind( "iiop/mysessions/" + mysessionid, ms ) I cannot look it up by my Java-Client neither via JRMP nor via IIOP ( always get a javax.naming.CommunicationException) ...


          How to obtain an InitialReference not for JRMP but for IIOP, but not using Properties for the constructor?

          • 2. Re: RMI-IIOP
            one_special_user Newbie

            It's me ... again :-)


            Ok, i tried a different approach.
            I've got a SessionBean A and a SessionBean B.
            Have to use IIOP as stated above.

            My ejb-jar.xml looks as follows:

            <?xml version="1.0" encoding="UTF-8"?>
            <ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
             <display-name>MyStuff-ejb</display-name>
            
             <enterprise-beans>
             <session>
             <display-name>B</display-name>
             <ejb-name>B</ejb-name>
             <home>mypkg.BHome</home>
             <remote>mypkg.B</remote>
             <ejb-class>mypkg.BBean</ejb-class>
             <session-type>Stateful</session-type>
             <transaction-type>Container</transaction-type>
             </session>
             <session>
             <display-name>A</display-name>
             <ejb-name>A</ejb-name>
             <home>mypkg.AHome</home>
             <remote>mypkg.A</remote>
             <ejb-class>mypkg.ABean</ejb-class>
             <session-type>Stateless</session-type>
             <transaction-type>Container</transaction-type>
             <ejb-ref>
             <ejb-ref-name>ejb/A</ejb-ref-name>
             <ejb-ref-type>Session</ejb-ref-type>
             <home>mypkg.AHome</home>
             <remote>mypkg.A</remote>
             <ejb-link>A</ejb-link>
             </ejb-ref>
             </session>
             </enterprise-beans>
            
             <assembly-descriptor>
             <container-transaction>
             <method>
             <ejb-name>B</ejb-name>
             <method-name>*</method-name>
             </method>
             <trans-attribute>Required</trans-attribute>
             </container-transaction>
             <container-transaction>
             <method>
             <ejb-name>A</ejb-name>
             <method-name>*</method-name>
             </method>
             <trans-attribute>Required</trans-attribute>
             </container-transaction>
             </assembly-descriptor>
            </ejb-jar>
            


            My jboss.xml looks as follows:
            <?xml version="1.0" encoding="UTF-8"?>
            <jboss>
             <enterprise-beans>
            
             <session>
             <ejb-name>A</ejb-name>
             <jndi-name>mystuff/A</jndi-name>
             <invoker-bindings>
             <invoker>
             <invoker-proxy-binding-name>iiop</invoker-proxy-binding-name>
             </invoker>
             </invoker-bindings>
             </session>
            
             <session>
             <ejb-name>B</ejb-name>
             <jndi-name>mystuff/B</jndi-name>
             <invoker-bindings>
             <invoker>
             <invoker-proxy-binding-name>iiop</invoker-proxy-binding-name>
             </invoker>
             </invoker-bindings>
             </session>
            
             </enterprise-beans>
            </jboss>



            A makes use of B, so i have to look it up in order to invoke.
            In ABean, I've tried to look up B via
            Context ctx = new InitialContext()
            followed by either
            "ctx.lookup("java:comp/env/ejb/VFMSession")" or "ctx.lookup( "mystuff/B" )", but none works.
            How to get a reference to BHome??!

            Should I change my jndi.properties?
            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
            java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
            
            #java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces


            • 3. Re: RMI-IIOP
              one_special_user Newbie

              Ok, the status so far:


              My C#-Client can lookup the SessionBeans and invoke them.
              But I just don't get any Java-Client to retrieve any SessionBean.
              Nevertheless, JNDIView states all EJBs are bound to right JNDI-Names.

              Now I'm already getting a reference at the clientside, but narrowing causes a NullPointerException:

               public static Properties getJBOSSProperties() {
               Properties props = new Properties();
               String factoryName = "org.jnp.interfaces.NamingContextFactory";
               String providerURL = "iiop://localhost:2255";
               String factoryPkgs = "org.jboss.naming:org.jnp.interfaces";
               props.put(Context.INITIAL_CONTEXT_FACTORY, factoryName);
               props.put(Context.PROVIDER_URL, providerURL);
               props.put(Context.URL_PKG_PREFIXES, factoryPkgs);
               return props;
               }
              
              
              ...
              
               Properties props = getJBOSSProperties();
               Context ctx = new InitialContext( props );
               System.out.println( "Got InitialContext!" );
              // some other SessionBeans-Names, but doesn't matter //
               String jndi = "vfmcontroller/VFMController";
               Object obj_ref = ctx.lookup( jndi );
               System.out.println( "Got Reference: " + jndi );
               System.out.println( "Class: " + obj_ref.getClass() );
              
              
              
               VFMControllerHome home = (VFMControllerHome)PortableRemoteObject.narrow( obj_ref, VFMControllerHome.class );
               VFMController controller = home.create();
               System.out.println( "Got VFMController: " + controller.getTime() );


              StackTrace:
              Got InitialContext!
              log4j:WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext).
              log4j:WARN Please initialize the log4j system properly.
              Got Reference: vfmcontroller/VFMController
              Class: class org.omg.stub.javax.ejb._EJBHome_Stub
              Exception in thread "main" java.lang.NullPointerException
               at test.TestKlasse.main(TestKlasse.java:93)



              I've tried all combinations of Properties (INITIAL_CONTEXT_FACTORY, PROVIDER_URL, URL_PKG_PREFIXES) with corresponding values and I think i have included all clientside-necessary JARs (jbossall-client.jar etc).

              WHAT AM I DOING WRONG?

              I've searched the web and found all just the same but no solution works for me.

              Please tell me, which jar's to be included (serverside/clientside) or specific configurations which might cause problems... :-/