9 Replies Latest reply on Apr 1, 2010 3:20 AM by Sunil M

    Can't call remote bean from standalone app

    nicolas duminil Novice

      Greetings,

       

      Having deployed an EAR on JBoss AS 5.1.0 containing some SLSB, trying to caal them from a standalone application gives the following:

       

      java.lang.ClassCastException: org.jnp.interfaces.NamingContext cannot be cast to <my remote interface>

       

      I've built with jbosall-client.jar. Please help as I'm spending lot of time here.

       

      Many thanks in advance,

       

      icolas

        • 1. Re: Can't call remote bean from standalone app
          Wolfgang Knauf Master

          Hi,

           

          could you provide the lookup code and details about your app (e.g. the JNDIView of your deployed bean)?

           

          Best regards

           

          Wolfgang

          • 2. Re: Can't call remote bean from standalone app
            nicolas duminil Novice

            Hi Wolfgang,

             

            Here is the lookup:

             

                Hashtable env = new Hashtable();
                env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                env.put(Context.PROVIDER_URL, "localhost:1099");
                env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                Context ctx = new InitialContext(env);
                ResourceFacadeRemote facade = (ResourceFacadeRemote)ctx.lookup("ejb/stateless/Facade");

            And here is the JNDIView:

             

            +- cpv-ear (class: org.jnp.interfaces.NamingContext)
              |   +- Facade (class: org.jnp.interfaces.NamingContext)
              |   |   +- remote-fr.logica.cpv.service.ResourceFacadeRemote (class: Proxy for: fr.logica.cpv.service.ResourceFacadeRemote)
              |   |   +- local (class: Proxy for: fr.logica.cpv.service.ResourceFacadeLocal)
              |   |   +- local-fr.logica.cpv.service.ResourceFacadeLocal (class: Proxy for: fr.logica.cpv.service.ResourceFacadeLocal)

            Many thanks in advance for your help.

             

            Nicolas

            • 3. Re: Can't call remote bean from standalone app
              Wolfgang Knauf Master

              Hi,

               

              first of all:I always used those URL_PKG_PREFIXES:

               

               

              {code}props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");{code}

               

              Second question: the JNDI view snippet does contain a binding for the remote interface (as it does for "local"). Did you just miss this line or is it not present in your JNDI view? How did you annotate the EJB + interfaces?

               

              Third question: do you bind the EJB to the Environment Naming Context, or do you want to lookup it from global JNDI?

               

               

              If you use the ENC, you should post either your jboss-app.xml or the binding annotations.

              If you want to lookup from global JNDI, this should be the correct name (assuming that the Remote interface is bound to "remote", which is the default, but which is missing in your JNDIview snippet):

               

              {code}ResourceFacadeRemote facade = (ResourceFacadeRemote)ctx.lookup("cpv-ear/Facade/remote");{code}

               

              Hope this helps

               

              Wolfgang

              • 4. Re: Can't call remote bean from standalone app
                nicolas duminil Novice

                Hi Wolfgang,

                 

                Many thanks again.

                 

                1. Changing the Context.URL_PKG_PREFIXES doesn't change anything.

                2. No, I didn't miss any line from the JNDIView, this all that I have. But there is a binding for the remote interface:

                 

                +- remote-fr.logica.cpv.service.ResourceFacadeRemote (class: Proxy for: fr.logica.cpv.service.ResourceFacadeRemote)

                 

                The adnotations are as follows:

                 

                @Remote
                public interface ResourceFacadeRemote
                {
                  ...
                }

                 

                @Stateless(name = "Facade", mappedName = "ejb/stateless/Facade/remote")
                public class ResourceFacadeBean implements ResourceFacadeRemote, ResourceFacadeLocal
                {
                  ...

                }

                 

                3. As I'm using the remote interface, even if there is also a local one, I can only lookup from the global JNDI and not from ENC, as I  would have done for the local interface. Well, at least this is my understanding. Replacing this:

                 

                ResourceFacadeRemote facade = (ResourceFacadeRemote)ctx.lookup("ejb/stateless/Facade");

                 

                with this:

                 

                ResourceFacadeRemote facade = (ResourceFacadeRemote)ctx.lookup("ejb/stateless/Facade/remote");

                 

                doesn't change anything.

                 

                Many thanks in advance for your help.

                 

                Nicolas

                • 5. Re: Can't call remote bean from standalone app
                  Wolfgang Knauf Master

                  Hi,

                   

                  it seems that JBoss does not support the "mappedName" attribute (the spec also declares that it is optional):

                  https://jira.jboss.org/jira/browse/EJBTHREE-648

                   

                  The JNDI bindings should contain two entries for the remote interface. The one you see is some JBoss internal I assume, should not be acccessed by your code. I would expect something like this:

                   

                   

                  {code}+- cpv-ear (class: org.jnp.interfaces.NamingContext)
                    |  +- Facade (class: org.jnp.interfaces.NamingContext)
                    |  |  +- remote (class: Proxy for: fr.logica.cpv.service.ResourceFacadeRemote)
                    |  |  +- remote-fr.logica.cpv.service.ResourceFacadeRemote (class: Proxy for: fr.logica.cpv.service.ResourceFacadeRemote)
                    |  |  +- local (class: Proxy for: fr.logica.cpv.service.ResourceFacadeLocal)
                    |  |  +- local-fr.logica.cpv.service.ResourceFacadeLocal (class: Proxy for: fr.logica.cpv.service.ResourceFacadeLocal){code}

                   

                  Seems that JBoss does not handle your remote interface properly.

                   

                  Could you make sure that the "@Remote" annotation is from the package "javax.ejb" (I saw cases where JBoss jars contained annotations with the same name in different packages, and maybe you imported the wrong one).

                   

                  You probably also annotated the local interface with "@javax.ejb.Local"?

                   

                  The remote interface contains methods?

                   

                  Best regards

                   

                  Wolfgang

                  • 6. Re: Can't call remote bean from standalone app
                    nicolas duminil Novice

                    Hi Wolfgang,

                     

                    Okay, I'm dropping the mappedName option. Now the situation is the following: here are the adnotations:

                     

                    @Remote
                    public interface ResourceFacadeRemote
                    {

                      ...

                    }

                     

                    @Stateless
                    public class ResourceFacadeBean implements ResourceFacadeRemote, ResourceFacadeLocal
                    {
                      ...

                    }

                     

                    Here is the JNDIView:

                     

                    +- cpv-ear (class: org.jnp.interfaces.NamingContext)
                      |   +- ResourceFacadeBean (class: org.jnp.interfaces.NamingContext)
                      |   |   +- remote-fr.logica.cpv.service.ResourceFacadeRemote (class: Proxy for: fr.logica.cpv.service.ResourceFacadeRemote)
                      |   |   +- local (class: Proxy for: fr.logica.cpv.service.ResourceFacadeLocal)
                      |   |   +- local-fr.logica.cpv.service.ResourceFacadeLocal (class: Proxy for: fr.logica.cpv.service.ResourceFacadeLocal)
                      |   |   +- remote (class: Proxy for: fr.logica.cpv.service.ResourceFacadeRemote)

                    Here is the lookup:

                     

                        Hashtable env = new Hashtable();
                        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                        env.put(Context.PROVIDER_URL, "localhost:1099");
                        env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
                        Context ctx = new InitialContext(env);
                        ResourceFacadeRemote facade = (ResourceFacadeRemote)ctx.lookup("cpv-ear/ResourceFacadeBean/remote");

                     

                    And here is the exception raised by the lookup:

                     

                    Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.421 sec <<< FAILURE!
                    testUnmarshall(fr.logica.cpv.client.TestModel)  Time elapsed: 0.375 sec  <<< ERROR!
                    java.lang.ClassCastException: javax.naming.Reference cannot be cast to fr.logica.cpv.service.ResourceFacadeRemote
                            at fr.logica.cpv.client.TestModel.testUnmarshall(TestModel.java:41)

                     

                    Do you see anything which could be a problem here ?

                     

                    Kind regards,

                     

                    Nicolas

                    • 7. Re: Can't call remote bean from standalone app
                      Wolfgang Knauf Master

                      Hi,

                       

                      well, JNDI looks good now, but this changed only the exception...

                       

                      Currently, I don't have much more ideas (besides hating the new wiki, because it made my previous post more broken each time I tried to repair formatting)...

                       

                      The only idea: I always use this URL (protocol declaration "jnp" added): env.put(Context.PROVIDER_URL, "jnp://localhost:1099");

                       

                      In EJB2.1, you would have had to "narrow" the lookup return value:

                      ResourceFacadeRemote facade = (ResourceFacadeRemote) PortableRemoteObject.narrow (ctx.lookup("cpv-ear/ResourceFacadeBean/remote"), ResourceFacadeRemote.class);

                      But for JBoss 5.1, this is not necessary any longer I heard.

                       

                      Could you verify that your client uses the same version of JBoss jars as the server, and that the ejb class files in your client are the same version as in the server?

                       

                      Best regards

                       

                      Wolfgang

                      • 8. Re: Can't call remote bean from standalone app
                        nicolas duminil Novice

                        Hi,

                         

                        Yes making sure that the client uses the same jbossall-client.jar as the server solves the problem. Looking at the jbossall-client.jar MANIFEST.MF, it says 5.1.0.GA. But using a dependency on that version of the artifact in the maven build raises the ClassCastException. The solution is to use the <scope>system</scope> in the maven build and this way it works. However, this requires a JBoss install on the client side and, even if this solves temporarily my problem, I think that there still exist a deeper implication. One couldn't assume that there is systematically a JBoss install on each client !

                         

                        By the way, the mappedBy is supported by JBoss.

                         

                        Many thanks,

                         

                        Nicolas

                        • 9. Re: Can't call remote bean from standalone app
                          Sunil M Newbie

                          Just to add on the ClassCastException, client classes in 5.0.0.GA are not compatible with JBoss client classes in 5.1.0.GA, see the below link:

                          https://jira.jboss.org/jira/browse/JBAS-7059