<?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>Berthou.com &#187; Uncategorized</title>
	<atom:link href="http://www.berthou.com/us/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.berthou.com/us</link>
	<description>A french developper blog</description>
	<lastBuildDate>Mon, 09 Aug 2010 08:55:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>A ServletFilter to monitor the execution state of a JSP.</title>
		<link>http://www.berthou.com/us/2009/02/14/a-servletfilter-to-monitor-the-execution-state-of-a-jsp/</link>
		<comments>http://www.berthou.com/us/2009/02/14/a-servletfilter-to-monitor-the-execution-state-of-a-jsp/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 18:08:31 +0000</pubDate>
		<dc:creator>rberthou</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[websphere]]></category>

		<guid isPermaLink="false">http://www.berthou.com/us/2009/02/14/a-servletfilter-to-monitor-the-execution-state-of-a-jsp/</guid>
		<description><![CDATA[The reasons of this little project Recently I had a little problem on a Websphere application server. A JSP page running on this application server had a problem (a no ending loop). This was a bit hard to identify because noting permit to isolate on this server the pages running. To solve this lake of [...]]]></description>
				<content:encoded><![CDATA[<h2 class="titre2">The reasons of this little project</h2>
<p>Recently I had a little problem on a Websphere application server. A JSP page running on this application server had a problem (a no ending loop). This was a bit hard to identify because noting permit to isolate on this server the pages running.<br />
To solve this lake of informations I realized a little  Servletfilter which permit to monitor this.<br />
I propose you this little tool for exemple as a ServletFilter. I wish it would be useful to you.<br />
<br/><br/></p>
<p><img src="/_img/StatsFilter_0.png" class="center" /><br />
<span id="more-51"></span></p>
<h2 class="titre2">The goal of the project.</h2>
<p>It consist to put in a HashTable the running pages. I also had some others informations which permit me to offer some more statistics (execution time, number of errors, number of executions&#8230;)<br />
A JSP page display the informations of this Hashtable.</p>
<p>The use of this filter allows me to add this option to the whole webapps without changing the actif code (only the file web.xml which have to be modifiate to activate the filter).<br />
<br/><br/></p>
<h2 class="titre2">Project source</h2>
<p>The whole source code is avaible to download. The application is composed of three smalls classes :</p>
<h3 class="titre3">StatsFilter.java : The filter</h3>
<p>Little class doing all his work in the method<strong>doFilter</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.berthou.web.filtre</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> StatsFilter <span style="color: #000000; font-weight: bold;">implements</span> Filter <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> FilterConfig filterConfig <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> appli <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doFilter<span style="color: #009900;">&#40;</span>ServletRequest request, ServletResponse response,
        FilterChain chain<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, ServletException <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>filterConfig <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>  <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">String</span> key <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">;</span>
    	<span style="color: #000066; font-weight: bold;">long</span> startTime <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
    		key <span style="color: #339933;">=</span> appli <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpServletRequest<span style="color: #009900;">&#41;</span>request<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getServletPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
    		<span style="color: #666666; font-style: italic;">// On ajoute la page dans la liste des pages en cours</span>
    		MonitorJsp.<span style="color: #006633;">action</span><span style="color: #009900;">&#40;</span> MonitorJsp.<span style="color: #006633;">ACT_ADD</span>, key, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
    		chain.<span style="color: #006633;">doFilter</span><span style="color: #009900;">&#40;</span>request, response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    		<span style="color: #666666; font-style: italic;">// On supprime la page dans la liste des pages en cours (+temsp d'execution)</span>
    		MonitorJsp.<span style="color: #006633;">action</span><span style="color: #009900;">&#40;</span> MonitorJsp.<span style="color: #006633;">ACT_DEL</span>, key, <span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> startTime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> io<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    		<span style="color: #666666; font-style: italic;">// Une erreur ce produit =&gt; on la trace puis on la renvoie</span>
    		MonitorJsp.<span style="color: #006633;">action</span><span style="color: #009900;">&#40;</span> MonitorJsp.<span style="color: #006633;">ACT_ERR</span>, key, <span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> startTime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
    		<span style="color: #000000; font-weight: bold;">throw</span> io <span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>ServletException se<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    		<span style="color: #666666; font-style: italic;">// Une erreur ce produit =&gt; on la trace puis on la renvoie</span>
    		MonitorJsp.<span style="color: #006633;">action</span><span style="color: #009900;">&#40;</span> MonitorJsp.<span style="color: #006633;">ACT_ERR</span>, key, <span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> startTime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
    		<span style="color: #000000; font-weight: bold;">throw</span> se <span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Lecture des paramètres d'exécution (dans web.xml)
     *  Ici uniquement la zone APPLICATION
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span>FilterConfig filterConfig<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">filterConfig</span> <span style="color: #339933;">=</span> filterConfig<span style="color: #339933;">;</span>
	appli <span style="color: #339933;">=</span> filterConfig.<span style="color: #006633;">getInitParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;APPLICATION&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> destroy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">filterConfig</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3 class="titre3">MonitorJsp.java : The monitor</h3>
<p>It is a static class of supervision (it is possible to change to a singleton)</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.berthou.web.filtre</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.text.SimpleDateFormat</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Classe de suppervision permettant de suivre l'état de certains objets
 * c'est un classe &lt;b&gt;static&lt;/b&gt;
 *
 * @author rberthou
 *
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MonitorJsp <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> version <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;MonitorJsp V1.00 du 4 Septembre 2008&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Hashtable</span> map <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Hashtable</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> ACT_ADD <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> ACT_DEL <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> ACT_ERR <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span> <span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #000066; font-weight: bold;">void</span> action<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> act, <span style="color: #003399;">String</span> key, <span style="color: #000066; font-weight: bold;">long</span> delay<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    	ItemMonitor itm <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ItemMonitor<span style="color: #009900;">&#41;</span>map.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
    	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> itm <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>act <span style="color: #339933;">==</span> ACT_ADD<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    			itm <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ItemMonitor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
    			map.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>key, itm<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
    		<span style="color: #009900;">&#125;</span>
    	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>act <span style="color: #339933;">==</span> ACT_ADD<span style="color: #009900;">&#41;</span> itm.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> 	       <span style="color: #000000; font-weight: bold;">else</span>
   			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>act <span style="color: #339933;">==</span> ACT_DEL<span style="color: #009900;">&#41;</span> itm.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>delay<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">else</span>
   			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>act <span style="color: #339933;">==</span> ACT_ERR<span style="color: #009900;">&#41;</span> itm.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>delay<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    ..... <span style="color: #009900;">&#91;</span>CUT<span style="color: #009900;">&#93;</span> ....
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3 class="titre3">ItemMonitor.java : The data</h3>
<p>It is a representation of a list of element.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.berthou.web.filtre</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ItemMonitor <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> nbrun  <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>  <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Nombre d'execution</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> nbact <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// Nombre de page active</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> nberr <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// Nombre d'erreur</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> mints <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// Temps min</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> maxts <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// Temps Max</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> lastAcc <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// date last exec</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Constructeur
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> ItemMonitor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> reset<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		nbrun  <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>  <span style="color: #339933;">;</span>
		nberr <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span>
		mints <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span>
		maxts <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> add<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		nbact<span style="color: #339933;">++</span> <span style="color: #339933;">;</span>
		lastAcc <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> remove<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> delay<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		nbrun<span style="color: #339933;">++</span> <span style="color: #339933;">;</span>
		nbact<span style="color: #339933;">--</span> <span style="color: #339933;">;</span>
&nbsp;
		sumts <span style="color: #339933;">+=</span> delay <span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mints <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">||</span> delay <span style="color: #339933;">&lt;</span> mints<span style="color: #009900;">&#41;</span> mints <span style="color: #339933;">=</span> delay <span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>delay <span style="color: #339933;">&gt;</span> maxts<span style="color: #009900;">&#41;</span> maxts <span style="color: #339933;">=</span> delay <span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> error<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> delay<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		nberr<span style="color: #339933;">++</span> <span style="color: #339933;">;</span>
		nbact<span style="color: #339933;">--</span> <span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
      ..... <span style="color: #009900;">&#91;</span>CUT<span style="color: #009900;">&#93;</span> .....
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><br/><br/></p>
<h2 class="titre2">Utilisation</h2>
<p>To use this filter you have to :</p>
<ul>
<li>Add the archive .jar in the collective librairies of your application server. (Be careful: if you put it at once in your directory /WEB-INF/lib of your webapp it will only work for this application.)</li>
<li>Change the file web.xml to parameter this filter (exemple just below). </li>
</ul>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>StatsFilter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.berthou.web.flitre.StatsFilter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>APPLICATION<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>TEST1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>StatsFilter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>It allows you to identify the filter in your webapp. You just have to write a JSP page as the one below to display the current datas</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ <span style="color: #000000; font-weight: bold;">import</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.berthou.web.filtre.*,java.util.*&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>
	<span style="color: #666666; font-style: italic;">// Get iterator for keys in HashMap</span>
	<span style="color: #003399;">Hashtable</span> monitorSession <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Hashtable</span><span style="color: #009900;">&#41;</span>MonitorJsp.<span style="color: #006633;">cloneIt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">Iterator</span> sessionIter     <span style="color: #339933;">=</span> monitorSession.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span> id <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">;</span>
	ItemMonitor itm <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">;</span>
<span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;</span>table<span style="color: #339933;">&gt;&lt;</span>thead<span style="color: #339933;">&gt;&lt;</span>tr<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>id<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>act<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>run<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>err<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>last<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>min<span style="color: #339933;">/</span>max<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>Sum<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;&lt;/</span>thead<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tbody<span style="color: #339933;">&gt;&lt;%</span>
<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>sessionIter.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  id <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span>sessionIter.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  itm <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ItemMonitor<span style="color: #009900;">&#41;</span>monitorSession.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">try</span>
  <span style="color: #009900;">&#123;</span>
		<span style="color: #339933;">%&gt;&lt;</span>tr valign<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;top&quot;</span><span style="color: #339933;">&gt;&lt;</span>td <span style="color: #339933;">&gt;&lt;%=</span>id<span style="color: #339933;">%&gt;&lt;/</span>td<span style="color: #339933;">&gt;&lt;%=</span>itm.<span style="color: #006633;">toHtmlString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">%&gt;&lt;/</span>tr<span style="color: #339933;">&gt;&lt;%</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">IllegalStateException</span> ie <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;/</span>tbody<span style="color: #339933;">&gt;&lt;/</span>table<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><br/><br/></p>
<h2 class="titre2">Attention</h2>
<p>I use a static class which is <strong>&#8220;synchronized&#8221;</strong>. You have to be careful about the goulot d&#8217;étranglement for the application server with a huge traffic. Personnaly I use this in a production server (intranet ) without any problems.<br />
<br/><br/></p>
<h2 class="titre2">Downloads</h2>
<p class="alertDownload">
<a href="/download.php?type=java&#038;file=StatsFilter.zip">StatsFilter.zip le code Source</a><br />
<a href="/download.php?type=java&#038;file=StatsFilter.jar">StatsFilter.jar la librairie</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.berthou.com/us/2009/02/14/a-servletfilter-to-monitor-the-execution-state-of-a-jsp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
