[cdi-dev] [JBoss JIRA] Commented: (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 03:09:00 EDT 2011
[ https://issues.jboss.org/browse/CDI-130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12602205#comment-12602205 ]
Richard Hightower commented on CDI-130:
---------------------------------------
Someone commented that the interceptor spec says that the interceptor should return Object, however, the CDI does have some examples that return void....
Ok... I missed that. There is still an example that shows a void return type interceptor and there is some prior art along these lines. So I guess I am still, asking that this be a feature request for CDI 1.1.
https://issues.jboss.org/browse/CDI-130
This works in Spring:
package com.arcmind.springquickstart.security;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
/**
* @author Richard Hightower
*/
@Component
public class SecurityAdvice {
@Autowired(required=true)
@Qualifier ("manager")
private SecurityService securityManager;
public void checkSecurity(ProceedingJoinPoint joinPoint) throws Throwable {
/* 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.getSignature().getName();
/* Get the name of the object being invoked. */
String objectName = joinPoint.getThis().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();
}
/**
* @return Returns the manager.
*/
public SecurityService getSecurityManager() {
return securityManager;
}
/**
* @param manager The manager to set.
*/
public void setSecurityManager(SecurityService manager) {
this.securityManager = manager;
}
}
> 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