1 2 Previous Next 16 Replies Latest reply on Feb 9, 2017 3:39 AM by mrudulav

    Remote EJB not working from WAR to EAR

    davidj

      Hi,

      I've got two JBoss AS 7.1.1Final servers.

       

      One has a WAR file.

      The second has an EAR file.

       

      My goal is to have the WAR file use remote EJBs in the EAR file.  Setup is as follows.

       

      I have a JAR file containing the @Remote interfaces. It is called "remote.jar".

      ! have a JAR file containing the @Entity JPA entity class.  It is called "model.jar".

       

      The WAR file contains both remote.jar and model.jar.

       

      The EAR file also contains both remote.jar and model.jar.  The EAR file also contains another JAR file called "domain.jar" which contains the @Stateless EJBs which implement the @Remote interfaces.  My "persistence.xml" is also contained within "domain.jar".

       

      If I deploy both the WAR file and EAR file to the same machine, everything works.  It I deploy the EAR file to another machine, then it doesn't work.

       

      I have tried two different methods: 1) Remote-JNDI lookup, and 2) JBoss EJB-remote client lookup.

      I've taken instruction from the following JBoss websites:

      https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project


      https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance
       
      https://community.jboss.org/thread/19710

       

      I've followed these instructions as closely and exactly as possible.  I've even stripped-down my JAR files to be as simple as possible (one Entity, one Remote, one EJB, etc.).

       

      As a side note; my setup works with Glassfish 3.1.2 (minus all of the JBoss configuration stuff, of course, such as jboss-ejb-client.properties, and JBoss JNDI stuff, etc.).

       

      Also as a side note: The instructions given in the second URL link above (EJB+invocations+from+a+remote+server+instance) I really, really hope is not truly what JBoss developed for EJBs.  These instructions seem like a hack (no offense); having to edit all those xml files etc.  Plus, it doesn't allow for easily swapping if you have multiple remote EJBs running on different boxes.

       

      Any advice would be appreciated.

      Thanks.

       

      PS The error message I get depends upon which method I'm attempting.  If I'm using the Remote JNDI lookup method, I get a message javax.naming.NameNotFoundException.  If I use the JBoss EJB-remote client method I get: "No EJB receiver available for handling [appName:" message.

       

      I'm using the latest and greatest versions of Java EE 6.  Including: JSF 2.x, JPA 2, EJB 3.x

        • 1. Re: Remote EJB not working from WAR to EAR
          wdfink

          I'm not sure that I understand your environment.

           

          I would start with a simple war that calls the remote EJB.

          Also I recommend to not use remote-naming-project.

           

          Have a look to this quickstart, you may clone it and follow the README, it's mostly autoconfigure a new JBoss instance.

           

          This might give you an example that you can adjust to your requirements.

          • 2. Re: Remote EJB not working from WAR to EAR
            davidj

            Hi Wolf-Dieter Fink,

             

            I've created a simple picture which will hopefully clarify the situation.

            I'm not doing anything fancy: I simply have one WAR file located on "Server A" which trys to communicate with a Remote EJB on "Sever B" (the EJB is inside an EAR file).  That's it.  The EJB will talk to a database and retreive information.

             

            overview.jpg

            • 3. Re: Remote EJB not working from WAR to EAR
              davidj

              I've made a little bit of progress on this topic.  I downloaded the "JBoss Quickstart" collection and used the "ejb-remote" example.  I put my  code into this project and pointed the jboss-ejb-client.properties file to point to "Server B" (as shown above), and it worked!  This tells me that: command-line java to remote JBoss server works, but JBoss Server to JBoss server doesn't work.  The question is: why?

               

              If command-line java (running on Server A as shown above) can successfully connect to my remote EJB server (Server B as shown above), but the JBoss Server (also running on "Server A" as shown above) cannot, then this tells me something has to be configured on the client JBoss server.  The question is: what?

               

              I know that the instruction guide found at: https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance gave some configuration instructions, maybe I'll go re-examine those again...... I'll go do that now, meanwhile if any of you have any thoughts about this new piece of information please let me know.

               

              Thanks.

              • 4. Re: Remote EJB not working from WAR to EAR
                wdfink

                Indeed, server-to-server calls are different.

                 

                An example for your doc-link can be found in this quickstart

                • 5. Re: Remote EJB not working from WAR to EAR
                  davidj

                  JBoss AS 7 (version 7.1.1.Final) doesn't not seem to function properly as a client referencing a remote EJB on another JBoss AS 7 server.  We have followed the instructions given in the above links.  In-fact, we had a second engineer on our team attempt to following the same instructions and couldn't get it to work either.  We have banged-our-heads against the wall too long.  Finally, one engineer had a bright idea:  Let's take the same WAR file and deploy it on a Glassfish Server (version 3.1.2).  So in my drawing up above, imagine that Server A, is now a Glassfish Server instead of JBoss AS 7 server.  It worked!  No code changes required.  The exact same WAR file which didn't work on JBoss, now is working on Glassfish.

                   

                  So the next idea was to deploy the same WAR file on a Tomcat 7 server.  It worked!

                   

                  So let's examine the score:  A WAR file which uses JBoss JAR files and was setup according to instructions given by JBoss, does not work on JBoss.  But yet it will work on two of it's competitors: Glassfish & Tomcat. ?  !   .....

                   

                  We are now in the process of getting permission from our corporate headquarters to use Tomcat as the front-end server.  We have no choice for the back-end server: we must use JBoss.  Our back-end servers are located behind a wirewall (in a different city). This is why we are using Remote EJBs. Corporate Headquarters wants us to use JBoss as the front-end server, but now we can go back to them and say:  "Hey look, we cannot get JBoss to function properly as a client to remote EJBs, but we can get it to work on Tomcat/Glassfish".

                   

                  This is very disappointing (I'm looking at you JBoss).

                   

                  By the way, in an effort to get this to work on JBoss, we stripped-down our project to a "Hello World" Remote EJB.  So in my drawing up-above, forget about "model.jar", forget about JPA Entites, forget about persistence.xml, forget about the structure of my EAR file, etc., etc.,  We stripped this down to as simple of a project as you can get, and JBoss still could not successfully call the Remote EJB.

                   

                  And as long as I'm complaining, let me quickly rant about the instructions given here: https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance

                  I appreciate the authors's time and energy, but as an engineer, this method is the most awkward I've seen to configure a remote ejb since the early 2000s back in the EJB 1.x days. It offers zero flexibility.

                   

                  PS  JBoss has a "quickstart" quide online where you can download sample projects.  We downloaded it, and used the "ejb-remote".  In-fact we copyed the pom.xml to ensure that we were using the correct dependencies.  You can try this yourself: download the quickstart and run the "ejb-remote" project.  You will find that it is successful.  The reason it is successful, is because you are running the client from the command-line (not from a JBoss AS 7 server).  As soon as you "WAR-ify" this project (turn it into a WAR file by adding web.xml and something like JSF etc) and run it on a JBoss server, it fails.

                  • 6. Re: Remote EJB not working from WAR to EAR
                    wdfink

                    David, do you try the quickstart ejb-multi-server [1]? This is the example how to configure and use jboss-AS7 as a client of JBoss-AS7.

                     

                    https://github.com/wfink/quickstart/tree/ejb-multi-server

                    • 7. Re: Remote EJB not working from WAR to EAR

                      I get the same exception (invoking remotly a method) even when running the client from a stand alone java application (execute from eclipse if it makes a difference).

                       

                      Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:flight.likegood.ear.ear,modulename:flight.likegood.com.ejb.jar,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@ac20151

                       

                      Lookup succeed , therefore (i guess) "jboss-ejb-client.properties is not in your CLASS_PATH" does not explain , i am seting the context properties within the client code.

                       

                      but unfortunatly when invoking a remote method i get the exception above ....

                       

                      I have tried everything is out there  ... any thing more?

                      • 8. Re: Remote EJB not working from WAR to EAR
                        max.charas

                        Hello all!

                        I just want to ping this post and say that I am facing the same problems as David.

                         

                        We've spent 6 man days (two parallel developers) trying to get a simple scenario working.

                         

                        Case 1 (That works)

                        • Server A: Hello world EJB. (Running on Jboss as 7)
                        • Server B: Jsp web application calling the EJB in Server A and printing the call in the JSP page. (Housed in Jetty)

                         

                         

                        Case 2 (That fails)

                        • Server A: Hello world EJB. (Running on Jboss as 7)
                        • Server C: Jsp web application calling the EJB in Server A and printing the call in the JSP page. (Housed in Jboss as 7)

                         

                        (Note that both cases uses separate JVM's)

                         

                        What really frustrates us is that Case 1 and Case 2 are running exactly the same code base yet one works and the other does not.

                         

                        We first thought that this might have been a configuration issue but as one case works and the other does not we've abandoned that idea.

                         

                        What we are leaning towards now is that this might be a class loading issue.

                         

                        We aren't really sure what dependencies to provide in Case 2. We've experimented with both suppling the entire  Jboss-Client Jar and trying to use the modular system in Jboss enabling modules via the Manifest.

                         

                        Anyway to end my rant.

                        We would greatly appreciate if someone in the Jboss as 7 Dev crew could set up an extremely easy hello world example as described in Case 2. I think lots of people will face this problem.

                         

                        (And to be frank I'm not sure if its a technical problem or a just a question about the documentation being a bit tricky in this case.)

                         

                        Best regards,

                        Max

                        • 9. Re: Remote EJB not working from WAR to EAR
                          wdfink

                          The concept of the ejb-client is different to former version.

                          The lookup is a local action and does not call the server side, so you will see the invocation failure only if you access the remote-method.

                           

                          If you still have problems you should open a new thread.

                          • 10. Re: Remote EJB not working from WAR to EAR
                            wdfink

                            The behaviour is different if you use the client inside AS7 or not.

                            You might have a look into this quickstart

                            • 11. Re: Remote EJB not working from WAR to EAR
                              max.charas

                              Hello Wolf-Dieter,

                              I've spent quite alot of time in that quickstart but I havent found an example where a EJB client is housed in a webapp (war/ear) and is deployed on a Jboss as 7.

                              Do you know if there is such an example?

                              • 12. Re: Remote EJB not working from WAR to EAR
                                davidj

                                Max, I'm glad to hear you are having the same problem as I.

                                I think we have overwhelmingly showed that the problem is JBoss running as the EJB Client.

                                 

                                We never solved the problem but luckily we got permission to use Tomcat 7 as the EJB Client server.

                                 

                                What I find the most humorous is how JBoss will not support the “mappedName” attribute.  This attribute is very useful. It allows you to quickly and easily configure and communicate with multiple Remote EJBs, and the Remote EJBs can reside on multiple servers. Glassfish does this very, very well. JBoss’s reason for not supporting the “mappedName” attribute is because it is “not officially part of the EE spec”. So my question to JBoss is: “Is the file jboss-ejb-client.properties part of the EE spec?”  JBoss will not support “mappedName” because it is not “standard”, but yet their own procedure for Remote EJBs is completely non-standard.

                                • 13. Re: Remote EJB not working from WAR to EAR
                                  wdfink

                                  Hi Max,

                                   

                                  I've pimped the quickstart with an JSF application in an EAR and a Servlet in a separate war file.

                                  It will run for EAP6 and AS7.2, I've not tested with AS7.1.1 at the moment but I suppose it should work.

                                  • 14. Re: Remote EJB not working from WAR to EAR
                                    marcio.dantas

                                    Hi Wolf,

                                     

                                    I studied your new quickstart, but as a beginner in as7 I just couldn't follow it.

                                    I would like to sugest you to write another one with a simpler case: a standalone as7 instance with a WAR client accessing remote EJBs from a EAR in another as7 standalone instance.

                                     

                                    Looking at your code was great to point where I had to put the jboss-ejb-client.xml in a WAR.

                                     

                                    With a lot of effort I was able to make the scenario above work.

                                     

                                    I posted a comment on https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance?focusedCommentId=54493186&# explaining what I did different from the documentation in order to make it work.

                                     

                                    My EAR and WAR are toy projects based on jboss' archetypes for jee6. If you find useful, I could share.

                                     

                                    cheers

                                    1 2 Previous Next