jean-philippe
jean-philippe

Reputation: 23

How to lookup EJB into WildFly server to a client

I would like to know how to look up a EJB located into a WildFly server from a remote client using JNDI.

Here is what I use to initialize the context

jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL, "http-remoting://192.168.0.15:8080");
jndiProps.put("jboss.naming.client.ejb.context", true);
Context ctx = new InitialContext(jndiProps);

And this is the console output when I deploy the server:

21:08:29,352 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-10) JNDI bindings for session bean named DataBaseServiceImpl in deployment unit deployment "AnalyseExcelServeur.war" are as follows:

java:global/AnalyseExcelServeur/DataBaseServiceImpl!serveur.database.DataBaseService
java:app/AnalyseExcelServeur/DataBaseServiceImpl!serveur.database.DataBaseService
java:module/DataBaseServiceImpl!serveur.database.DataBaseService
java:jboss/exported/AnalyseExcelServeur/DataBaseServiceImpl!serveur.database.DataBaseService
java:global/AnalyseExcelServeur/DataBaseServiceImpl
java:app/AnalyseExcelServeur/DataBaseServiceImpl
java:module/DataBaseServiceImpl

I have try a lot of combination but every time I get a javax.naming.NameNotFoundException:

javax.naming.NameNotFoundException: exported/AnalyseExcelServeur/DataBaseServiceImpl!serveur.database.DataBaseService -- service jboss.naming.context.java.jboss.exported.exported.AnalyseExcelServeur."DataBaseServiceImpl!serveur.database.DataBaseService"
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:104)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:202)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

I have not defined an app name nor a module name.

Here is how I declare the EJB:

@Stateless
@Remote(DataBaseService.class)
public class DataBaseServiceImpl extends SessionDB implements DataBaseService

On the client side the implementation of the DataBaseService interface is located in the package compte.remote.ejb

I don't know if I have to use ejb:/appname/modulename/bean/location or just /appname/modulename/bean/location or anything else...

Maybe I have to put a file into the .war to declare the EJB...

Upvotes: 2

Views: 5556

Answers (3)

jean-philippe
jean-philippe

Reputation: 23

I did it !! The problem was that i used two different classpath for the ejb.

The ejb on server side was in serveur.database.DataBaseService

The interface of the ejb on client side was in compte.remote.ejb.DataBaseService

They should be in the same path so i relocate the ejb on client side into a package name serveur.database and that work !

Upvotes: 0

sathya_dev
sathya_dev

Reputation: 513

Hope this might help to sort it out. (It's for looking up JMS queue but the same way you can do it for Beans also.)

http://www.mastertheboss.com/jboss-server/jboss-jms/how-to-code-a-remote-jms-client-for-wildfly-8

Thanks

Upvotes: 0

ehsavoie
ehsavoie

Reputation: 3517

Maybe you should take a look at the documentation :

https://docs.jboss.org/author/display/WFLY8/EJB+invocations+from+a+remote+client+using+JNDI

Upvotes: 1

Related Questions