glassfish
  1. glassfish
  2. GLASSFISH-13513

CDI Interceptor + EJB 3.1 + OSGi doesn't work

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: 3.1_ms07
    • Component/s: ejb_container
    • Labels:
      None
    • Environment:

      Operating System: Linux
      Platform: Linux

    • Issuezilla Id:
      13,513

      Description

      This issue is similar to issue 11491 but differs as we use a highly modular
      enterprise application here using OSGi bundles.

      When trying to use an interceptor by using the annotation the following
      exception occurs during EJB access (called by a web service on top):

      WARNING: A system exception occurred during an invocation on EJB UserServiceImpl
      method public java.lang.Long
      org.glassfish.cditest.user.impl.UserServiceImpl.addUser(org.glassfish.cditest.user.api.model.User)
      throws javax.ejb.EJBException
      javax.ejb.EJBException
      at
      com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5184)
      at
      com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5082)
      at
      com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4870)
      at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2037)
      at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1988)
      at
      com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:203)
      at
      com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
      at $Proxy219.addUser(Unknown Source)
      at
      org.glassfish.cditest.user.impl.ws.UserServiceWS.addUser(UserServiceWS.java:47)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at
      org.glassfish.webservices.InstanceResolverImpl$1.invoke(InstanceResolverImpl.java:141)
      at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
      at
      com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
      at
      com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:95)
      at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:637)
      at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:596)
      at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:581)
      at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:478)
      at
      com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:112)
      at org.glassfish.webservices.MonitoringPipe.process(MonitoringPipe.java:142)
      at
      com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
      at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:637)
      at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:596)
      at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:581)
      at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:478)
      at
      com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:112)
      at
      com.sun.enterprise.security.webservices.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:199)
      at
      com.sun.enterprise.security.webservices.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:131)
      at
      com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
      at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:637)
      at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:596)
      at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:581)
      at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:478)
      at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:310)
      at
      com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:600)
      at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:264)
      at
      com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:144)
      at org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:159)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
      at
      org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1522)
      at
      org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
      at
      org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at
      org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
      at
      org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
      at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
      at
      com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
      at
      org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
      at
      org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
      at
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
      at
      com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
      at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:824)
      at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:721)
      at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1014)
      at
      com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:220)
      at
      com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
      at
      com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
      at
      com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
      at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
      at
      com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
      at
      com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
      at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
      at
      com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:530)
      at
      com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:511)
      at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.IllegalStateException: Singleton not set for
      WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)
      at
      org.glassfish.weld.ACLSingletonProvider$ACLSingleton.get(ACLSingletonProvider.java:110)
      at org.jboss.weld.Container.instance(Container.java:58)
      at
      org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:45)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at
      com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862)
      at
      com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
      at
      com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
      at
      com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at
      com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862)
      at
      com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
      at
      com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:371)
      at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5329)
      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5317)
      at
      com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:195)
      ... 62 more

      The whole test setup is made up of four bundles:

      • security.api (containing a "Secure" annotation + interceptor binding)
      • security.impl (containing the interceptor implementation)
      • user.impl (containing a local ejb)
      • user.ws (containing a simple web service for remote testing)
      1. client.zip
        1 kB
        marina vatkina
      2. interceptor-osgi-test.tar.gz
        9 kB
        chaoslayer
      3. README
        0.4 kB
        Sanjeeb Sahoo
      4. server.log
        28 kB
        marina vatkina

        Activity

        Hide
        chaoslayer added a comment -

        The error message you see is because you don't have the XMPP OSGi bundle
        deployed (and yes I know it's not appropriate for a test case).

        So the real problem might not been hit yet. I'll attach an OSGi bundle for that
        library.

        Show
        chaoslayer added a comment - The error message you see is because you don't have the XMPP OSGi bundle deployed (and yes I know it's not appropriate for a test case). So the real problem might not been hit yet. I'll attach an OSGi bundle for that library.
        Hide
        chaoslayer added a comment -

        Created an attachment (id=5549)
        XPP3 OSGi Bundle

        Show
        chaoslayer added a comment - Created an attachment (id=5549) XPP3 OSGi Bundle
        Hide
        marina vatkina added a comment -

        With your jar, 'java Main' prints 'foo.UserClient@69fe571f' and server.log
        contains only the log message above:

        [#|2010-11-19T17:20:51.266-0800|INFO|glassfish3.1|org.glassfish.cditest.user.api.UserService|_ThreadID=17;_ThreadName=Thread-1;|Returning
        user UserImpl [id=0, emailAddress=test@test.org, firstName=John, gender=UNISEX,
        lastName=Doe, username=john-123]|#]

        Show
        marina vatkina added a comment - With your jar, 'java Main' prints 'foo.UserClient@69fe571f' and server.log contains only the log message above: [#|2010-11-19T17:20:51.266-0800|INFO|glassfish3.1|org.glassfish.cditest.user.api.UserService|_ThreadID=17;_ThreadName=Thread-1;|Returning user UserImpl [id=0, emailAddress=test@test.org, firstName=John, gender=UNISEX, lastName=Doe, username=john-123]|#]
        Hide
        chaoslayer added a comment -

        Well, shortly before that log message it should also print something from the
        interceptor method:

        @AroundInvoke
        protected Object invoke(final InvocationContext ctx) throws Exception
        {
        Principal p = ejbCtx.getCallerPrincipal();
        Method interfaceMethod = ctx.getMethod();

        LOG.log(Level.INFO, "EJB Method called [Full]:\"

        {0}\" by " +
        "Principal:{1}", new Object[]{ getFullEJBClassName(interfaceMethod), p.toString()});
        LOG.log(Level.INFO, "EJB Method called [Methodonly]:{0}

        by " +
        "Principal:

        {1}

        ", new Object[]

        {interfaceMethod.getName(), p.toString()}

        );

        return ctx.proceed();
        }

        Show
        chaoslayer added a comment - Well, shortly before that log message it should also print something from the interceptor method: @AroundInvoke protected Object invoke(final InvocationContext ctx) throws Exception { Principal p = ejbCtx.getCallerPrincipal(); Method interfaceMethod = ctx.getMethod(); LOG.log(Level.INFO, "EJB Method called [Full] :\" {0}\" by " + "Principal:{1}", new Object[]{ getFullEJBClassName(interfaceMethod), p.toString()}); LOG.log(Level.INFO, "EJB Method called [Methodonly] :{0} by " + "Principal: {1} ", new Object[] {interfaceMethod.getName(), p.toString()} ); return ctx.proceed(); }
        Hide
        Sanjeeb Sahoo added a comment -

        I have the fix that Marina has checked in and I see exactly the behavior Marina
        observes. I am not very familiar with interceptors, but whatever little I know,
        I can confirm that it should work. It seems to me that at runtime, interceptors
        are not getting bound to your EJB, which will be a different bug. I doubt it has
        anything to do with OSGi now. Since the test uses InterceptorBinding, here
        GlassFish CDI integration layer could play a role. In fact, I just made a simple
        plain war with your ejbs and interceptors and saw the same behavior. I have
        filed issue 14831 against cdi module in glassfish. You are most welcome to try
        the test case as well. Let's see what the cdi engineer has to say.

        To make others' life easier, let me explain how your test case is set up:

        @WebService
        public class UserServiceWS {

        // @Resource resolves to an OSGi service backed by an EJB reference in GF.
        @Resource UserService svc;
        @WebMethod
        public UserClient findById(long arg0) throws UserServiceFaultException

        { return svc.findById(arg0); }

        }

        @Stateless
        @Secure // interceptor binding
        @Local
        public class UserServiceImpl implements UserService {

        public User findById(long userId) throws EJBException {
        ...
        LOG.log(Level.INFO, "Returning user

        {0}", u);
        }
        }

        @Inherited
        @Target({ TYPE, METHOD })
        @Retention(RUNTIME)
        @InterceptorBinding
        public @interface Secure
        {}

        @Secure
        @Interceptor
        public class SecurityInterceptor implements Serializable
        {
        @AroundInvoke
        protected Object invoke(final InvocationContext ctx) throws Exception
        {
        ...
        LOG.log(Level.INFO, "EJB Method called [Full]:\"{0}

        \" by Principal:

        {1}",
        new Object[]{getFullEJBClassName(interfaceMethod), p.toString()});
        LOG.log(Level.INFO, "EJB Method called [Methodonly]:{0} by
        Principal:{1}

        ", new Object[]

        {interfaceMethod.getName(), p.toString()}

        );

        return ctx.proceed();
        }
        }

        Show
        Sanjeeb Sahoo added a comment - I have the fix that Marina has checked in and I see exactly the behavior Marina observes. I am not very familiar with interceptors, but whatever little I know, I can confirm that it should work. It seems to me that at runtime, interceptors are not getting bound to your EJB, which will be a different bug. I doubt it has anything to do with OSGi now. Since the test uses InterceptorBinding, here GlassFish CDI integration layer could play a role. In fact, I just made a simple plain war with your ejbs and interceptors and saw the same behavior. I have filed issue 14831 against cdi module in glassfish. You are most welcome to try the test case as well. Let's see what the cdi engineer has to say. To make others' life easier, let me explain how your test case is set up: @WebService public class UserServiceWS { // @Resource resolves to an OSGi service backed by an EJB reference in GF. @Resource UserService svc; @WebMethod public UserClient findById(long arg0) throws UserServiceFaultException { return svc.findById(arg0); } } @Stateless @Secure // interceptor binding @Local public class UserServiceImpl implements UserService { public User findById(long userId) throws EJBException { ... LOG.log(Level.INFO, "Returning user {0}", u); } } @Inherited @Target({ TYPE, METHOD }) @Retention(RUNTIME) @InterceptorBinding public @interface Secure {} @Secure @Interceptor public class SecurityInterceptor implements Serializable { @AroundInvoke protected Object invoke(final InvocationContext ctx) throws Exception { ... LOG.log(Level.INFO, "EJB Method called [Full] :\"{0} \" by Principal: {1}", new Object[]{getFullEJBClassName(interfaceMethod), p.toString()}); LOG.log(Level.INFO, "EJB Method called [Methodonly] :{0} by Principal:{1} ", new Object[] {interfaceMethod.getName(), p.toString()} ); return ctx.proceed(); } }

          People

          • Assignee:
            marina vatkina
            Reporter:
            chaoslayer
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: