0
votes

I've been trying to create a standalone java app that connects to a EJB in a JBOSS As 7.1.1. I'm going through this tutorial: https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

Problem is, I just can't connect to the EJB. I'm always getting a IllegalStateException as follows

Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:testeWeb-web-0.0.1-SNAPSHOT,modulename:testeWeb-ejb-0.0.1-SNAPSHOT,distinctname:] combination
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:485)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:84)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:175)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:122)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:107)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:90)
at com.sun.proxy.$Proxy0.getSenha(Unknown Source)
at testes.TesteCodigo.main(TesteCodigo.java:94)

Thing is. I have no idea how to correctly form the JNDI lookup String. Here's the loojup code i'm using private static TesteFacade lookupFacade() throws NamingException{ final Hashtable jndiProperties = new Hashtable(); jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

    final Context context = new InitialContext(jndiProperties);

    return (TesteFacade) context.lookup("ejb:testeWeb-web-0.0.1-SNAPSHOT/testeWeb-ejb-0.0.1-SNAPSHOT//TesteFacadeImpl!facade.TesteFacade");
}

and here's the deployment log for that EJB:

java:global/testeWeb/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl!facade.TesteFacade
java:app/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl!facade.TesteFacade
java:module/TesteFacadeImpl!facade.TesteFacade
java:jboss/exported/testeWeb/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl!facade.TesteFacade
java:global/testeWeb/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl
java:app/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl
java:module/TesteFacadeImpl

how should I create the JNDI lookup string?

1
do you deploy the EJB in a .ear file? - Gabriel Aramburu
Look at the JNDI url, the ear is present and its name is 'testeWeb' - iskramac

1 Answers

0
votes

In jndiProperties you are missing EJB context initialization, try those props:

    Properties props = new Properties();
    props.put("jboss.naming.client.ejb.context", true);
    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    props.put(Context.PROVIDER_URL,  "remote://localhost:4447");
    props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

I also think that EJB url is incorrect, try lookup for your EJB at address:

ejb:testeWeb/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl!facade.TesteFacade