1 2 3 Previous Next 30 Replies Latest reply on Mar 17, 2014 2:41 PM by sdgiant Go to original post
      • 15. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
        pushpak1981

        Thanks a lot Carlo.   It worked like a charm.

        • 16. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
          hanskr

          Hi, I have a similar situation where I try to call a EJB that's served from JBoss 5.1 with a client on JBoss 7.1 (nightly from 27.01.12)

           

          I've followed the suggestions in this thread, and my code for calling the EJB is now like this:

          Context ctx = null;

                              Properties env = new Properties();

                              env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                              env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                              env.put(Context.PROVIDER_URL, "jnp://myservername.com:1099");

           

                              URL clientUrl;

                              try {

                                        clientUrl = new URL(new File("C:\\jboss-as-7.1.0.Final-SNAPSHOT").toURI().toURL(), "modules/org/jboss/jboss-5-client/main/jbossall-client.jar");

                              } catch (MalformedURLException e) {

                                        throw new SystemException(e);

                              }

                              URL[] urls = new URL[1];

                              urls[0] = clientUrl;

                              URLClassLoader urlCl = new URLClassLoader(urls, null);

                              ClassLoader previous = Thread.currentThread().getContextClassLoader();

                              ClassLoader cl = new AluniteClassLoader(urlCl, previous);

                              Thread.currentThread().setContextClassLoader(cl);

           

                              try {

                                        ctx = new InitialContext(env);

                                        return (PIAService)ctx.lookup("thisisthe/name/remote");

                              } catch (NamingException e) {

                                        throw new SystemException(e);

                              } finally {

                                 Thread.currentThread().setContextClassLoader(previous);

                              }

           

           

          When I try to run this, i get the following error:

          Exception: org.jboss.security.plugins.JBossSecurityContext cannot be cast to org.jboss.security.SecurityContext: java.lang.ClassCastException: org.jboss.security.plugins.JBossSecurityContext cannot be cast to org.jboss.security.SecurityContext

                    at org.jboss.security.SecurityContextFactory.createSecurityContext(SecurityContextFactory.java:117) [picketbox-4.0.6.final.jar:4.0.6.final]

                    at org.jboss.security.SecurityContextFactory.createSecurityContext(SecurityContextFactory.java:76) [picketbox-4.0.6.final.jar:4.0.6.final]

                    at org.jboss.ejb3.security.client.SecurityActions$1.run(SecurityActions.java:662)

                    at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_26]

                    at org.jboss.ejb3.security.client.SecurityActions.createSecurityContext(SecurityActions.java:657)

                    at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:59)

                    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                    at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)

                    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                    at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)

                    at $Proxy135.invoke(Unknown Source)          at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)

                    at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)

                    at $Proxy134.getContract(Unknown Source)          at protector.claims.logic.remote.pia.PiaManager.getRemoteContract(PiaManager.java:43) [classes:]

                    at protector.claims.logic.remote.pia.PiaManager.getContract(PiaManager.java:48) [classes:]

          Any idea what's going on?

          • 17. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
            shadowcreeper

            My colleague found that in JBoss7 you can just exclude modules "org.picketbox" and "org.jboss.logging" in your jboss-deployment-structure.xml file and you can do jndi lookup from jboss7  to jboss5 server the same way you would do it between two jboss5 servers (as long as your ear has the jboss5 client libs in it that is). No need for the AluniteClassLoader at all.

            • 18. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
              garcimouche

              I also needed to call an EJB 2.0 running in AS5 from AS7. Here are the steps I took to make this work:

              1. create a module in AS7 refering all jboss5-client jars.
              2. create a module in AS7 refering your jboss 5 service client classes with a dependency to the module created in step1.
              3. DO NOT package your service client classes into your deployment archive! (BTW You will need the dependency at compile time obviously).
              4. create a dependency (for example by creating a jboss-deployment-structure.xml) for your deployment (or your sub-deployment) on the module created in step2.
              5. before making your jndi call, swap the TCCL to MyServiceRemote.class.getClassLoader() (this class loader will have visibility on all client classes of AS5+your services but will be isolated from other AS7 classes that might conflict. No need to use the AluniteClassLoader here.).
              6. enjoy!
              • 19. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                ricardoarguello

                Like this?

                 

                ClassLoader previousTCCL = Thread.currentThread().getContextClassLoader();

                ClassLoader classLoader = MyServiceRemote.class.getClassLoader();



                try {

                  // Swap the TCCL

                  Thread.currentThread().setContextClassLoader(classLoader);


                  // Invoke the service

                  Context ctx = new InitialContext();

                  MyServiceRemote service = (MyServiceRemote) context.lookup("ejb/MyServiceRemote");

                  service.doSomething();


                } catch (Exception e) {

                  e.printStackTrace();

                } finally{

                  // Switch the TCCL back

                  Thread.currentThread().setContextClassLoader(previousTCCL);

                }

                • 20. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                  garcimouche

                  Yes (just a detail, move Thread.currentThread().setContextClassLoader(classLoader) before the try).

                  • 21. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                    ricardoarguello

                    Could you post the module.xml file for the jboss-client module?

                    • 22. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                      garcimouche

                      Here you go https://gist.github.com/3799073.

                      (You will find all the mentionned jars in the jboss as5/client directory)

                      • 23. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                        felipenova

                        I did exactly what was said but the error does not find a class:

                        org.jboss.security.plugins.JBossSecurityContext

                         

                        In deployments i exclude <module name="org.picketbox" />

                        All the Jboss 5 client libs is in a module.

                         

                        How to resolve this?

                         

                        Thanks

                        • 24. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                          shadowcreeper

                          We didn't create a JBoss5 module. We simply included the JBoss5 client jar into our project.

                           

                          We also don't play tricks with classloaders. We do include a jboss-deployment-structure.xml file in the ear's META-INF. In this file, we exclude org.picketbox and org.jboss.logging.

                          • 25. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                            garcimouche

                            I guess the JBossSecurityContext is not called with the appropriate CL, it should be called within the remote service classloader. The class is in jbosssx-client.jar which is part of jboss5 client jars so it is visible to your remote service. I would remove security on the remote service for a try.

                            • 26. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                              felipenova

                              And how is my client lookup in jboss 7 to access my ejb in jboss5?

                              • 27. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                                shadowcreeper

                                We do it the same way we always did between 2 jboss5 clients.

                                 

                                Something like the following:

                                 

                                Properties jndiProperties = new Properties();

                                properties.put( Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );

                                properties.put( Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );

                                properties.put( Context.PROVIDER_URL, "jnp://" + jbossHostName + ":" + jbossPort );

                                properties.put( Context.SECURITY_PRINCIPAL, username );

                                properties.put( Context.SECURITY_CREDENTIALS, password );

                                Context context = new InitialContext( jndiProperties );

                                return (MyBean)contex.lookup( "MyBean/remote" );

                                 

                                Edit: In fact we usually do this via a MyBeanFactory class which is part of the MyBean service's client library and we use the same library in the same way whether we are using it in JBoss5 or in JBoss7.1.

                                • 28. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                                  jangalinski

                                  Can you please post your jboss-deployment-structure and the jars, you include? You always mention "the client jar", but since AS5 there is a bunch of jars required.

                                   

                                  Whenever I try to deploy the AS5-client jars within my EAR/lib, I get

                                   

                                  Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS017052: Failed to parse POJO xml [ "/content/EAR/lib/jboss-ejb3-core-1.1.5.jar/META-INF/ejb3-deployers-jboss-beans.xml" ]

                                  • 29. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
                                    shadowcreeper

                                    My appologies, when I say "the client jar" I am not being clear. I meant the group of jar files (which at my company, before we used maven, we had stuck into 1 large jar file) which must be used to connect to a JBoss5 remote EJB from a standalone Java program (or from Tomcat, etc). Right now we use a pom file which we got from somewhere on the web and hacked up a bit to work with some of the other stuff we use (such as jaas authentication).

                                     

                                    Since I cannot find a way to attach it, and cannot remember where I got the original from, I created an article for it here:

                                    https://community.jboss.org/wiki/ConnectingToJBoss510GARemoteEJBFromJBoss71