<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>REVERT TO CONSOLE &#187; EJB3</title>
	<atom:link href="http://www.reverttoconsole.com/blog/category/ejb3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.reverttoconsole.com</link>
	<description>for f in *;do echo &#124; sed 'i\rtc' &#62;&#62; $f;done;</description>
	<lastBuildDate>Sat, 10 Jul 2010 12:40:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Example Interceptor in Seam, EJB3</title>
		<link>http://www.reverttoconsole.com/blog/ejb3/example-interceptor-in-seam-ejb3/</link>
		<comments>http://www.reverttoconsole.com/blog/ejb3/example-interceptor-in-seam-ejb3/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 00:00:54 +0000</pubDate>
		<dc:creator>Priyatam</dc:creator>
				<category><![CDATA[EJB3]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/?p=198</guid>
		<description><![CDATA[It&#8217;s insanely easy to write an interceptor in EJB3. Here&#8217;s a tutorial/example code for an interceptor which collects statistics info around a method invocation. import java.util.Collection; import javax.interceptor.AroundInvoke; import javax.interceptor.InvocationContext; import org.apache.commons.lang.time.StopWatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class StatisticsInterceptor { private static final Log log = LogFactory .getLog(StatisticsInterceptor.class); @AroundInvoke @SuppressWarnings(&#34;unchecked&#34;) public Object intercept(InvocationContext ctx) throws [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s insanely easy to write an interceptor in EJB3. Here&#8217;s a tutorial/example code for an interceptor which collects statistics info around a method invocation.</p>
<pre class="brush: java">import java.util.Collection;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class StatisticsInterceptor {
	private static final Log log = LogFactory
			.getLog(StatisticsInterceptor.class);

	@AroundInvoke
	@SuppressWarnings(&quot;unchecked&quot;)
	public Object intercept(InvocationContext ctx) throws Exception {
		StopWatch stopWatch = new StopWatch();
		stopWatch.start();
		Object result = ctx.proceed();
		log.debug(&quot;Statistics for &quot;
				+ ctx.getMethod().getDeclaringClass().getSimpleName() + &quot;.&quot;
				+ ctx.getMethod().getName());
		log.debug(&quot;\tTime = &quot; + stopWatch);
		if (result instanceof String) {
			log.debug(&quot;\tValue returned = &quot; + result);
		}
		if (result instanceof Collection) {
			Collection col = (Collection) result;
			log.debug(&quot;\tSize of collection returned = &quot; + col.size());
		}
		return result;
	}
}
</pre>
<p>The only place, this needs to be added is in ejb-jar.xml</p>
<pre class="brush: xml">
&lt;assembly-descriptor&gt;
      &lt;interceptor-binding&gt;
         &lt;ejb-name&gt;*&lt;/ejb-name&gt;
         &lt;interceptor-class&gt;org.jboss.seam.ejb.SeamInterceptor&lt;/interceptor-class&gt;
      &lt;/interceptor-binding&gt;
      &lt;interceptor-binding&gt;
         &lt;ejb-name&gt;*&lt;/ejb-name&gt;
         &lt;interceptor-class&gt;com.evergreen.asr.util.StatisticsInterceptor&lt;/interceptor-class&gt;
      &lt;/interceptor-binding&gt;
   &lt;/assembly-descriptor&gt;
</pre>
<p>That&#8217;s it.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fejb3%2Fexample-interceptor-in-seam-ejb3%2F&amp;title=Example+Interceptor+in+Seam%2C+EJB3" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fejb3%2Fexample-interceptor-in-seam-ejb3%2F&amp;title=Example+Interceptor+in+Seam%2C+EJB3" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fejb3%2Fexample-interceptor-in-seam-ejb3%2F&amp;title=Example+Interceptor+in+Seam%2C+EJB3" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fejb3%2Fexample-interceptor-in-seam-ejb3%2F&amp;title=Example+Interceptor+in+Seam%2C+EJB3" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fejb3%2Fexample-interceptor-in-seam-ejb3%2F&amp;title=Example+Interceptor+in+Seam%2C+EJB3', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fejb3%2Fexample-interceptor-in-seam-ejb3%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fejb3%2Fexample-interceptor-in-seam-ejb3%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fejb3%2Fexample-interceptor-in-seam-ejb3%2F&amp;title=Example+Interceptor+in+Seam%2C+EJB3" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fejb3%2Fexample-interceptor-in-seam-ejb3%2F&amp;title=Example+Interceptor+in+Seam%2C+EJB3" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/ejb3/example-interceptor-in-seam-ejb3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
