users@glassfish.java.net

Remote EJB 3.0 lookup and Glassfish v2.1.1

From: <glassfish_at_javadesktop.org>
Date: Fri, 29 Jan 2010 02:35:29 PST

Hello,

I have been searching for a solution for 3 days now for the problem I am currently facing, I have seen various information on the forums but I am still unable to understand where is exactly my problem.

I am trying to lookup remote session beans within the same server instance. Each remote bean is deployed as standalone EJB module and the client session bean (the one that does the lookup is packed into EAR). I keep getting the exception:

[Root exception is java.lang.RuntimeException: Could not invoke defineClass!

the code that does lookup:

Context ctx = new InitialContext();

for (String name : lookupNames) {
            HelloService hs;
            try {
                hs = (HelloService) ctx.lookup(name);
                logger.info("lookup: " + hs.getName());
                hs.send("Hi There!");
            } catch (NamingException ex) {
                logger.log(Level.SEVERE, null, ex);
            }
   }

A little bit of background to explain what I am trying to do:

I don't want to tie my lookup bean to the Remote interfaces of the service beans so I have a common interface:

interface HelloService {
 public void send(String msg);
}

And each bean remote interface extends HelloService so they would be as following:

@Remote
interface HelloServiceARemote extends HelloService {...}

@Stateless
class HelloServiceSessionA implements HelloServiceARemote {...}

@Remote
interface HelloServiceBRemote extends HelloService {...}

@Stateless
class HelloServiceSessionB implements HelloServiceBRemote {...}

So the idea in general would be to lookup new services without having to touch the EAR file, for now I've included the remote interfaces in the library directory of the EAR as I am not sure why glassfish doesn't generate the stubs. My approach is also probably bad and violates the recommendation of EJB 3.0 where injection is favoured but the problem with injection is that it's statically done in the code which isn't what I am trying to achieve.

I hope someone can give me any insightful or short answer on where I might have gone wrong, thanks.

Mohamed
[Message sent by forum member 'mohamedelshami' (mohamed.shami_at_gmail.com)]

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