14 Replies Latest reply on Sep 17, 2007 5:06 AM by andber

    Calling a remote ejb interface in app1.ear from a servlet in

    andber

      As topic says, I want to call a session bean which is deployed in an ejb-jar inside app1.ear, I am calling it from a servlet which is deployed in a war-file inside app2.ear.

      Since I have problems with dom4j/jaxen classloading colliding with the jboss jars I have isolated both ear classloading by using this in jboss-app.xml for both app1 and app2:

      <loader-repository>
      appname:loader=appname.ear
      <loader-repository-config>
      java2ParentDelegation=false
      </loader-repository-config>

      But with this configuration I can't make it work. :(
      App1.ear works 100% but I can't call it from app2.ear..

      I have tried all kinds of configurations, my main attempt (which I still think should work) is to put the ejb-jar.jar from app1.ear in the root of app2.ear and thereby get it in the classpath of app2.
      But this doesn't work, I check in jmx-console for the loader-repository of app2 and the ejb-jar.jar is not loaded even if it is in the root of app2.ear. This results in a NoClassDefFoundException when trying to call app1 from the servlet in app2.

      There is one way to get the ejb-jar.jar loaded in app2 classloader. That is if I put a reference to the ejb-jar.jar in the Class-Path attribute of the manifest.mf for the war-file in app2.ear.
      Then I can see it in the loader-repository for app2.ear, but now I get a ClassCastException on portableobject.narrow when calling app1 session bean from the servlet in app2.ear/war.

      I guess the classcastexception is related to what is said in this thread: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=66651 which says that I can't put interface classes in web-inf/lib of the war.
      I guess that even if I haven't put the ejb-jar.jar in web-inf/lib (it's in the root of app2.ear) I get this error because it is loaded by the war-classloader which gives the same effect as if I would have put it in web-inf/lib..?

      So, how can I get the ejb-jar.jar loaded in app2.ear without putting a class-path reference in the manifest.mf of the war-file? There is no other ejb or web-module in app2.ear.

      Any other suggestion on how to package these applications on JBoss would be appreciated to. It works without problems on Websphere and Weblogic..

      Would really appreciate some help. :)


      (In this thread I wrote some more about my problem but then I was not really sure about what was happening: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=81466)


        • 1. Re: Calling a remote ejb interface in app1.ear from a servle
          andber

          I am using Jboss 4.0.4 CR2

          • 2. Re: Calling a remote ejb interface in app1.ear from a servle
            andber

            Anyone that understands my question/problem and can give me a hint?

            • 3. Re: Calling a remote ejb interface in app1.ear from a servle
              andber

              Does this mean that no one has two enterprise applications where the webapp of one of the ears is calling the other ears sessionbean??

              As far as I can see Jboss doesn't support this when you use isolated classpaths for the ears (which btw should be used as default..). At least not in a standard j2ee way where you have all related jar-files inside the ears..??

              • 4. Re: Calling a remote ejb interface in app1.ear from a servle
                j2ee_junkie

                Hey gang,

                This version of this thread is a better place to ask this. Please excuse the double post (also on thread http://www.jboss.com/index.html?module=bb&op=viewtopic&t=81466)

                I have this exact problem too. I have two ear's that are isolated with by unique loader-repository elements in thier respective jboss-app.xmls. If a class of ear 1 want's to call a ejb bean of ear 2, I get NoClassDefFoundException. So I created a jar file with ear1's bean interfaces. Put the interfaces jar in ear2 root. Add an appropriate manifest entry. Now I get ClassCastExceptions. Is there a solution to this exact situation?

                thanks for your time, cgriffith

                • 5. Re: Calling a remote ejb interface in app1.ear from a servle
                  j2ee_junkie

                  I think in know the answer so I will post this in case others try to find solution. I'll preface this with the fact that I still have not really found a solution posted anywhere. So this is just a conclusion that I am making based on bits and peices I have put together.

                  If ear1 (at least) is isolated and ear2 wants to call an ejb inside ear1, the interfaces of the ejb that are in ear1 must be made available to both ear1 and ear2 classloaders. This means that either...


                  1 ear1 does not isolate itself

                  2 the interfaces of ejbs in ear1 are put into a jar and placed say in deploy directory to be made accessible to all deployments.


                  I was really looking for something that would allow both ears to remain isolated without making interfaces available to all ears. This is due to my shared environment. However, after spending some time thinking about it. I think option 1 is the way to go. After all, if my ejbs are secured, who cares what other ears can attempt to call them.

                  later, cgriffith

                  • 6. Re: Calling a remote ejb interface in app1.ear from a servle
                    jahlborn

                    you did not specify if you were calling the local or the remote interface of the EJB. That is an important distinction. If you are calling the local interface, you pretty much have to turn off isolation or stick the everything in the same ear (same diff). If you are calling the remote interface, then this can be made to work (we are doing this). the trick is that jboss ships with default settings that optimize local calls to remote interfaces (this actually "violates" the j2ee correctness). while this makes things slightly faster, this makes using isolation impossible in the scenario you describe. In the deploy/ear-deployer.xml, you must have these settings:

                    <attribute name="Isolated">true</attribute>
                    <attribute name="CallByValue">true</attribute>


                    Hope that helps.

                    • 7. Re: Calling a remote ejb interface in app1.ear from a servle
                      jahlborn

                      Oops, guess i missed the fact that you do say it is the "remote" interface in the subject.

                      • 8. Re: Calling a remote ejb interface in app1.ear from a servle
                        j2ee_junkie

                        jahlborn,

                        So where did you put your remote EJB interfaces? As I stated earlier, I think they need to be made external and accessable to both the ears. This would mean say deploying the interfaces in a jar in the deploy directory or puting the interfaces jar in the lib directory. Is this correct?

                        cgriffith

                        • 9. Re: Calling a remote ejb interface in app1.ear from a servle
                          jahlborn

                          well, to reference your previous post, isolation is not a form of security. all it does is allow different versions of the same class to exist in different ears. it does nothing to control "who can call it". to answer your recent question: ear2 should treat ear1 the same as if ear1 was deployed on a separate app server, i.e. ear2 should contain ear1's interfaces. ear1 should be deployed as normal.

                          • 10. Re: Calling a remote ejb interface in app1.ear from a servle
                            j2ee_junkie

                            I appreciate you taking the time to help, but it I do not think you understand what I was asking. I never said isolation is a form of security. The orginal problem is that if ear2 contains ear1's interfaces, and if ear1 is isolated, ear2's call to ejb in ear1 produces an NoClassDefFoundException. This is an obvious exception because ear2 can not load the interface isolated in ear1. So the solution might seem to be, include the interfaces in ear2. However, this produces a ClassCastException. Obviously that is because ear1 loaded the interface with its isolated classloader, and ear2 loaded the interface with its isolated classloader which are not the same. So how does one get around this. My answer is to ensure the interfaces are loaded by a shared classloader(i.e. deploy the interfaces jar or put in the server's lib dir.) I just wanted you to confirm this.

                            cgriffith

                            • 11. Re: Calling a remote ejb interface in app1.ear from a servle
                              jahlborn

                              The security comment was in reference to your comment of May 12.

                              After all, if my ejbs are secured, who cares what other ears can attempt to call them.


                              But that's neither here nor there. As for the ClassCastException, i was referring to that problem with my comments about the ear-deployer.xml settings. We are doing exactly what i described (the remote interfaces exist in both ears on the same box), and it is working just fine.

                              • 12. Re: Calling a remote ejb interface in app1.ear from a servle
                                j2ee_junkie

                                Thank you much for setting me straight. I will look into how you solve this issue.

                                cgriffith

                                • 13. Re: Calling a remote ejb interface in app1.ear from a servle
                                  yogendra_g

                                  Hi,
                                  We also have two ear's and both have session beans.
                                  A session bean from one ear gives remote call to the session bean in second ear. And its working fine.
                                  I have set the isolation true. And yes this is set for allowing the use of multiple versions of the third party jar.

                                  • 14. Re: Calling a remote ejb interface in app1.ear from a servle
                                    andber

                                     

                                    "yogendra_g" wrote:
                                    Hi,
                                    We also have two ear's and both have session beans.
                                    A session bean from one ear gives remote call to the session bean in second ear. And its working fine.
                                    I have set the isolation true. And yes this is set for allowing the use of multiple versions of the third party jar.


                                    In my case I have a servlet in one ear that calls the session bean in the other ear.