[cdi-dev] [JBoss JIRA] Updated: (CDI-130) interceptor that return void, unclear in 1.0 specification, needs clarification in 1.1

Richard Hightower (JIRA) jira-events at lists.jboss.org
Mon May 16 02:41:01 EDT 2011


     [ https://issues.jboss.org/browse/CDI-130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Richard Hightower updated CDI-130:
----------------------------------

    Description: 
The specification has an example in 9.5.1 that returns a void. AspectJ/AspectWerks annotation allow this (prior art).


Can interceptors return void? The specification seem unclear on this. Well, it shows an example but there is no further verbiage.


I get three different behaviors for this interceptor:

{{{

package org.cdi.advocacy.security;







import javax.inject.Inject;

import javax.interceptor.AroundInvoke;

import javax.interceptor.Interceptor;

import javax.interceptor.InvocationContext;



/**

 * @author Richard Hightower

 */

@Secure @Interceptor

public class SecurityAdvice {

        

        @Inject

        private SecurityService securityManager;



        @AroundInvoke

        public void checkSecurity(InvocationContext joinPoint) throws Exception {

        

        System.out.println("In SecurityAdvice");

                

            /* If the user is not logged in, don't let them use this method */

            if(!securityManager.isLoggedIn()){            

                throw new SecurityViolationException();

            }



            /* Get the name of the method being invoked. */

            String operationName = joinPoint.getMethod().getName();

            /* Get the name of the object being invoked. */

            String objectName = joinPoint.getTarget().getClass().getName();





           /*

            * Invoke the method or next Interceptor in the list,

            * if the current user is allowed.

            */

            if (!securityManager.isAllowed(objectName, operationName)){

                throw new SecurityViolationException();

            }

        

            joinPoint.proceed();

        }

}

}}}

Weld does not recognize it because it returns void. It fails silently.

Candi recognizes it and uses it.

OpenWebBeans throws an exception as follows:







org.apache.webbeans.exception.WebBeansConfigurationException: @AroundInvoke annotated method : checkSecurity in class : org.cdi.advocacy.security.SecurityAdvice must return Object type

at org.apache.webbeans.util.WebBeansUtil.checkAroundInvokeAnnotationCriterias(WebBeansUtil.java:1094)

at org.apache.webbeans.util.WebBeansUtil.configureInterceptorMethods(WebBeansUtil.java:1241)

at org.apache.webbeans.intercept.WebBeansInterceptorConfig.addMethodInterceptors(WebBeansInterceptorConfig.java:349)

at org.apache.webbeans.intercept.WebBeansInterceptorConfig.configure(WebBeansInterceptorConfig.java:250)

at org.apache.webbeans.config.DefinitionUtil.defineBeanInterceptorStack(DefinitionUtil.java:1058)

at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:365)

at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:326)

at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:179)

at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:123)

at org.cdiadvocate.beancontainer.OpenWebBeansBeanContainer.doStart(OpenWebBeansBeanContainer.java:26)

at org.cdiadvocate.beancontainer.AbstractBeanContainer.start(AbstractBeanContainer.java:111)

at org.cdi.advocacy.AtmMain.<clinit>(AtmMain.java:25)

Exception in thread "main" java.lang.ExceptionInInitializerError

Caused by: org.cdiadvocate.beancontainer.BeanContainerInitializationException: Unable to start BeanContainer : @AroundInvoke annotated method : checkSecurity in class : org.cdi.advocacy.security.SecurityAdvice must return Object type

at org.cdiadvocate.beancontainer.AbstractBeanContainer.start(AbstractBeanContainer.java:113)

at org.cdi.advocacy.AtmMain.<clinit>(AtmMain.java:25)

Caused by: org.apache.webbeans.exception.WebBeansConfigurationException: @AroundInvoke annotated method : checkSecurity in class : org.cdi.advocacy.security.SecurityAdvice must return Object type

at org.apache.webbeans.util.WebBeansUtil.checkAroundInvokeAnnotationCriterias(WebBeansUtil.java:1094)

at org.apache.webbeans.util.WebBeansUtil.configureInterceptorMethods(WebBeansUtil.java:1241)

at org.apache.webbeans.intercept.WebBeansInterceptorConfig.addMethodInterceptors(WebBeansInterceptorConfig.java:349)

at org.apache.webbeans.intercept.WebBeansInterceptorConfig.configure(WebBeansInterceptorConfig.java:250)

at org.apache.webbeans.config.DefinitionUtil.defineBeanInterceptorStack(DefinitionUtil.java:1058)

at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:365)

at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:326)

at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:179)

at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:123)

at org.cdiadvocate.beancontainer.OpenWebBeansBeanContainer.doStart(OpenWebBeansBeanContainer.java:26)

at org.cdiadvocate.beancontainer.AbstractBeanContainer.start(AbstractBeanContainer.java:111)

... 1 more



I think CDI 1.1 should clarify the behavior and I think it should support return types of void.

  was:
The specification has an example in 9.5.1 that returns a void. AspectJ/AspectWerks annotation allow this (prior art).


Can interceptors return void? The specification seem unclear on this. Well, it shows an example but there is no further verbiage.


I get three different behaviors for this interceptor:



package org.cdi.advocacy.security;







import javax.inject.Inject;

import javax.interceptor.AroundInvoke;

import javax.interceptor.Interceptor;

import javax.interceptor.InvocationContext;



/**

 * @author Richard Hightower

 */

@Secure @Interceptor

public class SecurityAdvice {

        

        @Inject

        private SecurityService securityManager;



        @AroundInvoke

        public void checkSecurity(InvocationContext joinPoint) throws Exception {

        

        System.out.println("In SecurityAdvice");

                

            /* If the user is not logged in, don't let them use this method */

            if(!securityManager.isLoggedIn()){            

                throw new SecurityViolationException();

            }



            /* Get the name of the method being invoked. */

            String operationName = joinPoint.getMethod().getName();

            /* Get the name of the object being invoked. */

            String objectName = joinPoint.getTarget().getClass().getName();





           /*

            * Invoke the method or next Interceptor in the list,

            * if the current user is allowed.

            */

            if (!securityManager.isAllowed(objectName, operationName)){

                throw new SecurityViolationException();

            }

        

            joinPoint.proceed();

        }

}



Weld does not recognize it because it returns void. It fails silently.

Candi recognizes it and uses it.

OpenWebBeans throws an exception as follows:







org.apache.webbeans.exception.WebBeansConfigurationException: @AroundInvoke annotated method : checkSecurity in class : org.cdi.advocacy.security.SecurityAdvice must return Object type

at org.apache.webbeans.util.WebBeansUtil.checkAroundInvokeAnnotationCriterias(WebBeansUtil.java:1094)

at org.apache.webbeans.util.WebBeansUtil.configureInterceptorMethods(WebBeansUtil.java:1241)

at org.apache.webbeans.intercept.WebBeansInterceptorConfig.addMethodInterceptors(WebBeansInterceptorConfig.java:349)

at org.apache.webbeans.intercept.WebBeansInterceptorConfig.configure(WebBeansInterceptorConfig.java:250)

at org.apache.webbeans.config.DefinitionUtil.defineBeanInterceptorStack(DefinitionUtil.java:1058)

at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:365)

at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:326)

at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:179)

at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:123)

at org.cdiadvocate.beancontainer.OpenWebBeansBeanContainer.doStart(OpenWebBeansBeanContainer.java:26)

at org.cdiadvocate.beancontainer.AbstractBeanContainer.start(AbstractBeanContainer.java:111)

at org.cdi.advocacy.AtmMain.<clinit>(AtmMain.java:25)

Exception in thread "main" java.lang.ExceptionInInitializerError

Caused by: org.cdiadvocate.beancontainer.BeanContainerInitializationException: Unable to start BeanContainer : @AroundInvoke annotated method : checkSecurity in class : org.cdi.advocacy.security.SecurityAdvice must return Object type

at org.cdiadvocate.beancontainer.AbstractBeanContainer.start(AbstractBeanContainer.java:113)

at org.cdi.advocacy.AtmMain.<clinit>(AtmMain.java:25)

Caused by: org.apache.webbeans.exception.WebBeansConfigurationException: @AroundInvoke annotated method : checkSecurity in class : org.cdi.advocacy.security.SecurityAdvice must return Object type

at org.apache.webbeans.util.WebBeansUtil.checkAroundInvokeAnnotationCriterias(WebBeansUtil.java:1094)

at org.apache.webbeans.util.WebBeansUtil.configureInterceptorMethods(WebBeansUtil.java:1241)

at org.apache.webbeans.intercept.WebBeansInterceptorConfig.addMethodInterceptors(WebBeansInterceptorConfig.java:349)

at org.apache.webbeans.intercept.WebBeansInterceptorConfig.configure(WebBeansInterceptorConfig.java:250)

at org.apache.webbeans.config.DefinitionUtil.defineBeanInterceptorStack(DefinitionUtil.java:1058)

at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:365)

at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:326)

at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:179)

at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:123)

at org.cdiadvocate.beancontainer.OpenWebBeansBeanContainer.doStart(OpenWebBeansBeanContainer.java:26)

at org.cdiadvocate.beancontainer.AbstractBeanContainer.start(AbstractBeanContainer.java:111)

... 1 more



I think CDI 1.1 should clarify the behavior and I think it should support return types of void.



> interceptor that return void, unclear in 1.0 specification, needs clarification in 1.1
> --------------------------------------------------------------------------------------
>
>                 Key: CDI-130
>                 URL: https://issues.jboss.org/browse/CDI-130
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>          Components: Interceptors
>    Affects Versions: 1.1 (Proposed)
>            Reporter: Richard Hightower
>             Fix For: 1.1 (Proposed)
>
>
> The specification has an example in 9.5.1 that returns a void. AspectJ/AspectWerks annotation allow this (prior art).
> Can interceptors return void? The specification seem unclear on this. Well, it shows an example but there is no further verbiage.
> I get three different behaviors for this interceptor:
> {{{
> package org.cdi.advocacy.security;
> import javax.inject.Inject;
> import javax.interceptor.AroundInvoke;
> import javax.interceptor.Interceptor;
> import javax.interceptor.InvocationContext;
> /**
>  * @author Richard Hightower
>  */
> @Secure @Interceptor
> public class SecurityAdvice {
>         
>         @Inject
>         private SecurityService securityManager;
>         @AroundInvoke
>         public void checkSecurity(InvocationContext joinPoint) throws Exception {
>         
>         System.out.println("In SecurityAdvice");
>                 
>             /* If the user is not logged in, don't let them use this method */
>             if(!securityManager.isLoggedIn()){            
>                 throw new SecurityViolationException();
>             }
>             /* Get the name of the method being invoked. */
>             String operationName = joinPoint.getMethod().getName();
>             /* Get the name of the object being invoked. */
>             String objectName = joinPoint.getTarget().getClass().getName();
>            /*
>             * Invoke the method or next Interceptor in the list,
>             * if the current user is allowed.
>             */
>             if (!securityManager.isAllowed(objectName, operationName)){
>                 throw new SecurityViolationException();
>             }
>         
>             joinPoint.proceed();
>         }
> }
> }}}
> Weld does not recognize it because it returns void. It fails silently.
> Candi recognizes it and uses it.
> OpenWebBeans throws an exception as follows:
> org.apache.webbeans.exception.WebBeansConfigurationException: @AroundInvoke annotated method : checkSecurity in class : org.cdi.advocacy.security.SecurityAdvice must return Object type
> at org.apache.webbeans.util.WebBeansUtil.checkAroundInvokeAnnotationCriterias(WebBeansUtil.java:1094)
> at org.apache.webbeans.util.WebBeansUtil.configureInterceptorMethods(WebBeansUtil.java:1241)
> at org.apache.webbeans.intercept.WebBeansInterceptorConfig.addMethodInterceptors(WebBeansInterceptorConfig.java:349)
> at org.apache.webbeans.intercept.WebBeansInterceptorConfig.configure(WebBeansInterceptorConfig.java:250)
> at org.apache.webbeans.config.DefinitionUtil.defineBeanInterceptorStack(DefinitionUtil.java:1058)
> at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:365)
> at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:326)
> at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:179)
> at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:123)
> at org.cdiadvocate.beancontainer.OpenWebBeansBeanContainer.doStart(OpenWebBeansBeanContainer.java:26)
> at org.cdiadvocate.beancontainer.AbstractBeanContainer.start(AbstractBeanContainer.java:111)
> at org.cdi.advocacy.AtmMain.<clinit>(AtmMain.java:25)
> Exception in thread "main" java.lang.ExceptionInInitializerError
> Caused by: org.cdiadvocate.beancontainer.BeanContainerInitializationException: Unable to start BeanContainer : @AroundInvoke annotated method : checkSecurity in class : org.cdi.advocacy.security.SecurityAdvice must return Object type
> at org.cdiadvocate.beancontainer.AbstractBeanContainer.start(AbstractBeanContainer.java:113)
> at org.cdi.advocacy.AtmMain.<clinit>(AtmMain.java:25)
> Caused by: org.apache.webbeans.exception.WebBeansConfigurationException: @AroundInvoke annotated method : checkSecurity in class : org.cdi.advocacy.security.SecurityAdvice must return Object type
> at org.apache.webbeans.util.WebBeansUtil.checkAroundInvokeAnnotationCriterias(WebBeansUtil.java:1094)
> at org.apache.webbeans.util.WebBeansUtil.configureInterceptorMethods(WebBeansUtil.java:1241)
> at org.apache.webbeans.intercept.WebBeansInterceptorConfig.addMethodInterceptors(WebBeansInterceptorConfig.java:349)
> at org.apache.webbeans.intercept.WebBeansInterceptorConfig.configure(WebBeansInterceptorConfig.java:250)
> at org.apache.webbeans.config.DefinitionUtil.defineBeanInterceptorStack(DefinitionUtil.java:1058)
> at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:365)
> at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:326)
> at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:179)
> at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:123)
> at org.cdiadvocate.beancontainer.OpenWebBeansBeanContainer.doStart(OpenWebBeansBeanContainer.java:26)
> at org.cdiadvocate.beancontainer.AbstractBeanContainer.start(AbstractBeanContainer.java:111)
> ... 1 more
> I think CDI 1.1 should clarify the behavior and I think it should support return types of void.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the cdi-dev mailing list