aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes JNDI lookup between GlassFish 3.1 and JBoss AS 7.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 between GlassFish 3.1 and JBoss AS 7.1" Watch "JNDI lookup between GlassFish 3.1 and JBoss AS 7.1" New topic
Author

JNDI lookup between GlassFish 3.1 and JBoss AS 7.1

Dana Peele
Greenhorn

Joined: Aug 04, 2012
Posts: 6
I have been puzzling over this for several days and have finally thrown in the towel and come here for help. I am just getting started with EJB 3 and am trying to create a simple session bean on either (or preferably both) GlassFish 3.1 and JBoss AS 7.1 and then look up its remote interface using JNDI from the other (both are running on the same computer, the GlassFish instance on 8080 and the JBoss on 80). I have successfully created such an EJB on each server and then looked it up from a client app on the same server, although I understand that this is not a remote lookup. I have also created a standalone application and successfully remotely looked up beans on the GlassFish server and JBoss server using the client jars (and in the case of JBoss, setting up an application user and InitialContext properties as per this page- http://middlewaremagic.com/jboss/?tag=remote). And when I try to lookup up one from the other and visa versa, I cannot perform the lookup. My understanding is this- I need to set some jndi properties (I am using a jndi.properties file), create an initial context, and then lookup the bean using its global name. I also believe that I need the client jar file from the one server to be on the other to make this work. However, whenever I do the lookup from one server to the other server, the InitialContext instance cannot find the remote interface. I've tried the lookups with the "FancyListCreator" handle I set with @Stateful(mappedName="FancyListCreator"), as well as the global name- "java:global/StatefulTest/FancyListBean" and a corba handle- "corbaname:iiop:localhost:3700#java:global/StatefulTest/FancyListBean" all with the same result.

Here is the Remote interface:

package beans;

import javax.ejb.*;

@Remote
public interface RandomNumber {

public double findNum();

public double findNumInRange(double range);

}

And here is the bean itself:

package beans;

import javax.ejb.*;

@Stateless(mappedName="RandomCreator")
public class RandomNumberBean implements RandomNumber {

@Override
public double findNum() {
return (Math.random());
}

@Override
public double findNumInRange(double range) {
return (Math.random() * range);
}

}
Here is the standalone for GlassFish:
package test;

import beans.*;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.Context;

public class BeanTest2 {
public static void main (String[] args) throws Exception {
InitialContext initialContext = new InitialContext();
RandomNumber2 randomNumber2 = (RandomNumber2)initialContext.lookup("java:global/RandomNumberEJB/RandomNumber2Bean");
randomNumber2.setupNum(100000);
System.out.printf("Random with range: %5.2f.%n", randomNumber2.currentValue());
randomNumber2.doubleNum();
System.out.printf("Random with range: %5.2f.%n", randomNumber2.currentValue());
randomNumber2.done();
}
Here is the standalone for JBoss:
package test;

import beans.*;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.Context;

public class BeanTest2 {
public static void main (String[] args) throws Exception {
String JBOSS_CONTEXT="org.jboss.naming.remote.client.InitialContextFactory";
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, JBOSS_CONTEXT);
props.put(Context.PROVIDER_URL, "remote://localhost:4447");
props.put(Context.SECURITY_PRINCIPAL, "testuser");
props.put(Context.SECURITY_CREDENTIALS, "testpassword");
InitialContext initialContext = new InitialContext(props);
System.out.println("Got initial context");
RandomNumber2 randomNumber2 = (RandomNumber2)initialContext.lookup("RandomNumberEJB/RandomNumber2Bean!beans.RandomNumber2");
randomNumber2.setupNum(100000);
System.out.printf("Random with range: %5.2f.%n", randomNumber2.currentValue());
randomNumber2.doubleNum();
System.out.printf("Random with range: %5.2f.%n", randomNumber2.currentValue());
randomNumber2.done();
}
}

Here is the servlet I am trying to use to look it up (I comment out the properties object and the InitialContext instantiation that uses it when I try to go from jBoss to GlassFish:


package tester;

import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;
import beans.*;

@WebServlet("/number-list-servlet-2")
public class NumberListServlet2 extends HttpServlet{

@Override
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
try {
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
InitialContext initialContext = new InitialContext(properties);
//InitialContext initialContext = new InitialContext();
FancyList fancyList= (FancyList) initialContext.lookup("java:global/StatefulTest/FancyListBean");
//FancyList fancyList= (FancyList) initialContext.lookup("corbaname:iiop:localhost:3700#java:global/StatefulTest/FancyListBean");
//FancyList fancyList= (FancyList) initialContext.lookup("FancyListCreator");
fancyList.initializeNumbers(250, 100000);
request.setAttribute("fancyList", fancyList);
RequestDispatcher requestDispatcher = request.getRequestDispatcher("WEB-INF/responses/numbers.jsp");
requestDispatcher.include(request, response);
fancyList.removeList();
} catch (NamingException e) {
System.out.println ("Exception getting remote EJB: " + e);
e.printStackTrace();
return;
}
}

}

My jboss-ejb-client.properties from JBoss:
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

java.naming.factory.url.pkgs=org.jboss.ejb.client.naming

And my jndi.properties from GlassFish:

org.omg.CORBA.ORBInitialHost=localhost

I am using Eclipse and when I am trying to do the lookup from JBoss to GlassFish, I add the gf-client.jar to the build path. And when I try to do the reverse lookup, I add jboss-client.jar.

Here is the stack trace from eclipse when I try to connect to JBoss from the standalone:
org.omg.CORBA.COMM_FAILURE: FINE: IOP00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700 vmcid: OMG minor code: 1 completed: No
at sun.reflect.GeneratedConstructorAccessor29.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:248)
at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:95)
at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.handleFullLogging(WrapperGenerator.java:387)
at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.access$400(WrapperGenerator.java:107)
at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator$2.invoke(WrapperGenerator.java:511)
at com.sun.corba.ee.spi.orbutil.proxy.CompositeInvocationHandlerImpl.invoke(CompositeInvocationHandlerImpl.java:99)
at $Proxy24.connectFailure(Unknown Source)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:257)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:270)
at com.sun.corba.ee.impl.transport.SocketOrChannelContactInfoImpl.createConnection(SocketOrChannelContactInfoImpl.java:129)
at com.sun.corba.ee.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:223)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:228)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.is_a(CorbaClientDelegateImpl.java:393)
at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:130)
at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNameService(SerialContext.java:1241)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:411)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at test.BeanTest2.main(BeanTest2.java:15)
Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused: connect
at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:340)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:242)
... 14 more
Caused by: java.net.ConnectException: Connection refused: connect
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:364)
at sun.nio.ch.Net.connect(Net.java:356)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:623)
at com.sun.corba.ee.impl.orbutil.ORBUtility.openSocketChannel(ORBUtility.java:110)
at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:325)
... 15 more
Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/RandomNumberEJB/RandomNumber2Bean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: IOP00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700 vmcid: OMG minor code: 1 completed: No]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at test.BeanTest2.main(BeanTest2.java:15)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: IOP00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700 vmcid: OMG minor code: 1 completed: No]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:352)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
... 3 more
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: IOP00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700 vmcid: OMG minor code: 1 completed: No
at sun.reflect.GeneratedConstructorAccessor29.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:248)
at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:95)
at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.handleFullLogging(WrapperGenerator.java:387)
at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.access$400(WrapperGenerator.java:107)
at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator$2.invoke(WrapperGenerator.java:511)
at com.sun.corba.ee.spi.orbutil.proxy.CompositeInvocationHandlerImpl.invoke(CompositeInvocationHandlerImpl.java:99)
at $Proxy24.connectFailure(Unknown Source)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:257)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:270)
at com.sun.corba.ee.impl.transport.SocketOrChannelContactInfoImpl.createConnection(SocketOrChannelContactInfoImpl.java:129)
at com.sun.corba.ee.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:223)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:228)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.is_a(CorbaClientDelegateImpl.java:393)
at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:130)
at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNameService(SerialContext.java:1241)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:411)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
... 4 more
Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused: connect
at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:340)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:242)
... 14 more
Caused by: java.net.ConnectException: Connection refused: connect
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:364)
at sun.nio.ch.Net.connect(Net.java:356)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:623)
at com.sun.corba.ee.impl.orbutil.ORBUtility.openSocketChannel(ORBUtility.java:110)
at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:325)

Here is the stack trace from GlassFish :

javax.naming.NamingException: Lookup failed for 'java:global/StatefulTest/FancyListBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: StatefulTest]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at tester.NumberListServlet2.doGet(NumberListServlet2.java:23)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.naming.NameNotFoundException: StatefulTest
at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:310)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:218)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:219)
at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:119)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:505)
... 30 more

And here is the snippet of the startup log for JBoss showing that this name is indeed registered:

14:57:41,091 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-5) JNDI bindings for session bean named FancyListBean in deployment unit deployment "StatefulTest.jar" are as follows:

java:global/StatefulTest/FancyListBean!beans.FancyList
java:app/StatefulTest/FancyListBean!beans.FancyList
java:module/FancyListBean!beans.FancyList
java:jboss/exported/StatefulTest/FancyListBean!beans.FancyList
java:global/StatefulTest/FancyListBean
java:app/StatefulTest/FancyListBean
java:module/FancyListBean


And here is the stacktrace from JBoss:

Exception getting remote EJB: javax.naming.NameNotFoundException: StatefulTest/FancyListBean -- service jboss.naming.context.java.global.StatefulTest.FancyListBean
15:02:09,335 ERROR [stderr] (http-localhost-127.0.0.1-80-1) javax.naming.NameNotFoundException: StatefulTest/FancyListBean -- service jboss.naming.context.java.global.StatefulTest.FancyListBean
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 tester.NumberListServlet2.doGet(NumberListServlet2.java:23)
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)

And again, the relevant snippet from GlassFish showing that the naming is indeed correct:

[#|2012-09-28T15:00:58.537-0400|INFO|glassfish3.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=83;_ThreadName=Thread-1;|Portable JNDI names for EJB FancyListBean : [java:global/StatefulTest/FancyListBean!beans.FancyList, java:global/StatefulTest/FancyListBean]|#]

I get the same errors no matter what jndi.properties file, client jar, or lookup name I use. I feel like I missing something key but it may just be a configuration issue I am missing. Please help!!!

Sincerely, Dana Peele
Dana Peele
Greenhorn

Joined: Aug 04, 2012
Posts: 6
Jboss AS 7.1.1 EJB lookup from Glassfish 3.1- http://javahowto.blogspot.com/2012/05/glassfish-31-to-jboss-as-711-ejb.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI lookup between GlassFish 3.1 and JBoss AS 7.1