1 2 3 Previous Next 35 Replies Latest reply on Feb 7, 2013 11:17 AM by Yves Martin

    invoking an EJB over iiop

    Anders Van Dildo Newbie

      Hi, folks.

      I've tried a couple of other forums with this issue but no traction, so here I am to tickle your brains. :)

      I have a servlet that makes calls to an EJB on another server using iiop. I've been trying for days but I still cannot get it to work. My current issue is that when I access the servlet it gets an initial context and performs a lookup for the EJB which returns this:
      12:23:00,104 ERROR [STDERR] java.lang.ClassCastException
      12:23:00,104 ERROR [STDERR] at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)

      For my INITIAL_CONTEXT_FACTORY I am using:
      org.jboss.iiop.naming.ORBInitialContextFactory

      This is the same class as I am specifying in my server's jndi.properties.

      Here are the steps being taken by the servlet:
      1. create a Properties object
      2. put the initial context factory class name i.e. org.jboss.iiop.naming.ORBInitialContextFactory
      3. put URL of the server where the EJB lives i.e. iiop:/server:3528
      4. create a new InitialContext using the above Properties object.
      5. once I have the InitialContext, I perform a lookup using the EJB name i.e. "iiop://my.EJBHome"
      6. I added a debug statement to the code and note that the Object returned by the lookup is : com.sun.jndi.cosnaming.CNCtx

      My understanding is that the EJB JAR doesn't need any stubs, etc. they are supposed to be created on at runtime. So I must be doing something wrong but I dont' know what. I also understand that JBoss iiop is supposed to be enabled when you use the all configuration which is what I am using. I don't know of any additional configuration changes that need to be made, if any. This type of work is new to me, I don't have experience with EJBs on any other application server platform to fall back on. Can anyone suggest any know traps that a newbie might fall into? My clientside WAR file does not contain the EJB classes, just the interfaces (I found that problem in another thread). I can't find a lab or tutorial for this on JBoss 4.2 GA so I have no reference. I can't find an answer on google and the books I have (O'Reilly and JBoss admin guide) don't discuss this topic.

      peace, Anders

        • 1. Re: invoking an EJB over iiop
          jaikiran pai Master

          How are you application(s) packaged? Are the EJB jar and the war file, two separate applications or are they part of an ear file?

          Also, do have a look at this wiki page (if you havent already seen that ) http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassCastExceptions


          Additionally, in your code try using some debug statements like:

          // lookup you ejb
          Object obj = ctx.lookup(".....");
          // i guess this is going to output Proxy$ or something similar
          System.out.println("Returned obj is of class: " + obj.getClass());
          
          // now lets see whether we can narrow that object
          if (obj instanceof MyHome ) {
          //where MyHome is the class name of the bean's home
           System.out.println("Everything looks fine. Lets do the PortableRemoteObject.narrow");
           MyHome home = (MyHome) PortableRemoteObject.narrow(obj,MyHome.class);
           System.out.println("Success");
           } else {
           System.out.println("Most probably a classloader issue");
           System.out.println("Object returned was loaded by: " + obj.getClass().getClassLoader());
           System.out.println("MyHome class in the servlet was loaded by: " + MyHome.class.getClassLoader());
           }
          
          
          
          


          P.S.: I havent tried this code, you might have to do any changes that are required. But it might just give you some options to try out.

          • 2. Re: invoking an EJB over iiop
            jaikiran pai Master

             

            I added a debug statement to the code and note that the Object returned by the lookup is : com.sun.jndi.cosnaming.CNCtx


            This doesnt look right to me. Are you using the right jndi name to lookup your bean? Can you post the code?

            • 3. Re: invoking an EJB over iiop
              Anders Van Dildo Newbie

              Thanks for your reply, jaikiran!

              The servlet is packaged in a WAR file and is deployed on server1.

              The EJB is packaged in a JAR file and is deployed on server2.

              The jndi-name in jboss.xml and ejb-jar.xml is set to interop.InteropHome. Here's jboss.xml:

              <?xml version="1.0" encoding="UTF-8"?>
              <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_2.dtd">
              <jboss>
               <enterprise-beans>
               <session>
               <ejb-name>interop.InteropBean</ejb-name>
               <invoker-bindings>
               <invoker>
               <invoker-proxy-binding-name>iiop</invoker-proxy-binding-name>
               </invoker>
               <jndi-name>interop.InteropHome</jndi-name>
               </invoker-bindings>
               </session>
               </enterprise-beans>
              </jboss>


              My ejb-jar.xml contains the exact same jndi-name.

              Here's how I create the initial context:
              Properties h = new Properties();
               String ctx = "";
               ctx = "org.jboss.iiop.naming.ORBInitialContextFactory";
               h.put( Context.INITIAL_CONTEXT_FACTORY, ctx );
               h.put( Context.PROVIDER_URL, url );
               InitialContext initCtx = new InitialContext(h);
               return initCtx;


              The URL I am using is:
              iiop://server2:3528


              Finally, here's the EJB lookup:
              Object foo = getInitialContext(url, user, password).lookup(ejbHomeName);
               Object bar = PortableRemoteObject.narrow( foo, InteropHome.class );
               home = (InteropHome) bar;
              


              In my source code I use this for the EJB name:
              iiop://interop.InteropHome


              user and password are null in this case. When I run this code and display the class name of the object in foo, I get :
              com.sun.jndi.cosnaming.CNCtx


              • 4. Re: invoking an EJB over iiop
                Anders Van Dildo Newbie

                When I change the EJB Home name in the source code i.e.

                FROM : iiop://interop.InteropHome
                TO : interop.InteropHome

                I get this message when I try and call the bean:

                javax.naming.NameNotFoundException: interop.InteropHome


                I don't know if that gives you any more info?

                Peace, Anders

                • 5. Re: invoking an EJB over iiop
                  Anders Van Dildo Newbie

                  I added the classloader System.outs specified above and I get this output when trying to access the EJB:

                  11:46:07,954 INFO [STDOUT] Object returned was loaded by: org.jboss.mx.loading.UnifiedClassLoader3@115875d{ url=null ,addedOrder=2}
                  11:46:07,954 INFO [STDOUT] MyHome class in the servlet was loaded by: WebappClassLoader
                   delegate: false
                   repositories:
                   /WEB-INF/classes/
                  ----------> Parent Classloader:
                  java.net.FactoryURLClassLoader@41254ec
                  


                  I get this result when I perform the EJB lookup using this:
                  iiop://server1:3528/interop.InteropHome


                  when I was simply using
                  iiop://interop.InteropHome
                  I was getting a message like this:
                  11:26:12,021 WARN [address] init_host, interop.InteropHome unresolvable


                  when I googled that message, minus the interop.InteropHome text, I found a link to some jacorb source code and found that for interop.InteropHome to appear in the warning message, the code thinks that I am specifying a URL and it's trying to determine the host addr. That led me to believe that the lookup for the EJB required me to add server and host information. I don't know if that's true but when I added it I got a different error. This time I got a NullPointerException in my servlet but there is no line information telling me where the error is. However, because of other debug statements in my code I can tell that it is the following statement:
                  Object bar = PortableRemoteObject.narrow( foo, InteropHome.class );


                  foo isn't null so I don't know why that exception is being thrown, it must be something deeper.

                  • 6. Re: invoking an EJB over iiop
                    Anders Van Dildo Newbie

                    Actually the NullPointerException is being caused by this line of code which appears immediately after the call to PortableRemoteObject.narrow:

                    System.out.println("Class bar is : " + bar.getClass().getName());


                    I guess that means the call to narrow is failing.

                    • 7. Re: invoking an EJB over iiop
                      Anders Van Dildo Newbie

                      when I change the ejb lookup name to iiop/interop.InteropHome, I get class

                      org.omg.stub.javax.ejb._EJBHome_Stub
                      returned by the lookup. That looks a little more promising.

                      • 8. Re: invoking an EJB over iiop
                        Anders Van Dildo Newbie

                        The latest errors I am seeing are:

                        13:47:38,057 ERROR [orb] no adapter activator exists for EJBHome&%interop.InteropHome
                        13:47:38,067 INFO [STDOUT] Class home is : class org.omg.stub.javax.ejb._EJBHome_Stub
                        


                        I googled the no adapter activator message and found some evidence (a post on a mailing list) to suggest that it's not really a problem.

                        • 9. Re: invoking an EJB over iiop
                          Anders Van Dildo Newbie

                          I just wanted to add the following stdout from my backend server to show that the EJB is being deployed as expected.

                          15:22:42,381 INFO [EjbModule] Deploying interop.InteropBean
                          15:22:42,880 INFO [InteropBean] EJBHome reference for interop.InteropHome:
                          IOR:0000000000000041524D493A7765626C6F6769632E71612E74657374732E656A6232302E696E7465726F702E496E7465726F70486F6D653A30303030303030303030303030303030000000000000000200000000000000D4000102000000000F3137322E31382E3133362E31323800000DC80000000000284A426F73732F454A42486F6D652625696E7465726F702E496E7465726F70486F6D652FACED000570000000050000000000000008000000004A414300000000010000001C000000000001000100000001050100010001010900000001050100010000001900000034000000000000002C687474703A2F2F7261703A383038332F576562434C5B696E7465726F702E496E7465726F704265616E5D2F000000002000000004000000000000001F0000000400000003000000010000005C00000000000000030000001900000034000000000000002C687474703A2F2F7261703A383038332F576562434C5B696E7465726F702E496E7465726F704265616E5D2F000000002000000004000000000000001F0000000400000003
                          15:22:42,881 INFO [InteropBean] Home IOR for interop.InteropBean bound to iiop/interop.InteropHome in JNP naming service
                          15:22:42,883 INFO [InteropBean] Home IOR for interop.InteropBean bound to interop.InteropHome in CORBA naming service


                          • 10. Re: invoking an EJB over iiop
                            jaikiran pai Master

                             

                            15:22:42,881 INFO [InteropBean] Home IOR for interop.InteropBean bound to iiop/interop.InteropHome
                            in JNP naming service
                            15:22:42,883 INFO [InteropBean] Home IOR for interop.InteropBean bound to interop.InteropHome in CO
                            RBA naming service


                            You seem to have made good progress :) Where's it that you are currently stuck at? I havent tried IIOP before so not sure what the exact issue might be. Could you do the following on the server2 where your bean is deployed:

                            - Go to http://localhost:8080/jmx-console
                            - Search for service=JNDIView
                            - Click on that link
                            - On the page that comes up, click on the Invoke button beside the list() method
                            - The page that comes up will show the contents of the JNDI tree. This will show you the jndi names and the objects that are bound to those names.
                            - Post the output


                            • 11. Re: invoking an EJB over iiop
                              Anders Van Dildo Newbie

                              That generates a lot of output so here is the EJB-related stuff. Let me know if you would like to see the rest:

                              Ejb Module: InteropBean.jar
                              
                              java:comp namespace of the interop.InteropBean bean:
                              
                               +- HandleDelegate (class: org.jboss.proxy.ejb.handle.HandleDelegateImpl)
                               +- UserTransaction (class: javax.transaction.UserTransaction)
                               +- ORB (class: org.jacorb.orb.ORB)
                               +- env (class: org.jnp.interfaces.NamingContext)


                              There's also a reference to my EJB in the Global JNDI Namespace:
                              Global JNDI Namespace
                              
                               +- iiop (class: org.jnp.interfaces.NamingContext)
                               | +- interop.InteropHome (class: javax.ejb.EJBHome)


                              • 12. Re: invoking an EJB over iiop
                                Anders Van Dildo Newbie

                                To answer your question, "where am I stuck at?", well, that varies as I try different things. I seem to be able to startup both the front end and back end servers without any issues but when the front end servlet tries to lookup the EJB, I get the errors. The errors change depending on what settings I am currently using.

                                It's a shame you haven't used IIOP before because what I think would really help me is a concrete example of a servlet communicating with an EJB over iiop. I haven't been able to find one though. I think if I had a working example I could figure out where I am going wrong. I think that my problem lies with one or more of these:
                                1. my jndi.properties,
                                2. my jacorb.properties,
                                3. my InitialContext as defined in my servlet,
                                4. my EJB lookup in the servlet.

                                Everything I have read discusses how JBoss doesn't need stubs and skeletons making the deployment easier. I agree that skipping a compilation step does make the process easier but I still think there needs to be something explaining the required configuration.

                                Peace, Anders

                                • 13. Re: invoking an EJB over iiop
                                  jaikiran pai Master

                                  The JNDI view looks good to me. You might have already seen this http://labs.jboss.com/jbossiiop/. If not, then see if you can get hold of the testcases that are mentioned there. They also mention

                                  If you are using JDK 1.4 or newer, your client-side jndi.properties file should look like this:

                                  java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
                                  java.naming.provider.url=corbaloc::server.host.name:3528/JBoss/Naming/root


                                  You might want to try passing
                                  h.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");


                                  Sorry, i am not being of much help - havent tried my hands at this stuff earlier

                                  • 14. Re: invoking an EJB over iiop
                                    Anders Van Dildo Newbie

                                    Thanks, jaikiran.

                                    I had found that lab and noted that it deals with JBoss 3.2. I am downloading the source for 4.2GA to see if similar test cases still exist. I don't believe there is a similar lab for 4.2 (at least I cannot find it).

                                    I tried the recommended jndi.properties settings but that just gave me errors when I started up JBoss.

                                    As a last gasp I have contacted one of the people mentioned in that lab directly. I don't know if that is the correct thing to do but google has dried up. :)

                                    Peace, Anders

                                    1 2 3 Previous Next