0

i have a problem with a JNDI configuration end EJB 3.1 And Oracle 12.1 DB. my code:

    private static NewSessionBeanRemote lookupRemoteSessionBean() throws NamingException {

    final Hashtable jndiProperties = new Hashtable();
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

    final Context context = new InitialContext(jndiProperties);
    final String appName = "";
    final String moduleName = "EjbComponent";
    final String distinctName = "";
    final String beanName = NewSessionBean.class.getSimpleName();
    final String viewClassName = NewSessionBeanRemote.class.getName();
    System.out.println("ejb:" + appName + "" + moduleName + "" + distinctName + "/" + beanName + "!" + viewClassName);
    return (NewSessionBeanRemote) context.lookup("ejb:" + appName + "" + moduleName + "" + distinctName + "/" + beanName + "!" + viewClassName);
}

ERROR when i try to lookup jndi:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.studio.java.client.EjbTester.lookupRemoteSessionBean(EjbTester.java:73)
at com.studio.java.client.EjbTester.invokeStatelessBean(EjbTester.java:51)
at com.studio.java.client.EjbTester.main(EjbTester.java:41)
reve
  • 99
  • 1
  • 9

1 Answers1

1

Besides your Context.URL_PKG_PREFIXES you also need to set the following properties:

jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");

Also, if you have any type of authentication, you have to set it through Context.SECURITY_PRINCIPAL and Context.SECURITY_CREDENTIALS:

jndiProperties.put(Context.SECURITY_PRINCIPAL, "username");
jndiProperties.put(Context.SECURITY_CREDENTIALS, "password");
António Ribeiro
  • 4,129
  • 5
  • 32
  • 49
  • Many Thanks aribeiro! now i will receive: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:EjbComponent, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@396a51ab – reve Mar 29 '16 at 17:35
  • @reve, you're also missing this property: `jndiProperties.put("jboss.naming.client.ejb.context", true);`. More information can be found [here](https://docs.jboss.org/author/display/WFLY9/Remote+JNDI+Reference+Update+Draft). – António Ribeiro Mar 29 '16 at 21:32