users@glassfish.java.net

cannot lookup Local interface

From: Stefan Schilling <mail.suse_at_gmx.de>
Date: Fri, 14 Mar 2008 20:09:10 +0100

Hello!

Running glassfish-v2.1-b24-nightly-05_mar_2008, I'm running into the
problem that I cannot lookup an interface, annotated with @Local.

Let's have a simple sample:

the implementation class:

package test;

import javax.ejb.Local;
import javax.ejb.Stateless;

@Local
public interface TestIF {
       public String helloWorld(String name);
}

the implementation class:

package test;

import javax.ejb.Local;
import javax.ejb.Stateless;

@Stateless
@Local(TestIF.class)
public class Test implements TestIF {

       public String helloWorldName(String name){
              return "Hello World " + name;
       }
}


Here comes my "using" class:

package test;

import javax.ejb.Local;
import javax.ejb.Stateless;

@Stateless
@Remote(UsingIF.class)
public class Using implements UsingIF {

  @Resource
  private SessionContext ctx;

  public Using(){
  }
  
  public String hello(String){
    try {
      TestIF test = (TestIF) ctx.lookup("test.TestIF");
                     
      return test.helloWorldName("John Doe");
  } catch ( Exception e ){
    e.printStracktrace();
    return "error";
  }
}

... of course, the @Resource import is missing here, just like the
UsingIF.
Now, if I do this, I get
- a NamingException: glassfish cannot find the requested interface,
    because no object "java/env/test.TestIF" was found.
-> if I change the @Local to @Remote and use

Context context = new InitialContext();
TestIF test = (TestIF) context.lookup("test.TestIF");

it works. But I don't want that bean to be Remote. I also tried to use
the construction above when this bean is @Local, but that doesn't work
either.
What works is the

@EJB
TestIF test;
[...]
test.helloWorldName("John Doe");

But I have to switch to the appropriate IF at Runtime, when I don't
know which ones will be in use at compile time (this can be done by
using String-parameters...).

So: why does glassfish not find my Local IFs, although it can find
    them when they are @Remote?

Thanks for your support.

Regards,
Stefan