File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes JNDI Lookup from JBoss AS 7.1.1 to Glassfish 3.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JNDI Lookup from JBoss AS 7.1.1 to Glassfish 3.1" Watch "JNDI Lookup from JBoss AS 7.1.1 to Glassfish 3.1" New topic

JNDI Lookup from JBoss AS 7.1.1 to Glassfish 3.1

Dana Peele

Joined: Aug 04, 2012
Posts: 6
I created 2 simple Session beans and deployed them on Glassfish 3.1. Here is the relevant snippet from the server log:

INFO: Portable JNDI names for EJB RandomNumber2Bean : [java:global/RandomNumberEJB/RandomNumber2Bean, java:global/RandomNumberEJB/RandomNumber2Bean!beans.RandomNumber2]
INFO: Glassfish-specific (Non-portable) JNDI names for EJB RandomNumber2Bean : [RandomNumber2, RandomNumber2#beans.RandomNumber2]
INFO: Portable JNDI names for EJB RandomNumberBean : [java:global/RandomNumberEJB/RandomNumberBean!beans.RandomNumber, java:global/RandomNumberEJB/RandomNumberBean]
INFO: Glassfish-specific (Non-portable) JNDI names for EJB RandomNumberBean : [RandomCreator#beans.RandomNumber, RandomCreator]
INFO: RandomNumberEJB was successfully deployed in 2,118 milliseconds.

Here is the remote interface:

package beans;

import javax.ejb.*;

public interface RandomNumber2 {

public void setupNum (double range);

public double currentValue ();

public void doubleNum ();

public void done ();


And the Bean itself:
package beans;

import javax.ejb.*;

public class RandomNumber2Bean implements RandomNumber2 {
@EJB RandomNumber randomNumber;
private double number;

public void setupNum(double range) {
number = randomNumber.findNumInRange(range);

public double currentValue() {
return number;

public void doubleNum() {
number = number*2;

public void done() {
number = 0;



I have a servlet that I have deployed to JBoss AS 7.1.1. Here is the code:

package test;

import java.util.Properties;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import javax.naming.*;

import beans.*;

public class RandomNumberServlet extends HttpServlet{

public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
PrintWriter out = response.getWriter();
Properties props = new Properties();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
InitialContext initialContext = new javax.naming.InitialContext(props);
NamingEnumeration bindings = initialContext.listBindings("");

// Go through each item in list
while (bindings.hasMore()) {
Binding bd = (Binding);
out.println(bd.getName() + ": " + bd.getObject());
RandomNumber2 randomNumber2 = (RandomNumber2) initialContext.lookup("java:global/RandomNumberEJB/RandomNumber2Bean");
out.println("<!doctype html>\n" +
"<html>\n" +
"<body>\n" +
"<ul>\n" +
"<li> Number: " + randomNumber2.currentValue() + "</li>");
out.println("<li> Double number: " + randomNumber2.currentValue() + "</li>\n" +
"</ul>" +
"</body>" +
} catch (NamingException e) {

As you can see, I am also trying to enumerate all the bindings just as a debugging test. But the only binding I get is:

TransactionManager: com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@48b83f10

And when the servlet does the jndi lookup, I get the following stack trace:

javax.naming.NameNotFoundException: RandomNumberEJB/RandomNumber2Bean -- service
at javax.naming.InitialContext.lookup(
at test.RandomNumberServlet.doGet(
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.Http11Processor.process(
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(

I am using Eclipse and have added the gf-client.jar to the build path for the web application.

When I change the InitialContext property to the one suggested by GlassFish:

Properties props = new Properties();
//props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
props.put("org.omg.CORBA.ORBInitialHost", "localhost");
InitialContext initialContext = new javax.naming.InitialContext(props);

I get the same single TransactionManager binding and stack trace.

I have successfully gotten a standalone app to remotely access the bean on the GlassFish server as well as the JBoss server and have also gotten the GlassFish server to access the bean on the JBoss server but I can get the JBoss Server to find the bean on the GlassFish server. Please help, any suggestions are very much appreciated.


Dana Peele
I agree. Here's the link:
subject: JNDI Lookup from JBoss AS 7.1.1 to Glassfish 3.1
It's not a secret anymore!