Finding JNP port in JBoss from Servlet
Posted
by Steve Jackson
on Stack Overflow
See other posts from Stack Overflow
or by Steve Jackson
Published on 2010-06-16T16:40:48Z
Indexed on
2010/06/17
7:03 UTC
Read the original article
Hit count: 611
I have a servlet running in JBoss (4.2.2.GA and 4.3-eap) that needs to connect to an EJB to do work.
In general this code works fine to get the Context to connect and make RMI calls (all in the same server).
public class ContextFactory
{
public static final int DEFAULT_JNDI_PORT = 1099;
public static final String DEFAULT_CONTEXT_FACTORY_CLASS = "org.jnp.interfaces.NamingContextFactory";
public static final String DEFAULT_URL_PREFIXES = "org.jboss.naming:org.jnp.interfaces";
public Context createContext(String serverAddress)
{
//combine provider name and port
String providerUrl = serverAddress + ":" + DEFAULT_JNDI_PORT;
//Set properties needed for Context: factory, provider, and package prefixes.
Hashtable<String, String> env = new Hashtable<String, String>(3);
env.put(Context.INITIAL_CONTEXT_FACTORY, DEFAULT_CONTEXT_FACTORY_CLASS);
env.put(Context.PROVIDER_URL, providerUrl);
env.put(Context.URL_PKG_PREFIXES, DEFAULT_URL_PREFIXES);
return new InitialContext(env);
}
Now, when I change the JNDI bind port from 1099 in server/conf/jboss-service.xml I can't figure out how to programatically find the correct port for the providerUrl above.
I've dumped System.getProperties() and System.getEnv() and it doesn't appear there.
I'm pretty sure I can set it in server/conf/jndi.properties as well, but I was hoping to avoid another magic config file.
I've tried the HttpNamingContextFactory but that fails "java.net.ProtocolException: Server redirected too many times (20)"
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");
env.put(Context.PROVIDER_URL, "http://" + serverAddress + ":8080/invoker/JNDIFactory");
Any ideas?
© Stack Overflow or respective owner