users@glassfish.java.net

EJB lookup between different applications on the same server

From: <glassfish_at_javadesktop.org>
Date: Wed, 07 May 2008 13:56:29 PDT

Hi

I'm using a glassfish 2 server and have deployed several EJB-projects on it. I use Eclipse + MyEclipse as dev-framework, the projects are deployed as jars and all of my api-parts are exported as jars into the folder glassfish/domains/domain1/lib. Each project works for itself and the lookup of a remote ejb within a single project works fine. I can even execute a little test class that does a lookup for an ejb X of project A and a lookup for ejb Y of project B like:

    public static void main(String[] args) {
        try {
            InitialContext context = new InitialContext();

            ProjectARemote ejbX = (ProjectARemote) context.lookup(ProjectARemote.class.getName());
            ejbX.doSomething();

            ProjectBRemote ejbY = (ProjectBRemote) context.lookup(ProjectBRemote.class.getName());
            ejbY.doSomethingDifferent();

        } catch (NamingException e) {
            e.printStackTrace();
        }
    }

As I said that works fine. But when I try to lookup a remote EJB from an application such that the ejb is hosted by another application (still on the same glassfish instance) I get this exception:

javax.naming.NamingException: ejb ref resolution error for remote business interface xyz.engine.ejb.EngineRemote [Root exception is java.lang.IllegalArgumentException: object is not an instance of declaring class]
        at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:425)
        at com.sun.ejb.containers.RemoteBusinessObjectFactory.getObjectInstance(RemoteBusinessObjectFactory.java:74)
        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
        at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:403)
        at javax.naming.InitialContext.lookup(InitialContext.java:351)
        at xyz.controller.core.ControllerEngineImpl.getEngine(ControllerEngineImpl.java:81)

The source code of the lookup call is like this:

...
@Stateful
public class ControllerEngineImpl implements ControllerEngineRemote {
    private EngineRemote engine = null;
[...]
    private EngineRemote getEngine() {
        if (engine == null) {
            try {
                InitialContext context = new InitialContext();
                engine = (EngineRemote) context.lookup(EngineRemote.class.getName());
            } catch (NamingException e) {
                LogUtil.log("Cannot resolve engine!", Level.SEVERE, e);
            }
        }

        return engine;
    }
}

When I use the same lookup source in my little test app or in an ejb within the same project, it works.

I appreciate if someone could help me with this.

greets,
Achim
[Message sent by forum member 'achimheynen' (achimheynen)]

http://forums.java.net/jive/thread.jspa?messageID=273217