Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJB is null in PreProcessInterceptor

I'm using RestEasy in a JBoss AS 7.1.1 environment.

I implemented for security reasons a PreProcessInterceptor class. The class is annotated with @Provider and @ServerInterceptor. The interceptor is invoked everytime, which is fine.

Now, what bothers me is the following.

I inject a EJB with the @EJB annotation into the class. When the PreProcessInterceptor is called, that said EJB is always null.

@Provider
@ServerInterceptor
public class SecurityInterceptor implements PreProcessInterceptor
{
    @EJB
    private SomeEjb someEjbServiceFacade;

    ... some funny stuff
}

That EJB looks like followed:

@Stateless
public class SomeEjb extends AbstractServiceFacade
{
    ... some important stuff
}

The funny part, it works via lookup:

Context ctx = new InitialContext();
SomeEjb asf = ( SomeEjb )ctx.lookup("java:global/mySuperApplication/SomeEjb" );

Does someone has an explanation for this behaviour?

Thanks in advance.

like image 972
xxx Avatar asked Oct 20 '22 14:10

xxx


1 Answers

You can not inject EJB in arbitrary class, but only in specified type such as Servlet, Filter, Listener, Stateless, Statefull, MessageDriven beans, Singleton. If you want to use EJB in other types of class then use access though JNDI as you pointed above.

like image 161
Alexander Fedyukov Avatar answered Oct 27 '22 10:10

Alexander Fedyukov