learn java
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

Win a copy of The Software Craftsman this week in the Agile forum!
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.io.PrintWriter;
import java.io.IOException;
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) bindings.next();
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 jboss.naming.context.java.global.RandomNumberEJB.RandomNumber2Bean
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at test.RandomNumberServlet.doGet(RandomNumberServlet.java:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
at java.lang.Thread.run(Thread.java:722)

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
Have you tried LearnNowOnline? http://www.learnnowonline.com/
subject: JNDI Lookup from JBoss AS 7.1.1 to Glassfish 3.1