1 November 2011

Access EJB via HTTP in JBoss AS

If you are trying to acccess EJB through HTTP, you need to use org.jboss.naming.HttpNamingContextFactory for your context factory. However, there is only one small twitch in using that. You need to specify credentials accessing that invoker. This is what you need to add:

env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "admin");


This is complete code:

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.HttpNamingContextFactory");
env.put(Context.PROVIDER_URL, "http://localhost:8080/invoker/JNDIFactory");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "admin");
Context ctx = new InitialContext(env);
ejbTestRemote obj = (ejbTestRemote) ctx.lookup("ejbTest/remote");


This is how it looks like if you are using NamingContextFactory:

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
Context ctx = new InitialContext(env);
ejbTestRemote obj = (ejbTestRemote) ctx.lookup("ejbTest/remote");

No comments:

Post a Comment