Using different Context inside of a bean
7seconds Jan 23, 2005 11:59 AMHello,
I hope someone may help me solving my problem.
I am busy writing a distributed application with this kind of structure:
I have two jboss servers on two different machines connected via lan: One with a standalone java application as client, both with a jboss4 server containing the same jar containing the same set of ejbs with the same jndi names providing some business functionality. I already set up this scenario and succeeded in communicating with the ejb components in a single jboss server from my client application.
I set up an InitialContext to connect from my client app to the jboss jnp service this way:
Properties properties = System.getProperties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("java.naming.security.principal", "myUserName");
properties.put("java.naming.security.credentials", "myPassWord");
InitialContext ctx = new InitialContext(properties);
and succeeded finding my ejbs using the jndi-names specified in jboss.xml by this code:
jndiContext = setContext(task.getDSKAddress().getComponentName());
Object ref = jndiContext.lookup("DSKHomeRemote");
DSKHomeRemote home = (DSKHomeRemote) PortableRemoteObject.narrow(ref,DSKHomeRemote.class);
DSKRemote DSK = home.create();
with task.getDSKAddress().getComponentName() returning the url of the server to connect to via jndi as String with value "jnp://localhost:1099".
I also succeeded in communincating with the ejbs living in the other jvm jboss located at a remote server from my client app by changing the provider.url to the according setting. I was able to access the Remote objects from the ejbs living in the same jboss container.
Now, heres my problem:
if I try to find a bean located on server b from a business method of a bean living in server a, i get this exception:
16:33:28,923 INFO [STDOUT] java.lang.ClassCastException: javax.naming.CompoundName
16:33:28,925 INFO [STDOUT] at org.jboss.util.property.PropertyMap.remove(PropertyMap.java:198)
16:33:28,926 INFO [STDOUT] at org.jnp.interfaces.NamingContext.getEnv(NamingContext.java:1299)
16:33:28,926 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:526)
16:33:28,926 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:520)
16:33:28,926 INFO [STDOUT] at javax.naming.InitialContext.lookup(InitialContext.java:351)
16:33:28,926 INFO [STDOUT] at redicat.mvs.IMVKBean.executeResourceCollection(IMVKBean.java:84)
What I did: I created a new Context using the values letting me connect successfully from my client app with this code:
jndiContext = setContext(task.getDSKAddress().getComponentName());
Object ref = jndiContext.lookup("DSKHomeRemote");
DSKHomeRemote home = (DSKHomeRemote) PortableRemoteObject.narrow(ref,DSKHomeRemote.class);
DSKRemote DSK = home.create();
with task.getDSKAddress().getComponentName() returning the url of the server to connect to via jndi as String containing "jnp://ip.of.the.server:1009" (replace the ip.of.. with its real ip).
Now my question: how can I get a reference to the Remote object of a bean living in a jboss server on a jvm on server b from a bean living in a different jboss server in a different jvm on server a?
Remember: the set of beans living in jboss on server a and b is identical. They were deployed with the same jar file and have the same ejb-jar and jboss.xml files, the same classnames and the same jndi names. The only difference is the machine on which the jboss server runs.
Is it possible to access beans with the same jndi-name located at different ejb containers? How do I have to set the context to find beans being in container b from a business method of a bean in container a?
My setup: jboss 4.0.1 linux, configuration out-of-the-box, jdk1.5.0
Please help, I get nuts if I don't get to solve this problem.
Greetings from Oldenburg, Germany
Ralph