-
15. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
pushpak1981 Jan 23, 2012 6:42 AM (in response to wolfc)Thanks a lot Carlo. It worked like a charm.
-
16. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
hanskr Jan 27, 2012 10:42 AM (in response to pushpak1981)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 May 23, 2012 9:09 PM (in response to pushpak1981)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 Sep 27, 2012 3:39 PM (in response to shadowcreeper)I also needed to call an EJB 2.0 running in AS5 from AS7. Here are the steps I took to make this work:
- create a module in AS7 refering all jboss5-client jars.
- create a module in AS7 refering your jboss 5 service client classes with a dependency to the module created in step1.
- DO NOT package your service client classes into your deployment archive! (BTW You will need the dependency at compile time obviously).
- 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.
- 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.).
- enjoy!
-
19. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
ricardoarguello Sep 27, 2012 3:12 PM (in response to garcimouche)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 Sep 27, 2012 3:26 PM (in response to ricardoarguello)Yes (just a detail, move
Thread.currentThread().setContextClassLoader(classLoader)
before the try). -
21. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
ricardoarguello Sep 27, 2012 4:27 PM (in response to garcimouche)Could you post the module.xml file for the jboss-client module?
-
22. Re: Jboss5 remote EJB lookup from Jboss 7.1CR1
garcimouche Sep 28, 2012 6:33 AM (in response to ricardoarguello)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 Nov 1, 2012 2:40 PM (in response to garcimouche)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 Nov 1, 2012 2:49 PM (in response to garcimouche)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 Nov 2, 2012 6:51 AM (in response to felipenova)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 Nov 7, 2012 12:36 PM (in response to shadowcreeper)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 Nov 8, 2012 2:19 PM (in response to felipenova)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 Nov 14, 2012 10:37 AM (in response to shadowcreeper)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 Nov 15, 2012 2:23 PM (in response to jangalinski)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