<?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>Everything is wrong &#187; AOP</title>
	<atom:link href="http://everythingiswrong.free.fr/index.php/tag/aop/feed/" rel="self" type="application/rss+xml" />
	<link>http://everythingiswrong.free.fr</link>
	<description>Un blog dédié à l&#039;informatique en général</description>
	<lastBuildDate>Wed, 06 Oct 2021 21:20:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>EJB3 : intercepteurs</title>
		<link>http://everythingiswrong.free.fr/index.php/2011/01/21/ejb3-intercepteurs/</link>
		<comments>http://everythingiswrong.free.fr/index.php/2011/01/21/ejb3-intercepteurs/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 21:47:17 +0000</pubDate>
		<dc:creator>Yan</dc:creator>
				<category><![CDATA[Conteneurs embarqués]]></category>
		<category><![CDATA[Java J2EE]]></category>
		<category><![CDATA[AOP]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[openEJB]]></category>

		<guid isPermaLink="false">http://yan.langlois.free.fr/wordpress/?p=793</guid>
		<description><![CDATA[Intercepteur EJB3]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Les intercepteurs sont des petits programmes qui interviennent avant et après l&#8217;exécution d&#8217;une méthode. ils permettent de faire de la programmation orientée AOP sur les méthodes publics des EJB. Il est possible de s&#8217;en servir pour logger les entrées et sorties d&#8217;une méthode comme je le propose dans mon <a href="https://subversion.assembla.com/svn/everythingiswrong/tutorial-interceptor-openejb" target="_blank">exemple</a> qui se base sur un simple &#8220;HelloWorld&#8221; en EJB3. J&#8217;utilise openEJB pour simplifier l&#8217;exécution et vous permettre d&#8217;utiliser l&#8217;exemple tel quel.</p>
<p style="text-align: justify;"><span style="text-decoration: underline;">Création de l&#8217;intercepteur</span> : c&#8217;est un EJB standard avec une méthode public annotée avec <em>@AroundInvoke</em>.</p>
<pre class="brush:java;toolbar: true;">public @Stateless class LoggerServiceBean implements LoggerService {
    @AroundInvoke
    public Object c(InvocationContext ctx) throws Exception {
        // Affiche le nom de la méthode
        System.out.println(ctx.getMethod().toGenericString());
        // Liste les paramètres passés à la méthode
        for (int i = 0; i &lt; ctx.getParameters().length; i++) {
            if (i != 0) {
                System.out.print(",");
            }
            System.out.print("parameter " + i +" : " + ctx.getParameters()[i]);
        }
        System.out.println();
        return ctx.proceed(); //Exécute de la méthode
    }
}</pre>
<p style="text-align: justify;">Comme vous pouvez le voir, c&#8217;est l&#8217;objet InvocationContext qui va vous permettre de visualiser la méthode et les paramètres utilisés.</p>
<p style="text-align: justify;"><span style="text-decoration: underline;">Déclaration de l&#8217;EJB en tant qu&#8217;intercepteur</span> : ajouter ces quelques lignes dans le fichier META-INF/ejb-jar.xml :</p>
<pre class="brush:xml;toolbar: true;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
    version="3.0"&gt;

  &lt;interceptors&gt;
    &lt;interceptor&gt;
      &lt;interceptor-class&gt;org.everythingiswrong.tutorial.interceptor_openejb.interceptor.LoggerServiceBean&lt;/interceptor-class&gt;
    &lt;/interceptor&gt;
  &lt;/interceptors&gt;

  &lt;assembly-descriptor&gt;
    &lt;interceptor-binding&gt;
      &lt;ejb-name&gt;*&lt;/ejb-name&gt;
      &lt;interceptor-class&gt;org.everythingiswrong.tutorial.interceptor_openejb.interceptor.LoggerServiceBean&lt;/interceptor-class&gt;
    &lt;/interceptor-binding&gt;
  &lt;/assembly-descriptor&gt;

&lt;/ejb-jar&gt;</pre>
<p>Voici l&#8217;adresse SVN du projet : <a href="https://subversion.assembla.com/svn/everythingiswrong/tutorial-interceptor-openejb" target="_blank">https://subversion.assembla.com/svn/everythingiswrong/tutorial-interceptor-openejb</a></p>
]]></content:encoded>
			<wfw:commentRss>http://everythingiswrong.free.fr/index.php/2011/01/21/ejb3-intercepteurs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
