Search code examples
javaejbjboss7.xejb-3.0jndi

JNDI loopup for a remote client accessing an EJB deployed in JBOSS AS (7.1.1 final)


I have created a simple EJB 3.0 application, deployed in JBOSS 7.1.1 final.

Here is the code:

EJB 1:

Interface

package com.example.server.local.bean;

import javax.ejb.Local;

@Local
public interface UtilLocalBeanLocal {

    public String addString();
}

Class implementing this interface:

package com.example.server.local.bean;

import javax.ejb.Local;
import javax.ejb.Stateless;

@Stateless
@Local(value=UtilLocalBeanLocal.class)
public class UtilLocalBean implements UtilLocalBeanLocal {

    public UtilLocalBean() {

    }

   @Override
   public String addString() {

        return "Added from Local bean"; 
    }
}

So, this EJB i am creating to be "locally" used by another EJB.

EJB 2:

Interface

package com.example.bean.session;

import javax.ejb.Remote;

@Remote
public interface FirstBeanRemote {

    public String callMe();
}

Class implementing this interface.

package com.example.bean.session;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import com.example.server.local.bean.UtilLocalBeanLocal;

@Stateless
@Remote(value=FirstBeanRemote.class)
public class FirstBean implements FirstBeanRemote {

    @EJB
    private UtilLocalBeanLocal utilLocalBeanLocal;

    public FirstBean() {

    }

    @Override
    public String callMe() {

        return "Hi there!" + utilLocalBeanLocal.addString();
    }
}

When i start the JBOSS, the JNDI bindings i get are like this:

00:34:15,928 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-5) JNDI bindings for session bean named FirstBean in deployment unit subdeployment "EJB30TestProj.jar" of deployment "EJB30TestProjEAR.ear" are as follows:

java:global/EJB30TestProjEAR/EJB30TestProj/FirstBean!com.example.bean.session.FirstBeanRemote
java:app/EJB30TestProj/FirstBean!com.example.bean.session.FirstBeanRemote
java:module/FirstBean!com.example.bean.session.FirstBeanRemote
java:jboss/exported/EJB30TestProjEAR/EJB30TestProj/FirstBean!com.example.bean.session.FirstBeanRemote
java:global/EJB30TestProjEAR/EJB30TestProj/FirstBean
java:app/EJB30TestProj/FirstBean
java:module/FirstBean

However in the remote client when I try to use any of these above JNDI binding values, it is not working, and what actually works (after lot of google) is:

ejb:EJB30TestProjEAR/EJB30TestProj//FirstBean!com.example.bean.session.FirstBeanRemote

It is difficult to understand how this JNDI bindings work. JBOSS outputs a different JNDI and in reality what works is different one.

Can anyone please demystify this? (how to decide which JNDI bindings will work in different scenarios and any further pointers)


Solution

  • The binding values that you mention are prepared for lookup locally, let say into the server that you publish the ejb. global, module, app are the scopes limit and in which you can use each one. For example, you could lookup a ejb from other ejb of the same ejb-module using module scope but you couldn't lookup it from another ejb-module even being modules of the same app (ear or war), you must use at least app scope for that, and you can use app or global in both scenarios.

    I strongly suggest you to take the time to read Jboss AS7 JNDI Referencia but to know about remote lookup go to Remote JNDI section