On Oct 16, 2008, at 8:16 AM, Chrys Rowe wrote:
> I have two stateless session beans and 1 interceptor class.
>
> In ssBean1 I inject and use a reference to ssBean2 using the @EJB
> notation. ssBean1 also has a method that has an @Interceptors wrapper
> that calls the interceptor class.
>
> In my interceptor class I also want to use methods in ssBean2 so I
> inject a reference using the same @EJB notation.
>
> The problem is that if I inject a reference to ssBean2 in both ssBean1
> and the interceptor class then my EJB reference in the interceptor
> is null.
>
> If I don't inject ssBean2 in ssBean1 then my interceptor EJB reference
> works fine.
>
> I also found that if I have a ssBean3 class that doesn't reference
> ssBean2 and calls the same interceptor before ssBean1 then the EJB
> reference in the interceptor will work when its later called from
> ssBean1.
>
> I attached the 5 sample classes that reproduce the issue.
> If you call ssBean1.Test() a NPE is thrown in TestInterceptor. If you
> comment out the EJB injection in ssBean1 then no NPE is thrown in
> TestInterceptor.
>
> Is this a bug or am I doing something wrong?
>
Sounds like a bug. Can you remove the name() attribute from the @EJB
annotations and see if you still get the NPE?
--ken
> Thanks
> Chrys
>
>
> package testapp;
>
> import javax.ejb.Remote;
>
> @Remote
> public interface ssBean1Remote {
>
> void Test();
> }
>
>
> package testapp;
>
> import javax.ejb.EJB;
> import javax.interceptor.AroundInvoke;
> import javax.interceptor.InvocationContext;
>
> public class TestInterceptor {
>
> @EJB(name = "ssBean2")
> private ssBean2Remote ssBean2;
>
> @AroundInvoke
> public Object myCheck(InvocationContext context) throws Exception {
>
> //this line will thrown a NPE if the EJB reference is
> ssBean2.printMessage();
> return context.proceed();
> }
> }
> package testapp;
>
> import javax.ejb.EJB;
> import javax.ejb.Stateless;
> import javax.interceptor.Interceptors;
>
> @Stateless(mappedName = "ssBean1")
> public class ssBean1Bean implements ssBean1Remote {
>
> //comment these two lines out and the NPE exception is not thrown
> in TestInterceptor
> @EJB(name = "ssBean2")
> private ssBean2Remote ssBean2;
>
> @Interceptors(testapp.TestInterceptor.class)
> public void Test() {
> System.out.println("This is the test method");
> }
> }
>
>
> package testapp;
>
> import javax.ejb.Stateless;
>
> @Stateless(mappedName = "ssBean2")
> public class ssBean2Bean implements ssBean2Remote {
>
> public void printMessage() {
> System.out.println("This is a message from Session Bean2");
> }
> }
>
>
> package testapp;
>
> import javax.ejb.Remote;
>
> @Remote
> public interface ssBean2Remote {
> void printMessage();
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net