EJB is null in PreProcessInterceptor

I am using RestEasy in a JBoss AS 7.1.1 environment.

For security reasons, I applied the PreProcessInterceptor class. The class is annotated with @Provider and @ServerInterceptor. Each time the interceptor is launched, and this is normal.

Now the following is bothering me.

I am inserting an EJB using the @EJB annotation into a class. When a PreProcessInterceptor is called, the EJB is always null .

@Provider @ServerInterceptor public class SecurityInterceptor implements PreProcessInterceptor { @EJB private SomeEjb someEjbServiceFacade; ... some funny stuff } 

What EJB looks like:

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

The funny part is, it works through a search:

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

Does anyone have an explanation for this behavior?

Thanks in advance.

+5
source share
3 answers

You cannot enter EJB in an arbitrary class, but only in the specified type, such as Servlet, filter, listener, Statelessness, Statefull, MessageDriven beans, Singleton. If you want to use EJB in other classes, then use access, although JNDI, as you indicated above.

+3
source

Try adding @Stateless annotation to your SecurityInterceptor class.

0
source

What are Interceptors?

Interceptors are used in conjunction with the Java EE managed classes to allow developers to invoke interceptor methods on the associated target class in conjunction with method invocations or lifecycle events .

The following SomeEjb class SomeEjb also be available for the associated target class ie, SecurityInterceptor .

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

To do this, we need to add a SecurityInterceptor to the <context-param> of web.xml .

It should look something like this!

 <context-param> <param-name>resteasy.providers</param-name> <param-value> .... com.myInterceptors.interceptors.security.SecurityInterceptor </param-value> </context-param> 
0
source

All Articles