<?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>Hacking so Existing &#187; Tomcat</title>
	<atom:link href="http://dev.zhourenjian.com/blog/category/tomcat/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.zhourenjian.com/blog</link>
	<description>Zhou Renjian&#039;s Development Blog</description>
	<lastBuildDate>Fri, 23 Apr 2010 01:54:09 +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>Implementing Web AIM Client</title>
		<link>http://dev.zhourenjian.com/blog/2008/05/06/implementing-aim.html</link>
		<comments>http://dev.zhourenjian.com/blog/2008/05/06/implementing-aim.html#comments</comments>
		<pubDate>Tue, 06 May 2008 01:00:58 +0000</pubDate>
		<dc:creator>Zhou Renjian</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[AIM]]></category>

		<guid isPermaLink="false">http://dev.zhourenjian.com/blog/?p=49</guid>
		<description><![CDATA[Here are some notes when I was struggling to develop a web AIM client: 1. Download AIM SDK, both Windows and Linux In Linux environment, you may already have NSS/NSPR libraries installed, if not following instructions to install it. You &#8230; <a href="http://dev.zhourenjian.com/blog/2008/05/06/implementing-aim.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here are some notes when I was struggling to develop a <a href="http://izuz.net/aim/">web AIM client</a>:</p>
<p>1. Download <a href="http://dev.aol.com/aim/sdk">AIM SDK</a>, both Windows and Linux<br />
In Linux environment, you may already have NSS/NSPR libraries installed, if not following <a href="http://dev.aol.com/aim/tutorials/linuxinstall">instructions</a> to install it. You only need to run:</p>
<blockquote><p>cd dist/release/<br />
ln -s /usr/lib/libnspr4.so .<br />
ln -s /usr/lib/libnss3.so .<br />
ln -s /usr/lib/libnssckbi.so .<br />
ln -s /usr/lib/libplc4.so .<br />
ln -s /usr/lib/libplds4.so .<br />
ln -s /usr/lib/libsmime3.so .<br />
ln -s /usr/lib/libsoftokn3.so .<br />
ln -s /usr/lib/libssl3.so .<br />
ln -s /usr/lib/libfreebl3.so .<br />
export LD_LIBRARY_PATH=/usr/local/tomcat/lib/
</p></blockquote>
<p>2. <a href="http://dev.aol.com/aim">Get a developer key</a> to use AIM SDK. The developer web site does not accept external email account, so create a new one. In fact, more new AIM screen names are needed, as testing AIM requires it.</p>
<p>3. Try to compile and run samples/accjsample:</p>
<blockquote><p>cd samples/accjsample<br />
javac -cp ../../dist/release/accjwrap.jar AccJSample.java Prefs.java<br />
java -cp ../../dist/release/accjwrap.jar:./ AccJSample username password developerkey
</p></blockquote>
<p>But you may get error messasge like:</p>
<blockquote><p>UNKNOWNVALUE<br />
com.aol.acc.AccException: IAccSession_SignOn<br />
        at com.aol.acc.AccSession.SignOn(Native Method)<br />
        at com.aol.acc.AccSession.signOn(AccSession.java:113)<br />
        at AccJSample.<init>(AccJSample.java:47)<br />
        at AccJSample.main(AccJSample.java:22)
</p></blockquote>
<p>But if you go into dist/release/ directory, where *.so are located, and run:</p>
<blockquote><p>/usr/local/java/bin/java -cp ../../dist/release/accjwrap.jar:../../samples/accjsample/ AccJSample username password developerkey</p></blockquote>
<p>You may get things running correctly:</p>
<blockquote><p>[5/5/08 8:34 AM]: OnStateChange: Connecting, ACC_S_OK<br />
[5/5/08 8:34 AM]: OnStateChange: Validating, ACC_S_OK<br />
[5/5/08 8:34 AM]: OnStateChange: Transferring, ACC_S_OK<br />
[5/5/08 8:34 AM]: OnStateChange: Negotiating, ACC_S_OK<br />
[5/5/08 8:34 AM]: OnStateChange: Starting, ACC_S_OK<br />
[5/5/08 8:34 AM]: OnStateChange: Online, ACC_S_OK<br />
[5/5/08 8:34 AM]: OnUserChange: ACC_S_OK<br />
&#8230;</p></blockquote>
<p>That is because *.so may not be loaded correctly if they are not in the current working directory.</p>
<p>Someone says that inaccurate time may cause problems, so run:</p>
<blockquote><p>/etc/init.d/ntpd start</p></blockquote>
<p>to synchronize your server&#8217;s time.</p>
<p>4. following, it comes to the time that developing AIM desktop client, and then converting it into Java Servlet based AIM client. So, tutorial &#8220;<a href="http://dev.aol.com/creating-aim-enabled-applications-java1">Creating AIM-Enabled Application in Java</a>&#8221; series are recommended. </p>
<p>5. And time to deploy your web AIM client to tomcat servlet container.</p>
<p>If your Tomcat 6 server is on Windows, you may need to copy all dist/release/*.dll into your %CATALINA_HOME%/bin/ folder, copy dist/release/accjwrap.jar into %CATALINA_HOME%/lib and restart Tomcat services to get things done. Deploy accjwrap.jar directly into webapps folder is not recommended, because you may want to restart your servlet application frequently while loading and unloading *.dll modules may cause &#8220;already loaded in another classloader UnsatisfiedLinkError&#8221; problems for Tomcat, which may result that you need to restart your Tomcat server.</p>
<p>If your Tomcat 6 server is on Linux, you also need to copy all dist/release/*.so into your $CATALINA_HOME/bin/ folder, copy dist/release/accjwrap.jar into $CATALINA_HOME/lib. And you need to modify your catalina.sh and add two lines:</p>
<blockquote><p>LD_LIBRARY_PATH=$CATALINA_HOME/bin<br />
cd $CATALINA_HOME/bin
</p></blockquote>
<p>And then restart Tomcat server.</p>
<p>Related links:</p>
<ul>
<li><a href="http://mail-archives.apache.org/mod_mbox/tomcat-users/200705.mbox/%3cAEF3D568DD1D9E428048C592AA16459705E2C49C@USRV-EXCH4.na.uis.unisys.com%3e">Tomcat Native library on java.library.path </a></li>
<li><a href="http://forum.java.sun.com/thread.jspa?threadID=780109">Java Native Interface (JNI) &#8211; JNI Dll &#8211; java.library.path</a> </li>
<li><a href="http://dev.aol.com/node/995">Java Linux issues with SDK</a></li>
<li><a href="http://dev.aol.com/aim/forums/clients">AIM Custom Client Forum</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dev.zhourenjian.com/blog/2008/05/06/implementing-aim.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Maximum Connections for Tomcat, Apache and Comet</title>
		<link>http://dev.zhourenjian.com/blog/2007/09/18/maximum-connections-for-tomcat-apache-and-comet.html</link>
		<comments>http://dev.zhourenjian.com/blog/2007/09/18/maximum-connections-for-tomcat-apache-and-comet.html#comments</comments>
		<pubDate>Tue, 18 Sep 2007 14:19:00 +0000</pubDate>
		<dc:creator>Zhou Renjian</dc:creator>
				<category><![CDATA[Comet]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[httpd]]></category>

		<guid isPermaLink="false">http://dev.zhourenjian.com/blog/2007/09/18/maximum-connections-for-tomcat-apache-and-comet.html</guid>
		<description><![CDATA[I struggled to find out why my server broke down frequently these days. And I think I found it. My Apache HTTP server was configured with MaxClients at 50, the default AJP connector&#8217;s connections number was about 15, and the &#8230; <a href="http://dev.zhourenjian.com/blog/2007/09/18/maximum-connections-for-tomcat-apache-and-comet.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I struggled to find out why <a href="http://dev.zhourenjian.com/blog/2007/09/01/ajp-connector-breaks-down-apache-http-server.html">my server broke down frequently these days</a>. And I think I found it.</p>
<p>My Apache HTTP server was configured with MaxClients at 50, the default AJP connector&#8217;s connections number was about 15, and the Tomcat&#8217;s maxThreads was 150. So the bottleneck would be AJP connector, especially all my connection-heavy Comet application was serving about 20 <a href="http://demo.java2script.org/gtalk/">Gtalk</a>/<a href="http://demo.java2script.org/msnlive/">MSNLive</a> simultaneous connections. It is obviously it will break down the servers. And after switching my Gtalk/MSNLive into query modes, it still broke down the server. The reason may be the bottleneck of Apache HTTP server&#8217;s 50 maximum connections. </p>
<p>I updated all the configuration to 256 for maximum simultaneous connections. Hope server won&#8217;t break down for Comet application from now on.</p>
<p>For more about extreme maximum simultaneous connections, please read articles:<br />
<a href="http://jha.rajeev.googlepages.com/web2push">http://jha.rajeev.googlepages.com/web2push</a><br />
<a href="http://www.stdlib.net/~colmmacc/Apachecon-EU2005/scaling-apache-handout.pdf">http://www.stdlib.net/~colmmacc/Apachecon-EU2005/scaling-apache-handout.pdf</a></p>
<p>http.conf</p>
<blockquote class="code"><p><code><span class="tag">&lt;</span>IfModule pre<span class="keyword">for</span>k.c<span class="tag">&gt;</span><br />
#StartServers       1<br />
#MinSpareServers    1<br />
#MaxSpareServers    5<br />
StartServers       3<br />
MinSpareServers    5<br />
MaxSpareServers    10<br />
#ServerLimit        50<br />
ServerLimit       256<br />
#MaxClients        50<br />
MaxClients        256<br />
MaxRequestsPerChild  4000<br />
<span class="tag">&lt;</span>/IfModule<span class="tag">&gt;</span><br />
</code></p></blockquote>
<p>server.xml</p>
<blockquote class="code"><p><code><span class="tag">&lt;</span>!-- Define an AJP 1.3 Connector on port 8009 --<span class="tag">&gt;</span><br />
<span class="tag">&lt;</span>Connector port=<span class="string">&quot;8009&quot;</span><br />
       maxThreads=<span class="string">&quot;256&quot;</span> minSpareThreads=<span class="string">&quot;25&quot;</span> maxSpareThreads=<span class="string">&quot;75&quot;</span><br />
       enableLookups=<span class="string">&quot;false&quot;</span> protocol=<span class="string">&quot;AJP/1.3&quot;</span> /<span class="tag">&gt;</span></code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://dev.zhourenjian.com/blog/2007/09/18/maximum-connections-for-tomcat-apache-and-comet.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJP Connector Breaks Down Apache HTTP Server</title>
		<link>http://dev.zhourenjian.com/blog/2007/09/01/ajp-connector-breaks-down-apache-http-server.html</link>
		<comments>http://dev.zhourenjian.com/blog/2007/09/01/ajp-connector-breaks-down-apache-http-server.html#comments</comments>
		<pubDate>Sat, 01 Sep 2007 03:31:33 +0000</pubDate>
		<dc:creator>Zhou Renjian</dc:creator>
				<category><![CDATA[Comet]]></category>
		<category><![CDATA[Google Talk]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[httpd]]></category>

		<guid isPermaLink="false">http://dev.zhourenjian.com/blog/2007/09/01/ajpw-breaks-down-apache-http-server.html</guid>
		<description><![CDATA[Recently, my Apache HTTP server was broken down twice. The scenario was when visiting a page, it was just waiting there, blank. And I checked the server through SSH and saw that there was a lot (about 50) of inner &#8230; <a href="http://dev.zhourenjian.com/blog/2007/09/01/ajp-connector-breaks-down-apache-http-server.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently, my Apache HTTP server was broken down twice. The scenario was when visiting a page, it was just waiting there, blank. And I checked the server through SSH and saw that there was a lot (about 50) of inner 8009 connections. After restarting Apache HTTP Server and Tomcat Server, these connections decreased to less than 10 connections.</p>
<p>Yes, I deployed Comet applications &#8220;<a href="http://demo.java2script.org/gtalk/">Google Talk in JavaScript</a>&#8221; and &#8220;<a href="http://demo.java2script.org/msnlive/">MSN Live in JavaScript</a>&#8221; on my server. Here is the connection routine:</p>
<p>Client <-Kept Connection-> Apache HTTP Server <-AJP Connector (8009 Connection)-> Tomcat</p>
<p>When a user is connected, an AJP Connector is setup for him/her. The connection will not be tore down until the user disconnects from Gtalk or MSNLive service. So if there are more than 50 users online, there are no doubts that the server crashes.</p>
<p>To solve this problem, one solution would be not using Apache HTTP Server in the middle of Tomcat server and browser client. So there is no limitation on AJP connections.</p>
<p>And another solution would be monitoring user connections on Tomcat server side, and if there are more than 50 connections, try to switch application&#8217;s Comet-mode into Query-mode smartly.</p>
<p>Providing Comet applications need to solve a lot of unknown problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.zhourenjian.com/blog/2007/09/01/ajp-connector-breaks-down-apache-http-server.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ridiculous mod_jk Problem with Flush Method</title>
		<link>http://dev.zhourenjian.com/blog/2007/07/29/ridiculous-mod_jk-problem-with-flush-method.html</link>
		<comments>http://dev.zhourenjian.com/blog/2007/07/29/ridiculous-mod_jk-problem-with-flush-method.html#comments</comments>
		<pubDate>Sun, 29 Jul 2007 15:10:06 +0000</pubDate>
		<dc:creator>Zhou Renjian</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[httpd]]></category>

		<guid isPermaLink="false">http://dev.zhourenjian.com/blog/2007/07/29/ridiculous-mod_jk-problem-with-flush-method.html</guid>
		<description><![CDATA[I am writing Java2Script&#8217;s Google Talk, and it uses a mode of continuation (also known as &#8220;Comet&#8221; application). In order to implement continuum data transfer between browser and server ( Tomcat in the backend ), I kept the HTTP connection &#8230; <a href="http://dev.zhourenjian.com/blog/2007/07/29/ridiculous-mod_jk-problem-with-flush-method.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am writing Java2Script&#8217;s Google Talk, and it uses a mode of continuation (also known as &#8220;<a href="http://alex.dojotoolkit.org/?p=545">Comet</a>&#8221; application). In order to implement continuum data transfer between browser and server ( Tomcat in the backend ), I kept the HTTP connection blocked waiting for data to be available. In the middle, Apache httpd server is used and mod_jk is used to connect the two server. </p>
<p>But I met a ridiculous problem between servlet container and http server. When the browser is assigned to connect servlet directly, it can obtain data from the connection, but it can not obtain a bit when it is piped through Apache httpd server.</p>
<p>I tried to add &#8220;Transfer-Encoding: chunked&#8221; or &#8220;Content-length: 0&#8243; but with no helps. And I modified jk.conf with &#8220;JkOptions +FlushPackets&#8221;, still with no helps. Finally, I remove a line of &#8220;writer.flush();&#8221; from my servlet source, and things all went correctly.</p>
<p>The line of &#8220;writer.flush();&#8221; was located in the the line when there is no data written to the response. And I considered that when there are no data in the response, calling flush method will hang mod_jk connector up. And the whole later data transfer will be disturbed.</p>
<p>More details about mod_jk, I recommend you to read &#8220;<a href="http://jha.rajeev.googlepages.com/web2push">Tunning apache and tomcat for web 2.0 comet application</a>&#8220;.</p>
<p><strong>Update</strong>:<br />
Finally I found out that &#8220;JkOptions +FlushPackets&#8221; works for me. #flush method problem is a fake problem. Only after I restart both Tomcat and Apache server do &#8220;JkOptions +FlushPackets&#8221; begin to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.zhourenjian.com/blog/2007/07/29/ridiculous-mod_jk-problem-with-flush-method.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
