Details

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

      Operating System: All
      Platform: All

    • Issuezilla Id:
      14,831

      Description

      This issue is filed subsequent to the discussion in issue 13513 . It seems CDI
      interceptor bindings are not working for EJBs. I have simplified the test case
      from issue 13513 to remove OSGi from the picture and converted it to a simple
      web application with a Servlet calling a local EJB which has some interceptors
      as shown below;

      @WebServlet(urlPatterns="/*")
      public class MyServlet extends HttpServlet {
      @EJB UserService svc;

      public void service(ServletRequest req, ServletResponse res)

      { svc.findById(0); // call the ejb }

      }

      @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();
      }
      }

      If unzip the attached interceptor-ejb-cdi-test.zip, it creates
      interceptor-ejb-cdi-test directory. Try the following:
      cd interceptor-ejb-cdi-test
      ./run.sh (this will compile, deploy and run the servlet)
      See the server.log, you shall not find any message from the interceptor.

      Now, open
      ./WEB-INF/classes/org/glassfish/cditest/user/impl/UserServiceImpl.java,
      uncomment the following line:
      @javax.interceptor.Interceptors(org.glassfish.cditest.security.interceptor.SecurityInterceptor.class)

      and run ./run.sh again. This time in server.log, you shall see interceptor
      message. As per the javadocs[1]:
      "If the target class is a CDI bean, by annotating both the interceptor class and
      the target class with an interceptor binding. "

      and as per CDI javadoc [2]:

      "Interceptors may be bound to any managed bean that is not itself an
      interceptor or decorator or to any EJB session or message-driven bean. An
      interceptor that is annotated @Interceptor may be identified by its interceptor
      bindings."

      [1]
      http://download.oracle.com/javaee/6/api/javax/interceptor/package-summary.html#package_description
      [2]
      http://download.oracle.com/javaee/6/api/javax/enterprise/inject/package-summary.html

      1. GLASSFISH-14831.diff
        0.7 kB
        Sivakumar Thyagarajan

        Activity

          People

          • Assignee:
            Sivakumar Thyagarajan
            Reporter:
            Sanjeeb Sahoo
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: