<?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; websphere</title>
	<atom:link href="http://www.berthou.com/us/tag/websphere/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>
		<item>
		<title>Websphere &#8211; Secure administration console</title>
		<link>http://www.berthou.com/us/2008/02/18/websphere-secure-administration-console/</link>
		<comments>http://www.berthou.com/us/2008/02/18/websphere-secure-administration-console/#comments</comments>
		<pubDate>Mon, 18 Feb 2008 10:03:31 +0000</pubDate>
		<dc:creator>rberthou</dc:creator>
				<category><![CDATA[websphere]]></category>

		<guid isPermaLink="false">http://www.berthou.com/us/2008/02/18/websphere-secure-administration-console/</guid>
		<description><![CDATA[The probleme During his installation Websphere is configure to accep all the users identification (wihout passwords) to accede to the administration console. You can type anything it goes perfectly, there is no verification. This is of course unacceptable and in the recent versions, a &#8216;wizard&#8221; lead you to activate the global security. But it activates [...]]]></description>
				<content:encoded><![CDATA[<h2 class="titre2">The probleme</h2>
<p><img src="/_img/was_secu_1.png" alt="Connexion without user identification" class="right"/><br />
During his installation Websphere is configure to accep all the users identification (wihout passwords) to accede to the administration console.<br />
You can type anything it goes perfectly, there is no verification.<br />
This is of course unacceptable and in the recent versions, a &#8216;wizard&#8221; lead you to activate the global security. But it activates all the J2EE security what is most of the time useless.<br />
<br/><br />
The goal of this little article is to explain you  (I hope in a clear way) how to securate the access to the WAS administration console without activating the whole J2EE security.<br />
<img src="/_img/was_secu_2.png" alt="Connexion without verification" class="left"/><br />
<span id="more-41"></span></p>
<h2 class="titre2">A solution</h2>
<p>Before changing anu important parameterin the WAS configuration, I remember you that it is always very important to do a backup of your configuration by a command.<a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/rxml_backupconfig.html" target="_blank">backupConfig.sh</a>.</p>
<p>To do this modification you have to know the code and the pass word of the administrator account that make WAS turn  (root).<br />
We will limit us voluntarily to the local exploitation system&#8217;s account as &#8220;user register&#8221; for this  implementation (you can also use LDAP and a personalisated solution -coded of course-).<br />
You must have the 9043 port open (the WAS administration is done in https and change by default from the 9060 port to the 9043 port).</p>
<h3 class="title3">Etapes</h3>
<p>1. If you have the &#8220;lead activities&#8221;  you can use itfor &#8220;global security activation&#8221;, it leads very well the user.<br />
Then you have to desactivate the &#8220;Java 2 security&#8221; and determine the users (see point 3).</p>
<p>2. Unlead activation<br />
Display the page&#8221;Security>Global security&#8221; and un tick off the option <b>&#8220;Apply the Java 2 security&#8221;</b><br />
<img src="/_img/was_secu_3.png" class=center"/><br />
You have to go and see :<br />
   &#8220;Activate the global security&#8221; with &#8220;on&#8221;<br />
   &#8220;Apply the Java 2 security&#8221; with &#8220;off&#8221;<br />
   &#8220;Apply the JCA security at small granulousity &#8221; with &#8220;off&#8221;<br />
   &#8220;Use defined user&#8217;s ID as a fonction of the domaine&#8221; with &#8220;off&#8221;</p>
<p>   &#8220;Emit a warning of access right&#8221; with &#8220;on&#8221;<br />
   &#8220;Protocole active&#8221; normaly CSI (but you can activate CSI and SAS)<br />
   &#8220;Active Authentification Method &#8221; par défaut &#8220;SWAP&#8221;<br />
   &#8220;Registre d&#8217;utilisateurs actif&#8221; sélectionnez &#8220;Système d&#8217;exploitation local&#8221;</p>
<p>When the modifications are done you can validate this and display the page &#8220;Users registers>Local system exploitation&#8221; which permit to configure the admin user ID (and his pass word).<br />
<img src="/_img/was_secu_4.png" class=center"/></p>
<p>3. Definitions of the users :<br />
For that, you have to apply the page &#8220;System administration>Console parameters>Console users&#8221; and you can add at that the system users to who you want to give rights in WAS asministration.<br />
<img src="/_img/was_secu_4.png" class=right"/></p>
<h2 class="titre2">Remarks</h2>
<p class="alertWarning">
Warning : If your Websphere serveur run under an other user account than <b>root</b> You can&#8217;t use the local exploitation system as &#8220;User register&#8221;
</p>
<p class="alertWarning">
Warningn : If you activate the security it is compulsoryto give authentification informations to command line tools (for exemple : stopNode <a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/topic/com.ibm.websphere.nd.doc/info/ae/ae/rxml_securecommand.html" target="_blank">plus d&#8217;info</a>
</p>
<ul>For a higher security you can also :</p>
<li>Configure your firewall to identify and filter the IP address which connect to the port <b>9043</b></li>
<li>Allow only the access to the administration in &#8220;local&#8221; (127.0.0.1) and use ssh tunels to admin this on an other computer.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.berthou.com/us/2008/02/18/websphere-secure-administration-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Websphere &#8211; Unsupported keysize</title>
		<link>http://www.berthou.com/us/2007/12/20/websphere-unsupported-keysize/</link>
		<comments>http://www.berthou.com/us/2007/12/20/websphere-unsupported-keysize/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 17:25:06 +0000</pubDate>
		<dc:creator>rberthou</dc:creator>
				<category><![CDATA[websphere]]></category>

		<guid isPermaLink="false">http://www.berthou.com/us/2007/12/20/websphere-unsupported-keysize/</guid>
		<description><![CDATA[Description A few days ago I had a little problem when I tried to deploy in WAS 6.0 (Websphere Application Serveur 6) an application including a PDF signature. During the execution of the servlet&#8217;s signature, I had the following problem : java.lang.Exception: java.lang.Exception: java.io.IOException: Error in loading the keystore: Private key decryption error: (java.lang.SecurityException: Unsupported [...]]]></description>
				<content:encoded><![CDATA[<h2 class="titre2">Description</h2>
<p>A few days ago I had a little problem when I tried to deploy in WAS 6.0 (Websphere Application Serveur 6)  an application including a PDF signature.<br />
During the execution of the servlet&#8217;s signature, I had the following problem :</p>
<pre class="alertCode">
java.lang.Exception: java.lang.Exception: java.io.IOException:
Error in loading the keystore: Private key decryption error:
(java.lang.SecurityException: Unsupported keysize or algorithm parameters)
</pre>
<h2 class="titre2">Resolution</h2>
<p>This error is caused by the <b>JCE</b> libraries used by the virtual java&#8217;s machine executing WAS.  This JVM is the standard version and it had a limited support of cryptographie&#8217;s algorithme. To correct this you just have to substitute  two jar files in teh configuration of the JVM IBM (local_policy.jar et US_export_policy.jar).<br />
This files are in the index $JAVA_HOME/jre/lib/security (for exemple  /usr/lib/jvm/jre-ibm/lib/security or /opt/IBM/WebSphere/AppServer/java/jre/lib/security).<br />
You can download this non limited librairies http://www-128.ibm.com/developerworks/java/jdk/security/142/  (file unrestrict142.zip)</p>
<p>When the file is download you had to:</p>
<ul>
<li>Decompress the downloaded file</li>
<li>Verify that this file contains  local_policy.jar et US_export_policy.jar</li>
<li>Stop Websphere</li>
<li>Save the old files</li>
<li>Substitute the two files</li>
<li>Take off again WAS</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.berthou.com/us/2007/12/20/websphere-unsupported-keysize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run Websphere on other user than root</title>
		<link>http://www.berthou.com/us/2007/12/04/run-websphere-on-other-user-than-root/</link>
		<comments>http://www.berthou.com/us/2007/12/04/run-websphere-on-other-user-than-root/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 06:46:12 +0000</pubDate>
		<dc:creator>rberthou</dc:creator>
				<category><![CDATA[websphere]]></category>

		<guid isPermaLink="false">http://www.berthou.com/us/2007/12/04/run-websphere-on-other-user-than-root/</guid>
		<description><![CDATA[Run Websphere on other user than root For his installation Websphere need to use root account. The installation&#8217;s script don&#8217;t propose the creation or utilisation of an other user account. This is disturbing because all the objets created by Webphere belong to root. But it&#8217;s easy to correct this problem. Modifications to do I take [...]]]></description>
				<content:encoded><![CDATA[<h2 class="titre2">Run Websphere on other user than root</h2>
<p>For his installation Websphere need to use <b>root</b> account. The installation&#8217;s script don&#8217;t propose the creation or utilisation of an other user account. This is disturbing because all  the objets created by Webphere belong to root.<br/><br />
But it&#8217;s easy to correct this problem.</p>
<h2 class="titre2">Modifications to do</h2>
<p>I take in account that you have created the user and the group that you wanted. After that you just have to connect yourself to the Websphere&#8217;s administration console to change some parametres in this page : <b>Execution process parameters</b>.<br/><br />
You can go to this page thanks to the menu  <b>Servers > Applications server > name_of_your_server</b> and (in the options of this page) <b>Server Infrastructure > Gestion des processus and Java > Processus Execution</b>.<br />
<img src="/_img/ws_1.png" class="center"/><br />
So you can change the user and group wich is going to run the principal process of Websphere ( java ). With that, all objects created by websphere  (images, files, &#8230;) are accessible even to other user than root.</p>
<p class="alertWarning">
<b>Warning  :</b> after this you must change the owner of all files and directorys read by Websphere ( $WAS_HOME/ and your  WebApp and all other required files)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.berthou.com/us/2007/12/04/run-websphere-on-other-user-than-root/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
