-
1. Re: JBoss as a RMI Server
yantriki Dec 9, 2005 9:48 AM (in response to chris.mag)You need the following:
1. rmi.policy file with the following content
grant {
// Allow everything for now
permission java.security.AllPermission;
};
2. You will need the jboss-client.jar available in JBOSS_HOME/client folder. The jar provides JNDI lookups.
3. In the client application do the following:
// your client method for looking up the registered RMI server object from JNDI
String BINDING = "RMIServerObjectRemoteInterface";
String binding = "//"+host+"/"+BINDING;
if(System.getSecurityManager() == null) {
ClassLoader cl = client.class.getClassLoader();
java.net.URL url = cl.getResource("config/rmi.policy");
System.setProperty("java.security.policy", url.toExternalForm());
System.out.println("Initializing the security manager");
System.setSecurityManager(new RMISecurityManager());
}
try{
// replacing rmi lookup with JNDI lookup
//obj = (IRMIService)Naming.lookup(binding);
Context context = getContext(host);
Object objref = context.lookup(BINDING);
obj = (IRMIService)PortableRemoteObject.narrow(objref,IRMIService.class);} catch(java.rmi.ConnectException ex){
System.out.println("The service may not be running on the host: "+host);
}
catch(Exception ex){
System.out.println("Exception: "+ex.getMessage());
ex.printStackTrace();
}
3. Server registration to the JNDI:
First create a security Manager
if(System.getSecurityManager() == null) {
ClassLoader cl = this.getClass().getClassLoader();
java.net.URL url = cl.getResource("config/rmi.policy");
System.setProperty("java.security.policy", url.toExternalForm());
System.out.println("Initializing the security manager");
System.setSecurityManager(new RMISecurityManager());
}
//To bind the server object to the JNDI
try{
m_service = new PASTService();
String binding;
String host;
if(args.length>0){
host = args[0];
}
else {
host = "localhost";
}
binding = "//"+host+"/"+BINDING;
// binding with rmi commented
// Naming.rebind(binding, m_service);
// will try JBoss JNDI
Context context = getContext(host);
context.rebind(BINDING, m_service);
} catch (Exception ex){
System.out.println("Exception: "+ex.getMessage());
ex.printStackTrace();
}
4. For jboss server's initial context, you can either user jndi.properties file or as detailed above in the code use the following method:
private static Context getContext(String serverURL) throws NamingException {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
p.put(Context.PROVIDER_URL, serverURL);
return new InitialContext(p);
}
Hope this works for you.
Vivek Srivastav -
2. Re: JBoss as a RMI Server
chris.mag Dec 13, 2005 5:46 AM (in response to chris.mag)It did!
Thanks a lot for your reply!
Now I need to dig a bit deeper to see how to set that up at deployement time (for now, I've just tested from the Duke's Bank Sample client app, by launching the configuration of my server app via a call to a StatelessSessionBean...)
Thanks again
Cheers
Chris