glassfish
  1. glassfish
  2. GLASSFISH-20914

Unable to get @InterceptorBinding working

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.0
    • Fix Version/s: None
    • Component/s: cdi
    • Labels:
      None

      Description

      I have created a InterceptorBinding annotation

      @Inherited
      @InterceptorBinding
      @Target(

      { TYPE, METHOD }

      )
      @Retention(RUNTIME)
      public @interface BusinessMethod { }

      And the following interceptor

      @BusinessMethod
      @Interceptor
      public class LoggingInterceptor {
      private static final Logger log = Logger.getLogger("net.trajano.app");
      @AroundInvoke
      public Object log(final InvocationContext ctx) throws Throwable {
      log.warning("around invoke " + ctx.getMethod());
      try

      { return ctx.proceed(); }

      catch (final Throwable e)

      { log.severe("Error calling ctx.proceed in " + ctx.getMethod()); throw e; }

      }
      }

      In my SLSB I have added the annotation

      @Stateless
      @BusinessMethod
      public class PersistedBeans

      However, the interceptor methods do not work. Explicitly listing the interceptor using @Interceptors(LoggingInterceptor.class) works thouhg.

        Activity

        Hide
        atrajano added a comment -

        Seems you require adding it to the beans.xml

        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
        version="1.1" bean-discovery-mode="annotated">
        <interceptors>
        <class>net.trajano.app.internal.LoggingInterceptor</class>
        </interceptors>
        </beans>

        Not sure if that is required by the spec or not, it didn't seem to take the CDI scopes into consideration.

        Please close if that is the expected behaviour.

        Show
        atrajano added a comment - Seems you require adding it to the beans.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd " version="1.1" bean-discovery-mode="annotated"> <interceptors> <class>net.trajano.app.internal.LoggingInterceptor</class> </interceptors> </beans> Not sure if that is required by the spec or not, it didn't seem to take the CDI scopes into consideration. Please close if that is the expected behaviour.
        Hide
        reza_rahman added a comment -

        This is unfortunately a known issue with the CDI spec: https://issues.jboss.org/browse/CDI-404. Hope this helps.

        Show
        reza_rahman added a comment - This is unfortunately a known issue with the CDI spec: https://issues.jboss.org/browse/CDI-404 . Hope this helps.
        Hide
        jjsnyder83 added a comment -

        Add @Dependent to your interceptor definition. As stated previously there is a problem with the spec but according to the previously mentioned jira adding @Dependent should resolve your issue.

        Show
        jjsnyder83 added a comment - Add @Dependent to your interceptor definition. As stated previously there is a problem with the spec but according to the previously mentioned jira adding @Dependent should resolve your issue.

          People

          • Assignee:
            jjsnyder83
            Reporter:
            atrajano
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: