0

I've written my own authentification realm for Glassfish server 4. As the reference says, I've placed the jar with the realm class and login module in domains/[domain]/lib and everything works. Now I want to access a business bean from this realm library. The business bean is located in the EJB part of the project. But it fails permanently. I tried:

    try {
        Object object = InitialContext.doLookup("java:global/My-Demo-ejb/A");
        System.out.println("=====> Obj: " + object);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Looking up failed:");
        logger.log(Level.SEVERE, e.toString());
        e.printStackTrace();
    }

In this case my project is named "My-Demo" and the EJB subproject is named "My-Demo-ejb". The Interface "A" looks like:

@Remote
public interface A {
...
}

and there is also an implementation:

@Stateless
@LocalBean
public class AB implements A {
...
}

But everytime I try this, the exception javax.naming.NameNotFoundException occurs. Also trying to place the Bean in the WAR part fails with the JNDI string java:global/My-Demo-war/A

Could you see any mistake?

EDIT: it is working, iff one uses the JNDI string java:global/Demo/Demo-ejb/AB!de.login.security.AB. Isn't there an easier way than referencing the complete path to the package and why doesn't it work with the interface name instead (A instead of AB)?

mythbu
  • 786
  • 1
  • 7
  • 20

1 Answers1

1

You may use application server dependent JNDI name like:

@Stateless(name="etc")

And you can access it:

InitialContext.doLookup("etc")

But this only works in glassfish.

csabee
  • 217
  • 2
  • 12