Skip to main content

Remote server: bean call

12 replies [Last post]
jandebeule
Offline
Joined: 2010-06-30
Points: 0

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jandebeule
Offline
Joined: 2010-06-30
Points: 0

Hello,

I've just tried your solution. I've attached the jar and war file. jar file deploy on server A (ip address 10.4.5.190, Ubuntu server) is no problem. When i deploy the war-file on server B (WinXP), it fails and this is the stacktrace:

[#|2010-07-03T17:38:17.871+0200|SEVERE|glassfish3.0|org.apache.catalina.core.StandardContext|_ThreadID=34;_ThreadName=Thread-1;|PWC1306: Startup of context /web3 failed due to previous errors|#]

[#|2010-07-03T17:38:17.871+0200|SEVERE|glassfish3.0|org.apache.catalina.core.ContainerBase|_ThreadID=34;_ThreadName=Thread-1;|ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class test.Servlet3
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5289)
at com.sun.enterprise.web.WebModule.start(WebModule.java:499)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:928)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:912)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:694)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1947)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1619)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:90)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:310)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
at org.glassfish.deployment.autodeploy.AutoOperation.run(AutoOperation.java:141)
at org.glassfish.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:573)
at org.glassfish.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:459)
at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:391)
at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:376)
at org.glassfish.deployment.autodeploy.AutoDeployService$1.run(AutoDeployService.java:195)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: org.apache.catalina.LifecycleException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class test.Servlet3
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5017)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5280)
... 26 more
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class test.Servlet3
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:312)
at com.sun.enterprise.web.WebContainer.createServletInstance(WebContainer.java:709)
at com.sun.enterprise.web.WebModule.createServletInstance(WebModule.java:1937)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1252)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1229)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5007)
... 27 more
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=test.Servlet3/bar,Remote 3.x interface =test.BarIF,ejb-link=null,lookup=null,mappedName=corbaname:iiop:1.2@10.4.5.190:3700#test.BarIF,jndi-name=,refType=Session into class test.Servlet3
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:614)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:384)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:141)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:127)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:306)
... 32 more
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/test.Servlet3/bar' in SerialContext [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=test.Servlet3/bar,Remote 3.x interface =test.BarIF,ejb-link=null,lookup=null,mappedName=corbaname:iiop:1.2@10.4.5.190:3700#test.BarIF,jndi-name=,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'corbaname:iiop:1.2@10.4.5.190:3700#test.BarIF__3_x_Internal_RemoteBusinessHome__' [Root exception is org.omg.CORBA.BAD_PARAM: vmcid: OMG minor code: 9 completed: No]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:513)
... 36 more
Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=test.Servlet3/bar,Remote 3.x interface =test.BarIF,ejb-link=null,lookup=null,mappedName=corbaname:iiop:1.2@10.4.5.190:3700#test.BarIF,jndi-name=,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'corbaname:iiop:1.2@10.4.5.190:3700#test.BarIF__3_x_Internal_RemoteBusinessHome__' [Root exception is org.omg.CORBA.BAD_PARAM: vmcid: OMG minor code: 9 completed: No]
at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:174)
at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1040)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:688)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:657)
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:148)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:428)
... 38 more
Caused by: org.omg.CORBA.BAD_PARAM: vmcid: OMG minor code: 9 completed: No
at com.sun.corba.ee.impl.logging.OMGSystemException.soBadSchemaSpecific(OMGSystemException.java:1075)
at com.sun.corba.ee.impl.logging.OMGSystemException.soBadSchemaSpecific(OMGSystemException.java:1093)
at com.sun.corba.ee.impl.resolver.INSURLOperationImpl.resolveCorbaname(INSURLOperationImpl.java:228)
at com.sun.corba.ee.impl.resolver.INSURLOperationImpl.resolveINSURL(INSURLOperationImpl.java:154)
at com.sun.corba.ee.impl.resolver.INSURLOperationImpl.operate(INSURLOperationImpl.java:144)
at com.sun.corba.ee.impl.orb.ORBImpl.string_to_object(ORBImpl.java:954)
at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:167)
... 43 more
Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:72)
at org.omg.CosNaming._NamingContextExtStub.resolve_str(_NamingContextExtStub.java:165)
at com.sun.corba.ee.impl.resolver.INSURLOperationImpl.resolveCorbaname(INSURLOperationImpl.java:222)
... 47 more

Anybody a suggestion why this works for everybody else and not for me?
Thanks already for all the answers!

Jan

jandebeule
Offline
Joined: 2010-06-30
Points: 0

the attachements for the previous post...

jandebeule
Offline
Joined: 2010-06-30
Points: 0

@ cf126330:
It's a bit difficult to include my test-project, besides, i think it has more to do with Glassfish version/configuration then with my code.
About the command line sysprops, i doubt it, but i tried to set the properties i set in solution 3) (cfr my initial post) to set as system properties.
For instance: System.setProperty("org.omg.CORBA.OMGInitialHost", "10.1.1.2");
and then: InitialContext ctx = new InitialContext(System.getProperties);

But still, no luck.

@rumblesnort:

Could you give me some more information about how you changed to SOAP then?

Message was edited by: jandebeule

rumblesnort
Offline
Joined: 2010-06-14
Points: 0

@jandebeule

Instead of using RMI/IIOP to call remote methods we exposed them via SOAP in the glassfish container which worked as well. Getting this accomplished depends more on what you utilize for your SOAP engine and IDE, (for example, we're on JAX-WS and Netbeans, we used to use Axis2 until the move to Glassfish). A remote method is a remote method, RMI/IIOP, SOAP, REST, etc, are different ways of calling the remote method.

We just used SOAP to wrapper what we needed called and it worked fine. If we can get the InitialContext() piece working we'll likely switch to CORBA for speed and less overhead.

cf126330
Offline
Joined: 2005-03-29
Points: 0

Injection (available in JavaEE 5 & 6, or GlassFish 2.x and 3.x) is easier than using traditional lookup. But if you prefer lookup, I've updated my code to get rid of all injections and use lookup only. Note: only need to update servlet3 class, add web.xml and sun-web.xml:

package test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(loadOnStartup = 1, urlPatterns = { "/Servlet3" })
public class Servlet3 extends HttpServlet {
// @EJB
// @EJB(mappedName="corbaname:iiop:1.2@gf.sun.com:3700#test.BarIF")

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
FooIF foo = lookup(FooIF.class, "java:comp/env/ejb/foo");
BarIF bar = lookup(BarIF.class, "java:comp/env/ejb/bar");
PrintWriter writer = response.getWriter();
writer.println("using lookup, foo.hello returned: " + foo.hello(getServletName()));
writer.println("using lookup, bar.hello returned: " + bar.hello(getServletName()));
}

private T lookup(Class cls, String lookupName) throws ServletException {
T result = null;
InitialContext ic;
try {
ic = new InitialContext();
result = (T) ic.lookup(lookupName);
} catch (NamingException e) {
throw new ServletException(e);
}
return result;
}
}

web.xml:
========
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

ejb/foo
Session
test.FooIF


ejb/bar
Session
test.BarIF

sun-web.xml (in the same place as web.xml, under WEB-INF)
=========





ejb/foo
test.FooIF


ejb/bar
corbaname:iiop:1.2@gf.sun.com:3700#test.BarIF

$ curl http://localhost:8080/web3/Servlet3
using lookup, foo.hello returned: Hello, test.Servlet3 from Mac OS X
using lookup, bar.hello returned: Hello, test.Servlet3 from SunOS

One of the benefits of using a sun-web.xml is, we can remove the machines names from java code, easier to configure.

In general, no-arg constructor of InitialContext should be used, especially inside JavaEE managed environment.

Also for ejb remote invocation (iiop) to work, both ends need to be in the same network.

Message was edited by: cf126330

jandebeule
Offline
Joined: 2010-06-30
Points: 0

Ok, we've finally nailed it.
The issue was that the server B returned "i'm at 127.0.1.1" on the first IIOP-request (context-listing) from server A. That way, server A requested the remote bean to 127.0.1.1 which it not could find because the bean was not deployed on server A (only on server B).

Sniffing on the network gave us the solution. We resolved this by changing the etc/hosts file on the Ubuntu server (and removed the line where '127.0.1.1' appeared).

This is, i think, a bit of a bug, and should be somehow configurable in Glassfish, so that you can decide on which interface Glassfish should be working (changing it in the admin-console, under IIOP-listener, from 0.0.0.0 to the correct IP-address did not solve the issue!).

rmuller
Offline
Joined: 2006-12-21
Points: 0

Just for the record:

We had the same problem and i can confirm the sample code in this thread just works (GF2/GF2, GF3/GF3 and GF3/GF2).
The issue with /etc/hosts only occurs on Ubuntu (both 8.04 and 10.04) not on CentOS (5.4).

Ronald

cf126330
Offline
Joined: 2005-03-29
Points: 0

Can you attach your test project, including src?
You don't need to copy ejb jar files to domain/lib. The command line sysprops may have overridden any other values you specified in the lookup code.

rumblesnort
Offline
Joined: 2010-06-14
Points: 0

cf126330,

This isn't my post, but I've run into similar trouble and it is simple to reproduce on our side:

1. Install two instances of GF 3.0.1 on different servers.
2. From one server call a method on the other using RMI/IIOP by whatever means you're used to.
3. If it works, please post your steps. There isn't a lot of docs out here but what is out doesn't seem to work. We've gone in circles for a day here on this before switching to SOAP.

cf126330
Offline
Joined: 2005-03-29
Points: 0

ok, just created a simple app deployed on 2 machines:

Mac OS machine (GF 3.1 nightly)
Servlet3 + FooBean + FooIF + BarIF, packaged as web3.war

SunOS machine (GF 3.0.1)
BarBean + BarIF, packged as BarBean.jar

Servlet3 calls the colocated FooBean, and the remote BarBean, both beans prints out its os.name, as a way to tell where it is:

/Users/cf126330/workspace/web3 > curl http://localhost:8080/web3/Servlet3
foo.hello returned: Hello, test.Servlet3 from Mac OS X
bar.hello returned: Hello, test.Servlet3 from SunOS

The ejb interfaces and bean classes contain no location info, the same as if running in the same machine. The servlet class @EJB has the mappedName using corbaname to point to the remote machine. That's the only place that specifies a location.

package test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(loadOnStartup=1, urlPatterns={"/Servlet3"})
public class Servlet3 extends HttpServlet {
@EJB
private FooIF foo;

@EJB(mappedName="corbaname:iiop:1.2@gf.sun.com:3700#test.BarIF")
private BarIF bar;

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter writer = response.getWriter();
writer.println("foo.hello returned: " + foo.hello(getServletName()));
writer.println("bar.hello returned: " + bar.hello(getServletName()));
}

}

------------------
package test;

public interface FooIF {
public String hello(String name);
}
-----------------
package test;

import javax.ejb.Remote;
import javax.ejb.Stateful;

@Stateful
@Remote(FooIF.class)
public class FooBean {

public String hello(String name) {
return "Hello, " + name + " from " + System.getProperty("os.name");
}

}
-----------------
package test;

public interface BarIF {
public String hello(String name);
}
-----------------
package test;

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

@Stateless
@Remote(BarIF.class)
public class BarBean {

public String hello(String name) {
return "Hello, " + name + " from " + System.getProperty("os.name");
}

}
-----------------

/Users/cf126330/workspace/web3 > jar tf web3.war
WEB-INF/classes/test/BarIF.class
WEB-INF/classes/test/FooBean.class
WEB-INF/classes/test/FooIF.class
WEB-INF/classes/test/Servlet3.class

/Users/cf126330/workspace/web3 > jar tf BarBean.jar
test/BarBean.class
test/BarIF.class

rumblesnort
Offline
Joined: 2010-06-14
Points: 0

cf126330,

Thank you very much, we're getting closer. Is this documented in the GF v3 guide anywhere? I wouldn't mind a RTFM in the least. One last question - have you gotten this to work with an initialContext() lookup:

InitialContext ctx = null;
EJBRemote thisEJB = (EJBRemote) ctx.lookup("corbaname:iiop:1.2@hostname.domain:3700#path.to.EJBRemote");

by chance? The guide says do not utilize a parameters for the context, just use InitialContext().

@jandebeule:

I've verified cf126330's example (except for the InitialContext() part), it seems we weren't placing @Remote(RemoteInterface.class) in our EJBs and using "iiop:1.2", although I'm fairly certain that was part of our test case(s) as we came across that in a few forums.

rumblesnort
Offline
Joined: 2010-06-14
Points: 0

This sounds very familiar. Did you ever figure this out? I find it difficult to believe GF would be released with this broken as it is a basic component to EJB, thus my assumption that I was missing something simple. However, most of the reference material we've been able to find leads to dead ends including Glassfish documentation.