| timasmith@hotmail.com 2006-05-11, 7:01 pm |
| I start my app with the line
My jndi.properties contains
java.naming.factory.initial=org.jboss.security.jndi.LoginInitialContextFactory
#org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://127.0.0.1:1099
java.naming.factory.url.pkgs=org.jboss.naming.client
java.naming.security.principal=200
java.naming.security.credentials=j2ee
java.naming.security.protocol=client-login
j2ee.clientName=osrmt-client
How do I alter my application code below to dynamically change the
server I am talking to?
i.e. how do I make lookup home talk to say jnp://192.168.1.101:12000
RequirementManagerHome ejbhome = (RequirementManagerHome)
lookupHome(null, RequirementManagerHome.COMP_NAME,
RequirementManagerHome.class);
RequirementManager refejb = ejbhome.find();
refejb.executeMyMethod(myParams);
private static Object lookupHome(java.util.Hashtable environment,
String jndiName, Class narrowTo) throws javax.naming.NamingException {
// Obtain initial context
javax.naming.InitialContext initialContext = new
javax.naming.InitialContext(environment);
try {
Object objRef = initialContext.lookup(jndiName);
// only narrow if necessary
if (java.rmi.Remote.class.isAssignableFrom(narrowTo))
return javax.rmi.PortableRemoteObject.narrow(objRef,
narrowTo);
else
return objRef;
} finally {
initialContext.close();
}
}
|