<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<tt>The interceptors spec says this about @AroundInvoke methods on
interceptors:<br>
<br>
<quote><br>
Around-invoke methods have the following signature:<br>
<br>
Object <METHOD>(InvocationContext) throws Exception<br>
<br>
</quote><br>
<br>
By the way, if Weld is failing silently, then I guess it needs to
be improved to throw an explicit error.<br>
<br>
-Jaikiran<br>
On Monday 16 May 2011 12:06 PM, Rick Hightower wrote:</tt>
<blockquote
cite="mid:BANLkTi=KUyRxFn8mxGgjTQFjO0s3vYR52w@mail.gmail.com"
type="cite">
<div>
<meta charset="utf-8">
<tt><span class="Apple-style-span" style="font-family:
Helvetica; font-size: 12px;">The specification has an
example in 9.5.1 that returns a void. AspectJ/AspectWerks
annotation allow this (prior art).</span></tt></div>
<div><tt><span class="Apple-style-span" style="font-family:
Helvetica; font-size: 12px;"><br>
</span></tt></div>
<div><tt><font class="Apple-style-span"><span
class="Apple-style-span" style="font-size: 12px;"><br>
</span></font></tt></div>
<tt>
Can interceptors return void? The specification seem unclear on
this. Well, it shows an example but there is no further
verbiage.</tt>
<div><tt><br>
</tt>
<div><tt><br>
</tt></div>
<div>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1038.35">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #5574c7}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #777777}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4f9073}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #ff1b18}
span.s1 {color: #921167}
span.s2 {color: #92afc9}
span.s3 {text-decoration: underline}
span.s4 {color: #000000}
span.s5 {color: #777777}
span.s6 {color: #211cc7}
span.s7 {color: #4726f9}
span.s8 {color: #4f9073}
span.s9 {text-decoration: underline ; color: #14118f}
span.Apple-tab-span {white-space:pre}
</style>
<p class="p1"><tt>I get three different behaviors for this
interceptor:</tt></p>
<p class="p2"><tt><br>
</tt></p>
<p class="p3"><tt><span class="s1">package</span>
org.cdi.advocacy.security;</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p3"><tt><span class="s1">import</span>
javax.inject.Inject;</tt></p>
<p class="p3"><tt><span class="s1">import</span>
javax.interceptor.AroundInvoke;</tt></p>
<p class="p3"><tt><span class="s1">import</span>
javax.interceptor.Interceptor;</tt></p>
<p class="p3"><tt><span class="s1">import</span>
javax.interceptor.InvocationContext;</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p5"><tt>/**</tt></p>
<p class="p5"><tt> * <span class="s2">@author</span> <span
class="s3">Richard</span> <span class="s3">Hightower</span></tt></p>
<p class="p5"><tt> */</tt></p>
<p class="p6"><tt>@Secure<span class="s4"> </span>@Interceptor</tt></p>
<p class="p3"><tt><span class="s1">public</span> <span
class="s1">class</span> SecurityAdvice {</tt></p>
<p class="p3"><tt> </tt></p>
<p class="p3"><tt> <span class="s5">@Inject</span></tt></p>
<p class="p3"><tt> <span class="s1">private</span>
SecurityService <span class="s6">securityManager</span>;</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p6"><tt><span class="s4"> </span>@AroundInvoke</tt></p>
<p class="p3"><tt> <span class="s1">public</span> <span
class="s1">void</span> checkSecurity(InvocationContext
joinPoint) <span class="s1">throws</span> Exception {</tt></p>
<p class="p3"><tt> <span class="Apple-tab-span"> </span></tt></p>
<p class="p3"><tt> <span class="Apple-tab-span"> </span>System.<span
class="s6">out</span>.println(<span class="s7">"In
SecurityAdvice"</span>);</tt></p>
<p class="p3"><tt> </tt></p>
<p class="p7"><tt><span class="s4"> </span>/* If
the user is not logged in, don't let them use this method
*/</tt></p>
<p class="p3"><tt> <span class="s1">if</span>(!<span
class="s6">securityManager</span>.isLoggedIn()){
</tt></p>
<p class="p3"><tt> <span class="s1">throw</span>
<span class="s1">new</span> SecurityViolationException();</tt></p>
<p class="p3"><tt> }</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p7"><tt><span class="s4"> </span>/* Get
the name of the method being invoked. */</tt></p>
<p class="p3"><tt> String operationName =
joinPoint.getMethod().getName();</tt></p>
<p class="p7"><tt><span class="s4"> </span>/* Get
the name of the object being invoked. */</tt></p>
<p class="p3"><tt> String objectName =
joinPoint.getTarget().getClass().getName();</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p3"><tt> <span class="s8">/*</span></tt></p>
<p class="p7"><tt> * Invoke the method or next <span
class="s3">Interceptor</span> in the list,</tt></p>
<p class="p7"><tt> * if the current user is
allowed.</tt></p>
<p class="p7"><tt> */</tt></p>
<p class="p3"><tt> <span class="s1">if</span> (!<span
class="s6">securityManager</span>.isAllowed(objectName,
operationName)){</tt></p>
<p class="p3"><tt> <span class="s1">throw</span>
<span class="s1">new</span> SecurityViolationException();</tt></p>
<p class="p3"><tt> }</tt></p>
<p class="p3"><tt> </tt></p>
<p class="p3"><tt> joinPoint.proceed();</tt></p>
<p class="p3"><tt> }</tt></p>
<p class="p3"><tt>}</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p3"><tt>Weld does not recognize it because it
returns void. It fails silently.</tt></p>
<p class="p3"><tt>Candi recognizes it and uses it.</tt></p>
<p class="p3"><tt>OpenWebBeans throws an exception as follows:</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p4"><tt><br>
</tt></p>
<p class="p8"><tt><span class="s9">org.apache.webbeans.exception.WebBeansConfigurationException</span>:
@AroundInvoke annotated method : checkSecurity in class :
org.cdi.advocacy.security.SecurityAdvice must return
Object type</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.util.WebBeansUtil.checkAroundInvokeAnnotationCriterias(<span
class="s9">WebBeansUtil.java:1094</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.util.WebBeansUtil.configureInterceptorMethods(<span
class="s9">WebBeansUtil.java:1241</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.intercept.WebBeansInterceptorConfig.addMethodInterceptors(<span
class="s9">WebBeansInterceptorConfig.java:349</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.intercept.WebBeansInterceptorConfig.configure(<span
class="s9">WebBeansInterceptorConfig.java:250</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.config.DefinitionUtil.defineBeanInterceptorStack(<span
class="s9">DefinitionUtil.java:1058</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.config.BeansDeployer.validate(<span
class="s9">BeansDeployer.java:365</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(<span
class="s9">BeansDeployer.java:326</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.config.BeansDeployer.deploy(<span
class="s9">BeansDeployer.java:179</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(<span
class="s9">AbstractLifeCycle.java:123</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.cdiadvocate.beancontainer.OpenWebBeansBeanContainer.doStart(<span
class="s9">OpenWebBeansBeanContainer.java:26</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.cdiadvocate.beancontainer.AbstractBeanContainer.start(<span
class="s9">AbstractBeanContainer.java:111</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.cdi.advocacy.AtmMain.<clinit>(<span class="s9">AtmMain.java:25</span>)</tt></p>
<p class="p8"><tt>Exception in thread "main"
java.lang.ExceptionInInitializerError</tt></p>
<p class="p8"><tt>Caused by: <span class="s9">org.cdiadvocate.beancontainer.BeanContainerInitializationException</span>:
Unable to start BeanContainer : @AroundInvoke annotated
method : checkSecurity in class :
org.cdi.advocacy.security.SecurityAdvice must return
Object type</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.cdiadvocate.beancontainer.AbstractBeanContainer.start(<span
class="s9">AbstractBeanContainer.java:113</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.cdi.advocacy.AtmMain.<clinit>(<span class="s9">AtmMain.java:25</span>)</tt></p>
<p class="p8"><tt>Caused by: <span class="s9">org.apache.webbeans.exception.WebBeansConfigurationException</span>:
@AroundInvoke annotated method : checkSecurity in class :
org.cdi.advocacy.security.SecurityAdvice must return
Object type</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.util.WebBeansUtil.checkAroundInvokeAnnotationCriterias(<span
class="s9">WebBeansUtil.java:1094</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.util.WebBeansUtil.configureInterceptorMethods(<span
class="s9">WebBeansUtil.java:1241</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.intercept.WebBeansInterceptorConfig.addMethodInterceptors(<span
class="s9">WebBeansInterceptorConfig.java:349</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.intercept.WebBeansInterceptorConfig.configure(<span
class="s9">WebBeansInterceptorConfig.java:250</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.config.DefinitionUtil.defineBeanInterceptorStack(<span
class="s9">DefinitionUtil.java:1058</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.config.BeansDeployer.validate(<span
class="s9">BeansDeployer.java:365</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(<span
class="s9">BeansDeployer.java:326</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.config.BeansDeployer.deploy(<span
class="s9">BeansDeployer.java:179</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(<span
class="s9">AbstractLifeCycle.java:123</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.cdiadvocate.beancontainer.OpenWebBeansBeanContainer.doStart(<span
class="s9">OpenWebBeansBeanContainer.java:26</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>at
org.cdiadvocate.beancontainer.AbstractBeanContainer.start(<span
class="s9">AbstractBeanContainer.java:111</span>)</tt></p>
<p class="p8"><tt><span class="Apple-tab-span"> </span>... 1
more</tt></p>
<p class="p2"><tt><br>
</tt></p>
<p class="p1"><tt>I think CDI 1.1 should clarify the behavior
and I think it should support return types of void.</tt></p>
<tt>-- <br>
<b>Rick Hightower</b><br>
(415) 968-9037 <br>
<a moz-do-not-send="true"
href="http://www.google.com/profiles/RichardHightower"
target="_blank">Profile</a> <br>
<br>
</tt>
</div>
</div>
<pre wrap=""><tt>
</tt><fieldset class="mimeAttachmentHeader"></fieldset><tt>
_______________________________________________
cdi-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/cdi-dev">https://lists.jboss.org/mailman/listinfo/cdi-dev</a>
</tt></pre>
</blockquote>
<tt><br>
</tt>
</body>
</html>