<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Vineet Manohar's blog</title>
	
	<link>http://www.vineetmanohar.com</link>
	<description>Java, Web 2.0 and other Tech topics</description>
	<lastBuildDate>Wed, 14 Jul 2010 07:03:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/vineetmanohar" /><feedburner:info uri="vineetmanohar" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>How to pass parameters in EL methods</title>
		<link>http://feedproxy.google.com/~r/vineetmanohar/~3/w8K_JB3f-H8/</link>
		<comments>http://www.vineetmanohar.com/2010/07/how-to-pass-parameters-in-el-methods/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 22:41:43 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[el]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1149</guid>
		<description><![CDATA[How to pass multiple parameters in an EL function, in 3 simple steps.


Related posts:<ol><li><a href='http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/' rel='bookmark' title='Permanent Link: 3 ways to run Java main from Maven'>3 ways to run Java main from Maven</a></li><li><a href='http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/' rel='bookmark' title='Permanent Link: 2 ways to convert Java Map to String'>2 ways to convert Java Map to String</a></li><li><a href='http://www.vineetmanohar.com/2009/09/jaxb-code-snippets-for-beginners/' rel='bookmark' title='Permanent Link: JAXB code snippets for beginners'>JAXB code snippets for beginners</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/07/how-to-pass-parameters-in-el-methods/';
var dzone_title = 'How to pass parameters in EL methods';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>This article describes how to pass any number of parameters in EL functions in 3 simple steps.</p>
<h2><strong>Step 1</strong>: Extend the class ELMethod</h2>
<p>Extend the class <a href="http://vineetmanohar.googlecode.com/svn/trunk/src/main/java/com/vineetmanohar/util/ELMethod.java" target="_blank">ELMethod.java</a>, and implement the following method:</p>
<pre name="code" class="java">public abstract Object result(Object[] args);
</pre>
<p>For example, say we want to create a <strong>formatDate</strong> method which takes 2 arguments</p>
<ol>
<li>the format String</li>
<li>the Date to be formatted</li>
</ol>
<p>All you need to do is extend the ELMethod class and implement the  result(Object[] args) method.</p>
<h3>Example</h3>
<pre name="code" class="java">import java.text.SimpleDateFormat;
import java.util.Date;

public class FormatDate extends ELMethod {
 private static final long serialVersionUID = 1L;

 public FormatDate() {
   // number of arguments to the result method
   super(2);
 }

 public Object result(Object[] args) {
   String pattern = (String) args[0];
   Date date = (Date) args[1];

   return new SimpleDateFormat(pattern).format(date);
 }
}
</pre>
<h2>Step 2: Add an instance of you class as an application scoped bean</h2>
<p>There are many ways to do this, depending on this technology you are using. Here are some examples:</p>
<p><strong>Set request scope in JSP<br />
</strong></p>
<pre name="code" class="java">request.setAttribute("formatDate", new FormatDate());
</pre>
<p><strong>Set session scope in JSP<br />
</strong></p>
<pre name="code" class="java">session.setAttribute("formatDate", new FormatDate());
</pre>
<p><strong>Set application scope from Servlet</strong></p>
<pre name="code" class="java">this.getServletContext().setAttribute("formatDate", new FormatDate())</pre>
<p><strong>Set application scope from JSP</strong></p>
<pre name="code" class="xml">&lt;jsp:useBean id="formatDate" class="FormatDate" scope="application" /&gt;
</pre>
<p><strong>Set application scope in Seam</strong></p>
<p>Add these annotations to your class</p>
<pre name="code" class="java">@Name("formatDate")
@Scope(ScopeType.APPLICATION)
</pre>
<h2>Step 3: Call the function via map syntax</h2>
<p>Simply pass each argument using the map syntax [] as follows</p>
<p><strong>EL code</strong></p>
<pre name="code" class="java">${formatDate["MMM, dd"][account.creationDate]}
</pre>
<p>All arguments passed via EL are sent to the result(Object[] args) method of the FormatDate class.</p>
<h2>How does it work</h2>
<p>Each argument is collected via the get(Object key) method and is added to an array. When all the arguments have been specified the result method is invoked and the resulting value is returned.</p>
<h2>Reference</h2>
<ul>
<li>Source code of<a href="http://code.google.com/p/vineetmanohar/source/browse/trunk/src/main/java/com/vineetmanohar/util/ELMethod.java" target="_blank"> ELMethod.java</a> on my Google Code project. This class is thread safe and can be application scoped.</li>
<li><a href="http://code.google.com/p/vineetmanohar/source/browse/trunk/src/main/java/com/vineetmanohar/util/FormatDate.java" target="_blank">FormatDate.java</a> example on my Google Code project</li>
<li><a href="http://code.google.com/p/vineetmanohar/source/browse/trunk/src/main/java/com/vineetmanohar/util/Add.java" target="_blank">Add.java</a> example, which adds 2 numbers in EL (e.g. ${add[1][2]})</li>
</ul>


<p>Related posts:<ol><li><a href='http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/' rel='bookmark' title='Permanent Link: 3 ways to run Java main from Maven'>3 ways to run Java main from Maven</a></li><li><a href='http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/' rel='bookmark' title='Permanent Link: 2 ways to convert Java Map to String'>2 ways to convert Java Map to String</a></li><li><a href='http://www.vineetmanohar.com/2009/09/jaxb-code-snippets-for-beginners/' rel='bookmark' title='Permanent Link: JAXB code snippets for beginners'>JAXB code snippets for beginners</a></li></ol></p><img src="http://feeds.feedburner.com/~r/vineetmanohar/~4/w8K_JB3f-H8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/07/how-to-pass-parameters-in-el-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.vineetmanohar.com/2010/07/how-to-pass-parameters-in-el-methods/</feedburner:origLink></item>
		<item>
		<title>How to automatically recover Tomcat from crashes</title>
		<link>http://feedproxy.google.com/~r/vineetmanohar/~3/cCYwA9-z4X0/</link>
		<comments>http://www.vineetmanohar.com/2010/06/howto-auto-recover-tomcat-crashes/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 03:09:19 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[auto]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1108</guid>
		<description><![CDATA[A script which automatically detects that tomcat has crashed and restarts it.


Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/03/howto-rotate-tomcat-catalina-out/' rel='bookmark' title='Permanent Link: How to rotate Tomcat catalina.out'>How to rotate Tomcat catalina.out</a></li><li><a href='http://www.vineetmanohar.com/2009/10/how-to-automate-project-versioning-and-release-with-maven/' rel='bookmark' title='Permanent Link: How to automate project versioning and release with Maven'>How to automate project versioning and release with Maven</a></li><li><a href='http://www.vineetmanohar.com/2010/03/cache-java-webapps-with-squid-reverse-proxy/' rel='bookmark' title='Permanent Link: Cache Java webapps with Squid Reverse Proxy'>Cache Java webapps with Squid Reverse Proxy</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/06/howto-auto-recover-tomcat-crashes/';
var dzone_title = 'How to automatically recover Tomcat from crashes';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>Tomcat occasionally crashes if you do frequent hot-deploys or if you are running it on a machine with low memory. Every time tomcat crashes someone has to manually restart it, so I wrote a script which automatically detects that tomcat has crashed and restarts it.</p>
<p>Here&#8217;s the pseudo logic:</p>
<pre name="code" class="css">every few minutes {
  check tomcat status;

  if (status is "not running") {
    start tomcat;
  }
}
</pre>
<p>Here&#8217;s a shell script to implement the above logic. It assumes that you are running on a unix/linux system and have /etc/init.d/tomcat* script setup to manage tomcat.</p>
<p>Adjust the path to &#8220;/etc/init.d/tomcat&#8221; in the script below to reflect the correct path on your computer. Sometimes it is called /etc/init.d/tomcat5 or /etc/init.d/tomcat6 depending on your tomcat version. Also make sure that the message &#8220;Tomcat Servlet Container is not running.&#8221; matches with the message that you get when you run the script when tomcat is stopped.</p>
<pre name="code" class="css">#! /bin/sh
SERVICE=/etc/init.d/tomcat
STOPPED_MESSAGE="Tomcat Servlet Container is not running."

if [ "`$SERVICE status`" == "$STOPPED_MESSAGE"];
then
{
  $SERVICE start
}
fi
</pre>
<p><strong>To run the script every 10 minutes: </strong></p>
<p>1. Save the above script to &#8220;/root/bin/recover-tomcat.sh&#8221;.</p>
<p>2. Add execute permission:</p>
<pre name="code" class="css">chmod +x /root/bin/recover-tomcat.sh</pre>
<p>3. Add this to root&#8217;s crontab, type the following as root:</p>
<pre name="code" class="css">crontab -e</pre>
<p>4. Add the following lines to the crontab:</p>
<pre name="code" class="css"># monitor tomcat every 10 minutes
*/10 * * * * /root/bin/recover-tomcat.sh</pre>
<h3>What if I don&#8217;t have /etc/init.d/tomcat* script on my computer?</h3>
<p>Tomcat creates a pid file, typically in the TOMCAT_HOME/bin directory. This file contains the process id of the tomcat process running on the machine. The pseudo logic in that case would be:</p>
<pre name="code" class="css">if (the PID file does not exist) {
  // conclude that tomcat is not running
  start tomcat
}
else {
  read the process id from the PID file
  if (no process that id is running) {
    // conclude that tomcat has crashed
    start tomcat
  }
}
</pre>
<p>You can implement the above logic as follows. The following is experimental and is merely a suggested way, test it on your computer before using it.</p>
<pre name="code" class="css"># adjust this to reflect tomcat home on your computer
TOMCAT_HOME=/opt/tomcat5

if [ -f $TOMCAT_HOME/bin/tomcat.pid ]
then
  echo "PID file exists"
  pid="`cat $TOMCAT_HOME/bin/tomcat.pid`"
  if [ "X`ps -p $pid | awk '{print $1}' | tail -1`" = "X"]
  then
    echo "Tomcat is running"
  else
    echo "Tomcat had crashed"
    $TOMCAT_HOME/bin/startup.sh
  fi
else
  echo "PID file does not exist. Restarting..."
  $TOMCAT_HOME/bin/startup.sh
fi
</pre>
<h3>Why would tomcat crash?</h3>
<p>The most common reason is low memory. For example, if you have allocated 1024MB of max memory to tomcat and enough memory is not available on that machine. Other reasons may involve repeated hot-deploys causing memory leaks, rare JVM bugs causing the JVM to crash.</p>


<p>Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/03/howto-rotate-tomcat-catalina-out/' rel='bookmark' title='Permanent Link: How to rotate Tomcat catalina.out'>How to rotate Tomcat catalina.out</a></li><li><a href='http://www.vineetmanohar.com/2009/10/how-to-automate-project-versioning-and-release-with-maven/' rel='bookmark' title='Permanent Link: How to automate project versioning and release with Maven'>How to automate project versioning and release with Maven</a></li><li><a href='http://www.vineetmanohar.com/2010/03/cache-java-webapps-with-squid-reverse-proxy/' rel='bookmark' title='Permanent Link: Cache Java webapps with Squid Reverse Proxy'>Cache Java webapps with Squid Reverse Proxy</a></li></ol></p><img src="http://feeds.feedburner.com/~r/vineetmanohar/~4/cCYwA9-z4X0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/06/howto-auto-recover-tomcat-crashes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.vineetmanohar.com/2010/06/howto-auto-recover-tomcat-crashes/</feedburner:origLink></item>
		<item>
		<title>Getting started with Nexus Maven Repo Manager</title>
		<link>http://feedproxy.google.com/~r/vineetmanohar/~3/K-Z-hk6s-Cs/</link>
		<comments>http://www.vineetmanohar.com/2010/06/getting-started-with-nexus-maven-repo-manager/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 01:32:20 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[nexus]]></category>
		<category><![CDATA[repo]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1076</guid>
		<description><![CDATA[This tutorial outlines steps required to install Nexus (Maven Repository Manager) under Tomcat, or another webapp container. It shows you practical configuration and includes code snippets that go in your pom.xml and settings.xml in order to read and publish artifacts to Nexus server.


Related posts:<ol><li><a href='http://www.vineetmanohar.com/2009/12/publishing-to-maven-central-repo-in-5-steps/' rel='bookmark' title='Permanent Link: Publishing to Maven Central Repo in 5 steps'>Publishing to Maven Central Repo in 5 steps</a></li><li><a href='http://www.vineetmanohar.com/2009/10/how-to-automate-project-versioning-and-release-with-maven/' rel='bookmark' title='Permanent Link: How to automate project versioning and release with Maven'>How to automate project versioning and release with Maven</a></li><li><a href='http://www.vineetmanohar.com/2009/11/tweet-your-builds-with-maven-twitter-plugin/' rel='bookmark' title='Permanent Link: Tweet your builds with Maven Twitter Plugin'>Tweet your builds with Maven Twitter Plugin</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/06/getting-started-with-nexus-maven-repo-manager/';
var dzone_title = 'Getting started with Nexus Maven Repo Manager';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<h2>Overview</h2>
<p>This tutorial outlines steps required to install <a href="http://nexus.sonatype.org/">Nexus</a> (Maven Repository Manager) under Tomcat, or another webapp container. It shows you practical configuration and includes code snippets that go in your pom.xml and settings.xml in order to read and publish artifacts to your Nexus server.</p>
<h3>Step 1: Download</h3>
<p>Download Nexus from <a href="http://nexus.sonatype.org/downloads" target="_blank">here</a> (at the time of writing, latest is <a href="http://nexus.sonatype.org/downloads/nexus-webapp-1.6.0.war" target="_blank">1.6.0</a>)</p>
<h3>Step 2: Install</h3>
<p>Copy the war to TOMCAT_HOME/webapps/nexus.war</p>
<p>Though not required, it is a generally good idea to restart tomcat after installing a new war.</p>
<pre name="code" class="xml">/etc/init.d/tomcat restart</pre>
<h3>Step 3: Configure security</h3>
<p><strong>a) </strong><strong>Change default admin password:</strong> The default admin username/password is admin/admin123. Login as admin and change the password to a secure password.</p>
<p>Login -&gt; [admin, admin123] -&gt; Left Menu -&gt; Security -&gt; Change Password -&gt; click &#8220;Change Password&#8221;</p>
<p><strong>b) </strong><strong>Anonymous Access:</strong> By default Nexus is open to the public. If you want to secure access to nexus, disable &#8216;Nexus anonymous user&#8217;</p>
<p>Admin -&gt; Left Menu -&gt; Users -&gt; &#8216;Nexus anonymous user&#8217; -&gt; Status=Disabled</p>
<p><strong>c) Deployment user:</strong> Change password for deployment user</p>
<p>Admin -&gt; Left menu -&gt; Users -&gt; Deployment user -&gt; Change email address</p>
<p>Admin -&gt; Left menu -&gt; Users -&gt; Right click on &#8216;Deployment user&#8217; in the user list -&gt; Set Password -&gt; click &#8216;Set password&#8217; to finish</p>
<h3>Step 4: Set SMTP server</h3>
<p>It is a good idea to configure SMTP server, so that you can receive emails from Nexus.</p>
<p>Admin login -&gt; Left menu -&gt; Administration -&gt; Server -&gt;SMTP Settings -&gt; (host localhost, port 25, no login, no password mostly works on a linux machine)</p>
<h3><strong>Step 5: Change Base Url<br />
</strong></h3>
<p>If you are running Nexus behind Apache using mod_jk or mod_proxy, change your base url here.</p>
<p>Admin login -&gt; Left menu -&gt; Administration -&gt; Server -&gt; Application Server Settings -&gt; Base url</p>
<h3>Step 6: Add a task to periodically remove old snapshots</h3>
<p>If you or your CI server publishes snapshots to Nexus several times a day, then you should consider adding a task to delete duplicate/old snapshots for the same GAV (group, artifact, version). If you don&#8217;t do this, you will notice that the Nexus disk usage will increase with time.</p>
<p>Admin login -&gt; Left menu -&gt; Administration -&gt; Scheduled tasks -&gt; Add&#8230; -&gt; name=&#8221;Remove old snapshots&#8221;, Repository/Group=Snapshots (Repo), Minimum Snapshot Count=1, Snapshot Retention(days)=3, Recurrence=Daily, Recurring time=2:00 -&gt; click &#8216;Save&#8217;</p>
<h3>Step 7: Using Nexus: reading and publishing artifacts</h3>
<p>If you want to deploy your artifacts to your Nexus, you need to configure 2 files: pom.xml and settings.xml</p>
<p><strong>a) pom.xml &#8211; </strong>for each project which wishes to publish to Nexus, add your repo to the pom.xml</p>
<pre name="code" class="xml">&lt;distributionManagement&gt;
 &lt;!-- Publish the versioned releases here --&gt;
 &lt;repository&gt;
  &lt;id&gt;vineetmanohar-nexus&lt;/id&gt;
  &lt;name&gt;vineetmanohar nexus&lt;/name&gt;
  &lt;url&gt;dav:http://nexus.vineetmanohar.com/nexus/content/repositories/releases&lt;/url&gt;
 &lt;/repository&gt;

 &lt;!-- Publish the versioned releases here --&gt;
 &lt;snapshotRepository&gt;
  &lt;id&gt;vineetmanohar-nexus&lt;/id&gt;
  &lt;name&gt;vineetmanohar nexus&lt;/name&gt;
  &lt;url&gt;dav:http://nexus.vineetmanohar.com/nexus/content/repositories/snapshots&lt;/url&gt;
 &lt;/snapshotRepository&gt;
&lt;/distributionManagement&gt;

&lt;!-- download artifacts from this repo --&gt;
&lt;repositories&gt;
 &lt;repository&gt;
  &lt;id&gt;vineetmanohar-nexus&lt;/id&gt;
  &lt;name&gt;vineetmanohar&lt;/name&gt;
  &lt;url&gt;http://nexus.vineetmanohar.com/nexus/content/groups/public&lt;/url&gt;
  &lt;releases&gt;
   &lt;enabled&gt;true&lt;/enabled&gt;
  &lt;/releases&gt;

  &lt;snapshots&gt;
   &lt;enabled&gt;true&lt;/enabled&gt;
  &lt;/snapshots&gt;
 &lt;/repository&gt;
&lt;/repositories&gt;

&lt;!-- download plugins from this repo --&gt;
&lt;pluginRepositories&gt;
 &lt;pluginRepository&gt;
  &lt;id&gt;vineetmanohar-nexus&lt;/id&gt;
  &lt;name&gt;vineetmanohar&lt;/name&gt;
  &lt;url&gt;http://nexus.vineetmanohar.com/nexus/content/groups/public&lt;/url&gt;
  &lt;releases&gt;
   &lt;enabled&gt;true&lt;/enabled&gt;
  &lt;/releases&gt;
  &lt;snapshots&gt;
   &lt;enabled&gt;true&lt;/enabled&gt;
  &lt;/snapshots&gt;
 &lt;/pluginRepository&gt;
&lt;/pluginRepositories&gt;</pre>
<p><strong>b) settings.xml</strong> &#8211; If you have disabled anonymous access to Nexus, add the deployment password to your <strong>~/.m2/repository/settings.xml</strong> file</p>
<pre name="code" class="xml">&lt;settings&gt;
 &lt;servers&gt;
  &lt;server&gt;
   &lt;!-- this id should match the id of the repo server in pom.xml --&gt;
   &lt;id&gt;vineetmanohar-nexus&lt;/id&gt;
   &lt;username&gt;deployment&lt;/username&gt;
   &lt;password&gt;password_goes_here&lt;/password&gt;
  &lt;/server&gt;
 &lt;/servers&gt;
&lt;/settings&gt;</pre>


<p>Related posts:<ol><li><a href='http://www.vineetmanohar.com/2009/12/publishing-to-maven-central-repo-in-5-steps/' rel='bookmark' title='Permanent Link: Publishing to Maven Central Repo in 5 steps'>Publishing to Maven Central Repo in 5 steps</a></li><li><a href='http://www.vineetmanohar.com/2009/10/how-to-automate-project-versioning-and-release-with-maven/' rel='bookmark' title='Permanent Link: How to automate project versioning and release with Maven'>How to automate project versioning and release with Maven</a></li><li><a href='http://www.vineetmanohar.com/2009/11/tweet-your-builds-with-maven-twitter-plugin/' rel='bookmark' title='Permanent Link: Tweet your builds with Maven Twitter Plugin'>Tweet your builds with Maven Twitter Plugin</a></li></ol></p><img src="http://feeds.feedburner.com/~r/vineetmanohar/~4/K-Z-hk6s-Cs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/06/getting-started-with-nexus-maven-repo-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.vineetmanohar.com/2010/06/getting-started-with-nexus-maven-repo-manager/</feedburner:origLink></item>
		<item>
		<title>What is Google TV … in 2 minutes</title>
		<link>http://feedproxy.google.com/~r/vineetmanohar/~3/zpYdgAMciO8/</link>
		<comments>http://www.vineetmanohar.com/2010/05/what-is-google-tv-in-2-minutes/#comments</comments>
		<pubDate>Fri, 21 May 2010 21:57:03 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1063</guid>
		<description><![CDATA[Google TV is a Smart TV (or set-top box) which aims to seamlessly combine your Internet and TV experience.


Related posts:<ol><li><a href='http://www.vineetmanohar.com/2009/06/what-is-google-wave-in-plain-simple-english-in-2-minutes/' rel='bookmark' title='Permanent Link: What is Google Wave: in plain simple English in 2 minutes'>What is Google Wave: in plain simple English in 2 minutes</a></li><li><a href='http://www.vineetmanohar.com/2010/02/what-is-google-buzz/' rel='bookmark' title='Permanent Link: What is Google Buzz?'>What is Google Buzz?</a></li><li><a href='http://www.vineetmanohar.com/2009/06/google-introduces-page-speed/' rel='bookmark' title='Permanent Link: Google introduces Page Speed'>Google introduces Page Speed</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/05/what-is-google-tv-in-2-minutes/';
var dzone_title = 'What is Google TV &#8230; in 2 minutes';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p><a href="http://www.google.com/tv/" target="_blank">Google TV</a> is a Smart TV (or set-top box) which aims to seamlessly combine your Internet and TV experience. It runs Android OS, Chrome browser and Flash 10. Third party developers can create interesting applications and make them available to end users via an App marketplace.</p>
<p>Google TV aims to take TV viewing experience to the next level, similar to what smart phones (Android, iPhone) did for phones. The key here, in my opinion, is creating a framework and open up the TV-internet application space to third-party developers.</p>
<h3>Summary</h3>
<ul>
<li>Google TV was <a href="http://www.youtube.com/googledevelopers#p/p/B09682344C2F233B/0/ASZbArr7vdI" target="_blank">announced</a> at <a href="http://code.google.com/events/io/2010/" target="_blank">2010 Google I/O</a>, in stores Fall 2010</li>
<li>Google has partnered with Sony (TVs), Intel (atom processor), Best Buy (sales to end users), Dish Network (Set-top box), Logitech (peripherals) and Adobe (Flash player)</li>
<li>Google TV units will be available (in form of TVs and/or Set-top boxes) this fall, well in time for the Christmas season</li>
<li>Runs Android OS, Chrome Browser, Flash 10</li>
<li>Third party developers can write apps and users can download apps via a Marketplace</li>
<li>End users can surf channels on TV as they normally do, and also access relevant internet related apps like Youtube, Picasa and discover apps written by third party developers</li>
<li>Sign up <a href="https://services.google.com/fb/forms/googletvinfo/" target="_blank">here</a> to receive updates about Google TV</li>
</ul>
<p><object width="425" height="355" type="application/x-shockwave-flash" data="http://www.youtube.com/v/diTpeYoqAhc"><param name="movie" value="http://www.youtube.com/v/diTpeYoqAhc" />This video was embedded using the YouTuber plugin by <a href="http://www.roytanck.com">Roy Tanck</a>. Adobe Flash Player is required to view the video.</object></p>


<p>Related posts:<ol><li><a href='http://www.vineetmanohar.com/2009/06/what-is-google-wave-in-plain-simple-english-in-2-minutes/' rel='bookmark' title='Permanent Link: What is Google Wave: in plain simple English in 2 minutes'>What is Google Wave: in plain simple English in 2 minutes</a></li><li><a href='http://www.vineetmanohar.com/2010/02/what-is-google-buzz/' rel='bookmark' title='Permanent Link: What is Google Buzz?'>What is Google Buzz?</a></li><li><a href='http://www.vineetmanohar.com/2009/06/google-introduces-page-speed/' rel='bookmark' title='Permanent Link: Google introduces Page Speed'>Google introduces Page Speed</a></li></ol></p><img src="http://feeds.feedburner.com/~r/vineetmanohar/~4/zpYdgAMciO8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/05/what-is-google-tv-in-2-minutes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.vineetmanohar.com/2010/05/what-is-google-tv-in-2-minutes/</feedburner:origLink></item>
		<item>
		<title>2 ways to convert Java Map to String</title>
		<link>http://feedproxy.google.com/~r/vineetmanohar/~3/cSBYncutWx0/</link>
		<comments>http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/#comments</comments>
		<pubDate>Sat, 08 May 2010 02:59:26 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[deserialize]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[serialize]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1003</guid>
		<description><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/';
var dzone_title = '2 ways to convert Java Map to String';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
This article shows 2 ways to convert Java Map to String. Approach 1: simple, lightweight &#8211; produces query string like output, but restrictive. Approach 2: uses Java XML bean serialization, more robust but produces overly verbose output. Approach 1: Map to query string format Approach 1 converts a map to a query-string like output. Here&#8217;s [...]


Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/' rel='bookmark' title='Permanent Link: 3 ways to serialize Java Enums'>3 ways to serialize Java Enums</a></li><li><a href='http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/' rel='bookmark' title='Permanent Link: 3 ways to run Java main from Maven'>3 ways to run Java main from Maven</a></li><li><a href='http://www.vineetmanohar.com/2009/07/first-look-at-selenium-inspector/' rel='bookmark' title='Permanent Link: First look at Selenium Inspector'>First look at Selenium Inspector</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/';
var dzone_title = '2 ways to convert Java Map to String';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>This article shows 2 ways to convert Java Map to String. </p>
<ul>
<li>Approach 1: simple, lightweight &#8211; produces query string like output, but restrictive. </li>
<li>Approach 2: uses Java XML bean serialization, more robust but produces overly verbose output.</li>
</ul>
<h3>Approach 1: Map to query string format</h3>
<p>Approach 1 converts a map to a query-string like output. Here&#8217;s what an output looks like:</p>
<pre name="code" class="java">
name1=value1&amp;name2=value2
</pre>
<p>Full code:</p>
<pre name="code" class="java">import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class MapUtil {
 public static String mapToString(Map&lt;String, String&gt; map) {
   StringBuilder stringBuilder = new StringBuilder();

   for (String key : map.keySet()) {
    if (stringBuilder.length() &gt; 0) {
     stringBuilder.append("&amp;");
    }
    String value = map.get(key);
    try {
     stringBuilder.append((key != null ? URLEncoder.encode(key, "UTF-8") : ""));
     stringBuilder.append("=");
     stringBuilder.append(value != null ? URLEncoder.encode(value, "UTF-8") : "");
    } catch (UnsupportedEncodingException e) {
     throw new RuntimeException("This method requires UTF-8 encoding support", e);
    }
   }

   return stringBuilder.toString();
  }

  public static Map&lt;String, String&gt; stringToMap(String input) {
   Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();

   String[] nameValuePairs = input.split("&amp;");
   for (String nameValuePair : nameValuePairs) {
    String[] nameValue = nameValuePair.split("=");
    try {
     map.put(URLDecoder.decode(nameValue[0], "UTF-8"), nameValue.length &gt; 1 ? URLDecoder.decode(
     nameValue[1], "UTF-8") : "");
    } catch (UnsupportedEncodingException e) {
     throw new RuntimeException("This method requires UTF-8 encoding support", e);
    }
   }

   return map;
  }
}
</pre>
<h4>Example usage code</h4>
<pre name="code" class="java">
 Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
 map.put("color", "red");
 map.put("symbols", "{,=&amp;*?}");
 map.put("empty", "");
 String output = MapUtil.mapToString(map);
 Map&lt;String, String&gt; parsedMap = MapUtil.stringToMap(output);
 for (String key : map.keySet()) {
  Assert.assertEquals(parsedMap.get(key), map.get(key));
 }
</pre>
<h4>Output with Approach 1</h4>
<pre name="code" class="java">
symbols=%7B%2C%3D%26*%3F%7D&amp;color=red&amp;empty=
</pre>
<h4>Caveat</h4>
<ul>
<li>Only supports String keys and values.</li>
<li>Due to the nature of serialization, null keys and values are not supported. Null will be converted to an empty String. This is because there is no way to distinguish between a null and an empty String in the serialized form. If you need support for null keys and values, use java.beans.XMLEncoder as shown below.</li>
</ul>
<h3>Approach 2: Java Bean XMLEncoder: Map to String</h4>
<p>Java provides XMLEncoder and XMLDecoder classes as part of the java.beans package as a standard way to serialize and deserialize objects. This</p>
<pre name="code" class="java">
 Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
 map.put("color", "red");
 map.put("symbols", "{,=&amp;*?}");
 map.put("empty", "");
 ByteArrayOutputStream bos = new ByteArrayOutputStream();
 XMLEncoder xmlEncoder = new XMLEncoder(bos);
 xmlEncoder.writeObject(map);
 xmlEncoder.flush();

 String serializedMap = bos.toString()
 System.output.println(serializedMap);
</pre>
<h4>Output with Approach 2</h4>
<p>The serialized value is shown below. As you can see this is more verbose, but can accommodate different data types and null keys and values.</p>
<pre name="code" class="java">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;java version="1.5.0_17"&gt;
 &lt;object&gt;
  &lt;void method="put"&gt;
   &lt;string&gt;symbols&lt;/string&gt;
   &lt;string&gt;{,=&amp;amp;*?}&lt;/string&gt;
  &lt;/void&gt;
  &lt;void method="put"&gt;
   &lt;string&gt;color&lt;/string&gt;
   &lt;string&gt;red&lt;/string&gt;
  &lt;/void&gt;
  &lt;void method="put"&gt;
   &lt;string&gt;empty&lt;/string&gt;
   &lt;string&gt;&lt;/string&gt;
  &lt;/void&gt;
 &lt;/object&gt;
</pre>
<h3>Java Bean XMLDecoder: String to Map</h3>
<pre name="code" class="java"> XMLDecoder xmlDecoder = new XMLDecoder(new ByteArrayInputStream(serializedMap.getBytes()));
 Map&lt;String, String&gt; parsedMap = (Map&lt;String, String&gt;) xmlDecoder.readObject();

 for (String key : map.keySet()) {
  Assert.assertEquals(parsedMap.get(key), map.get(key));
 }
</pre>
<h3>Summary</h3>
<p>While Java provides a standard (and overly verbose) way to serialize and deserialize objects, this articles discusses an alternative lightweight way to convert a Java Map to String and back. If you are serializing a map with non-null String keys and values, then you should be able to use this alternative way, otherwise use the Java bean serialization.</p>


<p>Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/' rel='bookmark' title='Permanent Link: 3 ways to serialize Java Enums'>3 ways to serialize Java Enums</a></li><li><a href='http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/' rel='bookmark' title='Permanent Link: 3 ways to run Java main from Maven'>3 ways to run Java main from Maven</a></li><li><a href='http://www.vineetmanohar.com/2009/07/first-look-at-selenium-inspector/' rel='bookmark' title='Permanent Link: First look at Selenium Inspector'>First look at Selenium Inspector</a></li></ol></p><img src="http://feeds.feedburner.com/~r/vineetmanohar/~4/cSBYncutWx0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/</feedburner:origLink></item>
		<item>
		<title>How to configure multiple page.xml files in Seam 2.2</title>
		<link>http://feedproxy.google.com/~r/vineetmanohar/~3/8DB3JvPQEqY/</link>
		<comments>http://www.vineetmanohar.com/2010/04/how-to-configure-multiple-page-xml-files-in-seam-2-2/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 00:04:43 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[seam]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=979</guid>
		<description><![CDATA[Seam lets you specify navigation rules in the pages.xml file which can become very large for apps with many pages and transitions. Seam allows you to break this file into multiple small files. This allows you to easily manage large applications by creating multiple pages.xml files, typically one per page. This article describes how to create multiple pages.xml files in Seam 2.2.


Related posts:<ol><li><a href='http://www.vineetmanohar.com/2009/03/a-common-configuration-mistake-which-makes-seam-slow/' rel='bookmark' title='Permanent Link: A common configuration mistake which makes Seam slow'>A common configuration mistake which makes Seam slow</a></li><li><a href='http://www.vineetmanohar.com/2009/04/seam-asynchronous-email/' rel='bookmark' title='Permanent Link: Seam Asynchronous Email'>Seam Asynchronous Email</a></li><li><a href='http://www.vineetmanohar.com/2009/03/implementing-context-senstive-permissions-and-authorization-in-jsf-seam/' rel='bookmark' title='Permanent Link: Implementing context senstive permissions and authorization in JSF Seam'>Implementing context senstive permissions and authorization in JSF Seam</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/04/how-to-configure-multiple-page-xml-files-in-seam-2-2/';
var dzone_title = 'How to configure multiple page.xml files in Seam 2.2';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<h3>Overview</h3>
<p>Seam lets you specify navigation rules in the <strong>pages.xml</strong> file which can become very large for apps with many pages and transitions. Seam allows you to break this file into multiple small files. This allows you to easily manage large applications by creating multiple pages.xml files, typically one per page. This article describes how to create multiple pages.xml files in Seam 2.2.</p>
<h3>Step 1: Configure /WEB-INF/components.xml</h3>
<p><strong>Make sure you declare the </strong><strong>navigation namespace at the top of components.xml and each file under &lt;navigation:pages&gt; as follows</strong></p>
<pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;components xmlns="http://jboss.com/products/seam/components"
 xmlns:core="http://jboss.com/products/seam/core" xmlns:persistence="http://jboss.com/products/seam/persistence"
 xmlns:drools="http://jboss.com/products/seam/drools" xmlns:bpm="http://jboss.com/products/seam/bpm"
 xmlns:security="http://jboss.com/products/seam/security" xmlns:mail="http://jboss.com/products/seam/mail"
 xmlns:web="http://jboss.com/products/seam/web" xmlns:navigation="http://jboss.com/products/seam/navigation"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
 http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd
 http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd
 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
 http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd
 http://jboss.com/products/seam/navigation http://jboss.com/products/seam/navigation-2.2.xsd
 http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd"&gt;

 &lt;mail:mail-session host="localhost" tls="false" ssl="false" port="25" /&gt;

 &lt;component&gt;
  &lt;property name="createTempFiles"&gt;true&lt;/property&gt;
  &lt;property name="maxRequestSize"&gt;1000000000&lt;/property&gt;
 &lt;/component&gt;

 &lt;component name="org.jboss.seam.core.init"&gt;
  &lt;!-- enabling this slows down Seam significantly --&gt;
  &lt;property name="debug"&gt;false&lt;/property&gt;
 &lt;/component&gt;

 &lt;core:init transaction-management-enabled="false" /&gt;

 &lt;security:identity authenticate-method="#{loginController.authenticate}"
  remember-me="true" /&gt;

 &lt;event type="org.jboss.seam.security.notLoggedIn"&gt;
  &lt;action execute="#{redirect.captureCurrentView}" /&gt;
 &lt;/event&gt;

 &lt;event type="org.jboss.seam.security.postAuthenticate"&gt;
  &lt;action execute="#{redirect.returnToCapturedView}" /&gt;
 &lt;/event&gt;

 &lt;navigation:pages&gt;
  &lt;navigation:resources&gt;
   &lt;!-- global --&gt;
   &lt;value&gt;/WEB-INF/pages.xml&lt;/value&gt;

   &lt;!-- one per page --&gt;
   &lt;value&gt;/WEB-INF/createAccount.page.xml&lt;/value&gt;
   &lt;value&gt;/WEB-INF/login.page.xml&lt;/value&gt;
  &lt;/navigation:resources&gt;
 &lt;/navigation:pages&gt;
&lt;/components&gt;</pre>
<h3>Step 2. Save all .page.xml files in WEB-INF directory</h3>
<pre name="code" class="xml">WEB-INF/createAccount.page.xml
WEB-INF/login.page.xml</pre>
<h3>Step 3. Create the .page.xml files.</h3>
<p>See the sample file: <strong>createAccount.page.xml</strong> below. Note that the root tag is <strong>&lt;pages&gt;</strong>. Make sure that the same page is not repeated in another file.</p>
<pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;pages xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd"&gt;

 &lt;page view-id="/createAccount.xhtml" login-required="false"&gt;
 &lt;!-- Create account --&gt;
 &lt;navigation
  from-action="#{createAccountController.createAccountFormCreateAccount}"&gt;

   &lt;!-- Account created --&gt;
   &lt;rule if-outcome="accountCreated"&gt;
    &lt;redirect view-id="/login.xhtml"&gt;
     &lt;message&gt;Your account has been created. Please log in.&lt;/message&gt;
    &lt;/redirect&gt;
   &lt;/rule&gt;
  &lt;/navigation&gt;
 &lt;/page&gt;
&lt;/pages&gt;</pre>
<h3>FAQ</h3>
<h4>Can I use Seam 2.0 style &lt;view id&gt;.page.xml files?</h4>
<p>You should be able to use <strong>viewid.page.xml</strong> xml files according to the examples that ship with Seam 2.2.0. However, some users have <a href="http://seamframework.org/Community/Seam210SP1PagexmlNavigationIsNotWorking" target="_blank">complained</a> that it doesn&#8217;t work in Seam 2.1. I could not get it to work with Seam 2.2.0 as well.</p>


<p>Related posts:<ol><li><a href='http://www.vineetmanohar.com/2009/03/a-common-configuration-mistake-which-makes-seam-slow/' rel='bookmark' title='Permanent Link: A common configuration mistake which makes Seam slow'>A common configuration mistake which makes Seam slow</a></li><li><a href='http://www.vineetmanohar.com/2009/04/seam-asynchronous-email/' rel='bookmark' title='Permanent Link: Seam Asynchronous Email'>Seam Asynchronous Email</a></li><li><a href='http://www.vineetmanohar.com/2009/03/implementing-context-senstive-permissions-and-authorization-in-jsf-seam/' rel='bookmark' title='Permanent Link: Implementing context senstive permissions and authorization in JSF Seam'>Implementing context senstive permissions and authorization in JSF Seam</a></li></ol></p><img src="http://feeds.feedburner.com/~r/vineetmanohar/~4/8DB3JvPQEqY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/04/how-to-configure-multiple-page-xml-files-in-seam-2-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.vineetmanohar.com/2010/04/how-to-configure-multiple-page-xml-files-in-seam-2-2/</feedburner:origLink></item>
		<item>
		<title>Spring classpath scan breaks when migrating from JBoss4 to JBoss5</title>
		<link>http://feedproxy.google.com/~r/vineetmanohar/~3/S5rlVX1lKI4/</link>
		<comments>http://www.vineetmanohar.com/2010/04/spring-classpath-scan-issue-jboss5/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 00:57:28 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=967</guid>
		<description><![CDATA[Spring 2.5 classpath scan does not work on JBoss5 due to internal architecture changes in JBoss5. You may face this issue when migrating from JBoss4 to JBoss5. This article walks you through a simple fix, with code snippets.


Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/' rel='bookmark' title='Permanent Link: EJB3 JPA error when migrating from JBoss version 4 to 5'>EJB3 JPA error when migrating from JBoss version 4 to 5</a></li><li><a href='http://www.vineetmanohar.com/2010/04/how-to-configure-multiple-page-xml-files-in-seam-2-2/' rel='bookmark' title='Permanent Link: How to configure multiple page.xml files in Seam 2.2'>How to configure multiple page.xml files in Seam 2.2</a></li><li><a href='http://www.vineetmanohar.com/2009/04/seam-asynchronous-email/' rel='bookmark' title='Permanent Link: Seam Asynchronous Email'>Seam Asynchronous Email</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/04/spring-classpath-scan-issue-jboss5/';
var dzone_title = 'Spring classpath scan breaks when migrating from JBoss4 to JBoss5';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>Spring 2.5 classpath scan does not work on JBoss5 due to internal architecture changes in JBoss5. You may face this issue when migrating from JBoss4 to JBoss5. This article walks you through a simple fix, with code snippets.</p>
<h3>Classpath scan issue</h3>
<p>In JBoss 4, your application was probably using Spring 2.5.6 with classpath scan to load spring beans (as shown below). When migrating your code to JBoss5, you will notice that component-scan does not work with JBoss5. Symptoms may include null Spring components or if you were using Spring Seam integration and the Spring beans were loaded through classpath scan then you may be the following error:</p>
<p><strong>Seam Code</strong></p>
<pre name="code" class="java">public class LoginController extends Controller {
    @In("#{userService}")
    protected demo.entity.service.UserService userService;</pre>
<p><strong>Stacktrace</strong></p>
<pre name="code" class="java">Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: loginController.#{userService}
 at org.jboss.seam.Component.getValueToInject(Component.java:2335)
 at org.jboss.seam.Component.injectAttributes(Component.java:1736)
 at org.jboss.seam.Component.inject(Component.java:1554)
 at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)</pre>
<p><strong>Spring 2.5.6 dependency in pom.xml</strong></p>
<pre name="code" class="xml"> &lt;dependency&gt;
 &lt;groupId&gt;org.springframework&lt;/groupId&gt;
 &lt;artifactId&gt;spring&lt;/artifactId&gt;
 &lt;version&gt;2.5.6&lt;/version&gt;
 &lt;/dependency</pre>
<p><strong>Old spring config XML</strong></p>
<pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

http://www.springframework.org/schema/context

 http://www.springframework.org/schema/context/spring-context-2.5.xsd"
 default-init-method="init" default-destroy-method="shutdown"&gt;
 &lt;context:annotation-config /&gt;
 &lt;context:component-scan base-package="demo.dao.jpa" /&gt;
&lt;/beans&gt;</pre>
<p>If you run the above code in JBoss5, component-scan does not work. See this <a href="http://jira.springframework.org/browse/SPR-5120?focusedCommentId=41972&amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_41972">JIRA issue on Spring&#8217;s website</a>.</p>
<h3>Solution</h3>
<p>You need to migrate your spring version from 2.5.6 to 3.0.0.RELEASE. Remove your old spring dependency for 2.5.6 and add the following. Add snippets for the components that your application needs. Here&#8217;s a list of common spring components and their maven dependencies.</p>
<p><strong>New dependency</strong></p>
<pre name="code" class="xml"> &lt;dependency&gt;
 &lt;groupId&gt;org.springframework&lt;/groupId&gt;
 &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
 &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
 &lt;/dependency&gt;

 &lt;dependency&gt;
 &lt;groupId&gt;org.springframework&lt;/groupId&gt;
 &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
 &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
 &lt;/dependency&gt;

 &lt;dependency&gt;
 &lt;groupId&gt;org.springframework&lt;/groupId&gt;
 &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
 &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
 &lt;/dependency&gt;</pre>
<pre name="code" class="xml"> &lt;dependency&gt;
 &lt;groupId&gt;org.springframework&lt;/groupId&gt;
 &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
 &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
 &lt;scope&gt;test&lt;/scope&gt;
 &lt;/dependency&gt;</pre>
<p>Complete list is available <a href="http://blog.springsource.com/2009/12/02/obtaining-spring-3-artifacts-with-maven/" target="_blank">here</a>. After making this change, build your project with the new dependencies. Your old code should work with Spring 3 on JBoss 5.1.0.GA.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">public abstract class GeneratedLoginController extends Controller {<br />
@In(&#8220;#{userDao}&#8221;)<br />
protected demo.dao.UserDao userDao;</p>
<p>@In(&#8220;#{userService}&#8221;)<br />
protected demo.entity.service.UserService userService;</p>
</div>


<p>Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/' rel='bookmark' title='Permanent Link: EJB3 JPA error when migrating from JBoss version 4 to 5'>EJB3 JPA error when migrating from JBoss version 4 to 5</a></li><li><a href='http://www.vineetmanohar.com/2010/04/how-to-configure-multiple-page-xml-files-in-seam-2-2/' rel='bookmark' title='Permanent Link: How to configure multiple page.xml files in Seam 2.2'>How to configure multiple page.xml files in Seam 2.2</a></li><li><a href='http://www.vineetmanohar.com/2009/04/seam-asynchronous-email/' rel='bookmark' title='Permanent Link: Seam Asynchronous Email'>Seam Asynchronous Email</a></li></ol></p><img src="http://feeds.feedburner.com/~r/vineetmanohar/~4/S5rlVX1lKI4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/04/spring-classpath-scan-issue-jboss5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.vineetmanohar.com/2010/04/spring-classpath-scan-issue-jboss5/</feedburner:origLink></item>
		<item>
		<title>EJB3 JPA error when migrating from JBoss version 4 to 5</title>
		<link>http://feedproxy.google.com/~r/vineetmanohar/~3/ISgqSBw7P20/</link>
		<comments>http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 00:03:54 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ejb3]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[jta]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=955</guid>
		<description><![CDATA[When I tried migrating my JBoss 4.2 application which uses Spring to manage transactions, to JBoss 5.1, I got the following error message. 

Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a jta-data-source for a JTA enabled persistence context

This is a known issue and there are two known workarounds for this problem. See article for details.


Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/04/spring-classpath-scan-issue-jboss5/' rel='bookmark' title='Permanent Link: Spring classpath scan breaks when migrating from JBoss4 to JBoss5'>Spring classpath scan breaks when migrating from JBoss4 to JBoss5</a></li><li><a href='http://www.vineetmanohar.com/2010/04/how-to-configure-multiple-page-xml-files-in-seam-2-2/' rel='bookmark' title='Permanent Link: How to configure multiple page.xml files in Seam 2.2'>How to configure multiple page.xml files in Seam 2.2</a></li><li><a href='http://www.vineetmanohar.com/2009/05/maven-cargo-jboss/' rel='bookmark' title='Permanent Link: Maven Cargo JBoss'>Maven Cargo JBoss</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/';
var dzone_title = 'EJB3 JPA error when migrating from JBoss version 4 to 5';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>When I tried migrating my JBoss 4.2 [war] application which uses Spring to manage transactions, to JBoss 5.1, I got the following error message.</p>
<h3>The error message</h3>
<pre name="code" class="xml">11:18:55,683 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=#demo state=Create
java.lang.RuntimeException: Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a jta-data-source for a JTA enabled persistence context named: demo
	at org.jboss.jpa.deployment.PersistenceUnitInfoImpl.&lt;init&gt;(PersistenceUnitInfoImpl.java:115)
	at org.jboss.jpa.deployment.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:275)</pre>
<h3>Here&#8217;s the persistence.xml file</h3>
<pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
 version="1.0"&gt;
 &lt;persistence-unit name="demo"&gt;
 &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
 &lt;class&gt;demo.jpa.User&lt;/class&gt;
 &lt;class&gt;demo.jpa.Issue&lt;/class&gt;
 &lt;class&gt;demo.jpa.UploadedFile&lt;/class&gt;
 &lt;properties&gt;
   &lt;property name="hibernate.hbm2ddl.auto" value="create" /&gt;
   &lt;property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /&gt;
   &lt;property name="hibernate.show_sql" value="true" /&gt;
   &lt;property name="hibernate.format_sql" value="true" /&gt;
   &lt;property name="hibernate.use_sql_comments" value="true" /&gt;
 &lt;/properties&gt;
 &lt;/persistence-unit&gt;
&lt;/persistence&gt;</pre>
<h2>Solution/workaround</h2>
<p>JBoss loads file named &#8220;persistence.xml&#8221; through this file:</p>
<pre name="code" class="xml">jboss-5.1.0.GA/server/default/deployers/ejb3.deployer/META-INF/jpa-deployers-jboss-beans.xml</pre>
<p>&#8230; via this code snippet (line 21-95)</p>
<pre name="code" class="xml">   &lt;bean name="PersistenceParsingDeployer" class="org.jboss.jpa.deployers.PersistenceParsingDeployer"/&gt;
   &lt;bean name="PersistenceDeployer" class="org.jboss.jpa.deployers.PersistenceDeployer"/&gt;

   &lt;bean name="PersistenceUnitDeployer" class="org.jboss.jpa.deployers.PersistenceUnitDeployer"&gt;
    ...
   &lt;/bean&gt;</pre>
<p><strong>Solution 1:</strong></p>
<p>Comment out the above lines. This solution is a server configuration modification and therefore must be done on every server (dev/qa/production) that you want to run your app on. You may not be able to use this approach if you don&#8217;t have control over your [production] server configuration. See Solution 2 for an application oriented solution.</p>
<p><strong>Solution 2:</strong></p>
<ol>
<li>Rename the <strong><em>persistence.xml</em></strong> file to something else, for example, <em><strong>spring-persistence.xml</strong></em></li>
<li>Change the config for the spring <em><strong>entityManagerFactory</strong></em> bean to explicitly refer to this new file. See below</li>
</ol>
<p style="padding-left: 60px;"><strong>Spring configuration &#8211; before:</strong></p>
<pre name="code" class="xml" style="padding-left: 60px;">&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
 &lt;property name="dataSource" ref="dataSource" /&gt;
 &lt;property name="jpaVendorAdapter"&gt;
   &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /&gt;
 &lt;/property&gt;
&lt;/bean&gt;</pre>
<p style="padding-left: 60px;"><strong>Spring configuration &#8211; after:</strong></p>
<pre name="code" class="xml" style="padding-left: 60px;">&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
 &lt;property name="dataSource" ref="dataSource" /&gt;
 &lt;property name="jpaVendorAdapter"&gt;
   &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /&gt;
 &lt;/property&gt;
 &lt;!-- ADD THE FOLLOWING PROPERTY --&gt;
 &lt;!-- provide the location of new persistence.xml --&gt;
 &lt;property name="persistenceXmlLocation" value="classpath:META-INF/spring-persistence.xml" /&gt;
&lt;/bean&gt;</pre>
<h3>Reference</h3>
<p>See more details of the corresponding <a title="JIRA issue at jboss.org" href="https://jira.jboss.org/jira/browse/EJBTHREE-1730?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&amp;focusedCommentId=12453872#action_12453872" target="_blank">JIRA issue at jboss.org</a></p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 198px; width: 1px; height: 1px;">&lt;bean name=&#8221;PersistenceParsingDeployer&#8221; class=&#8221;org.jboss.jpa.deployers.PersistenceParsingDeployer&#8221;/&gt;</p>
<p>&lt;bean name=&#8221;PersistenceDeployer&#8221; class=&#8221;org.jboss.jpa.deployers.PersistenceDeployer&#8221;/&gt;<br />
&lt;bean name=&#8221;PersistenceUnitDeployer&#8221; class=&#8221;org.jboss.jpa.deployers.PersistenceUnitDeployer&#8221;&gt;</p>
</div>


<p>Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/04/spring-classpath-scan-issue-jboss5/' rel='bookmark' title='Permanent Link: Spring classpath scan breaks when migrating from JBoss4 to JBoss5'>Spring classpath scan breaks when migrating from JBoss4 to JBoss5</a></li><li><a href='http://www.vineetmanohar.com/2010/04/how-to-configure-multiple-page-xml-files-in-seam-2-2/' rel='bookmark' title='Permanent Link: How to configure multiple page.xml files in Seam 2.2'>How to configure multiple page.xml files in Seam 2.2</a></li><li><a href='http://www.vineetmanohar.com/2009/05/maven-cargo-jboss/' rel='bookmark' title='Permanent Link: Maven Cargo JBoss'>Maven Cargo JBoss</a></li></ol></p><img src="http://feeds.feedburner.com/~r/vineetmanohar/~4/ISgqSBw7P20" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/</feedburner:origLink></item>
		<item>
		<title>How to rotate Tomcat catalina.out</title>
		<link>http://feedproxy.google.com/~r/vineetmanohar/~3/XvobHZ9KLf0/</link>
		<comments>http://www.vineetmanohar.com/2010/03/howto-rotate-tomcat-catalina-out/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 19:21:20 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[automati]]></category>
		<category><![CDATA[catalina.out]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[logrotate]]></category>
		<category><![CDATA[rotate]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=935</guid>
		<description><![CDATA[If catalina.out becomes 2GB in size, tomcat crashes and fails to start without any error message. To avoid this scenario you should rotate the catalina.out frequently. This article describes how to setup auto rotation of catalina.out on a linux/unix machine.


Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/06/howto-auto-recover-tomcat-crashes/' rel='bookmark' title='Permanent Link: How to automatically recover Tomcat from crashes'>How to automatically recover Tomcat from crashes</a></li><li><a href='http://www.vineetmanohar.com/2010/03/cache-java-webapps-with-squid-reverse-proxy/' rel='bookmark' title='Permanent Link: Cache Java webapps with Squid Reverse Proxy'>Cache Java webapps with Squid Reverse Proxy</a></li><li><a href='http://www.vineetmanohar.com/2010/06/getting-started-with-nexus-maven-repo-manager/' rel='bookmark' title='Permanent Link: Getting started with Nexus Maven Repo Manager'>Getting started with Nexus Maven Repo Manager</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/03/howto-rotate-tomcat-catalina-out/';
var dzone_title = 'How to rotate Tomcat catalina.out';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>If catalina.out becomes 2GB in size, tomcat crashes and fails to start without any error message. To avoid this scenario you should rotate catalina.out frequently. This article describes how to setup auto rotation of catalina.out on a linux/unix machine.</p>
<h3>How to automatically rotate catalina.out daily or when it becomes bigger than 5M</h3>
<p><strong>1. Create this file </strong></p>
<pre name="code" class="css">/etc/logrotate.d/tomcat</pre>
<p><strong>2. Copy the following contents into the above file</strong></p>
<pre name="code" class="css">/var/log/tomcat/catalina.out {
 copytruncate
 daily
 rotate 7
 compress
 missingok
 size 5M
}</pre>
<p>About the above configuration:</p>
<ul>
<li>Make sure that the path <strong>/var/log/tomcat/catalina.out</strong> above is adjusted to point to your tomcat&#8217;s catalina.out</li>
<li><strong>daily <strong>- </strong></strong>rotates the catalina.out <strong>daily</strong></li>
<li><strong>rotate</strong> &#8211; keeps at most <strong>7</strong> log files</li>
<li><strong>compress &#8211; </strong>compresses<strong> </strong>the rotated files</li>
<li><strong>size</strong> &#8211; rotates if the size of catalina.out is bigger than <strong>5M</strong></li>
<li><strong>copytruncate</strong> &#8211; truncates the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one, It can be used when some program can not be told to close its logfile and thus might continue writing (appending) to the previous log file forever. <strong>Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost</strong>. When this option is used, the create option will have no effect, as the old log file stays in place.</li>
</ul>
<p>You don&#8217;t need to do anything else.</p>
<h3>How it works</h3>
<ol>
<li>Every night the cron daemon runs jobs listed in the <strong>/etc/cron.daily/</strong> directory</li>
<li>This triggers the <strong>/etc/cron.daily/logrotate</strong> file which is generally shipped with linux installations. It runs the command &#8220;<strong>/usr/sbin/logrotate /etc/logrotate.conf</strong>&#8220;</li>
<li>The <strong>/etc/logrotate.conf<strong> </strong></strong>includes all scripts in the<strong><strong> </strong><strong>/etc/logrotate.d/ </strong></strong>directory.</li>
<li>This triggers the <strong>/etc/logrotate.d/tomcat</strong> file that you wrote in the previous step.</li>
</ol>
<h3>Run logrotate manually</h3>
<p>Run the following command to run the cron job manually</p>
<pre name="code" class="css">/usr/sbin/logrotate /etc/logrotate.conf</pre>
<h3>Is it completely safe?</h3>
<p>See the description of copytruncate method above. There is a slight chance of a small amount of logging data loss between copy and truncate steps, usually it is acceptable but sometimes its not.</p>
<h3>More logrotate options</h3>
<p>To see all logrotate options on your system, see the manual:</p>
<pre name="code" class="css">man logrotate</pre>


<p>Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/06/howto-auto-recover-tomcat-crashes/' rel='bookmark' title='Permanent Link: How to automatically recover Tomcat from crashes'>How to automatically recover Tomcat from crashes</a></li><li><a href='http://www.vineetmanohar.com/2010/03/cache-java-webapps-with-squid-reverse-proxy/' rel='bookmark' title='Permanent Link: Cache Java webapps with Squid Reverse Proxy'>Cache Java webapps with Squid Reverse Proxy</a></li><li><a href='http://www.vineetmanohar.com/2010/06/getting-started-with-nexus-maven-repo-manager/' rel='bookmark' title='Permanent Link: Getting started with Nexus Maven Repo Manager'>Getting started with Nexus Maven Repo Manager</a></li></ol></p><img src="http://feeds.feedburner.com/~r/vineetmanohar/~4/XvobHZ9KLf0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/03/howto-rotate-tomcat-catalina-out/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.vineetmanohar.com/2010/03/howto-rotate-tomcat-catalina-out/</feedburner:origLink></item>
		<item>
		<title>Cache Java webapps with Squid Reverse Proxy</title>
		<link>http://feedproxy.google.com/~r/vineetmanohar/~3/znWrrVye7zE/</link>
		<comments>http://www.vineetmanohar.com/2010/03/cache-java-webapps-with-squid-reverse-proxy/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 00:37:19 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[reverse proxy]]></category>
		<category><![CDATA[squid]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=132</guid>
		<description><![CDATA[This article shows you step by step how to cache your entire tomcat web application using Squid reverse Proxy without writing any java code. Cache your entire website as static HTML files stored in memory or disk. This technique is useful to when dynamically generated pages in Java are time and CPU intensive. Ideal scenario is when there are high number of reads and few writes. Caution: do not use this approach to cache secure pages. Read article for full details.


Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/06/howto-auto-recover-tomcat-crashes/' rel='bookmark' title='Permanent Link: How to automatically recover Tomcat from crashes'>How to automatically recover Tomcat from crashes</a></li><li><a href='http://www.vineetmanohar.com/2010/03/howto-rotate-tomcat-catalina-out/' rel='bookmark' title='Permanent Link: How to rotate Tomcat catalina.out'>How to rotate Tomcat catalina.out</a></li><li><a href='http://www.vineetmanohar.com/2009/12/publishing-to-maven-central-repo-in-5-steps/' rel='bookmark' title='Permanent Link: Publishing to Maven Central Repo in 5 steps'>Publishing to Maven Central Repo in 5 steps</a></li></ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/03/cache-java-webapps-with-squid-reverse-proxy/';
var dzone_title = 'Cache Java webapps with Squid Reverse Proxy';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>This article shows you step by step how to cache your entire tomcat web application with Squid reverse Proxy without writing any java code.</p>
<h2>What is Squid</h2>
<p><a title="Squid official website" href="http://www.squid-cache.org/" target="_blank">Squid</a> is a free proxy server for HTTP, HTTPS and FTP which saves bandwidth and increases response time by caching frequently requested web pages. While squid can be used as a proxy server when users try to download pages from the internet, it can be also used as a reverse-proxy by putting squid between the user and your webapp. All user requests first hit Squid. If the requested page already exists in Squid&#8217;s cache it is served directly from the cache without hitting your Webapp. If the page does not exist in Squid&#8217;s cache, it is fetched from your web application and stored in the cache for future requests.</p>
<p>Squid reduces hits to your server by caching response pages. You don&#8217;t have to worry about building page level caching in every application that your write, Squid takes care of that part.</p>
<h2>When should I use Squid</h2>
<p>Ideally you should use Squid for pages which have a high ratio of reads to writes. In other words, a page that changes less frequently but is accessed very often. Here are some scenarios:</p>
<ul>
<li>A dynamical web page which displays news and is updated once an hour, and receives hundreds of hits during the hour</li>
<li>A static web page accessed freqently. Squid can give performance boost by caching frequently accessed static web pages in memory</li>
</ul>
<h2>When should I not use Squid</h2>
<p>In most cases, if the request URL is the only factor which determines the response then you can safely use Squid. See more specific examples below:</p>
<ul>
<li>If the entire apps is very dynamic in nature, and the validity of pages changes immediately.</li>
<li>Squid is not suitable for apps which require login. This unfortunately is a large number of applications. Such applications need to resort to back end caching, for example use other caching frameworks like Ehcache to cache re-usable page fragments and/or cache database queries and/or other performance bottlenecks.</li>
<li>Apps which heavily use browser cookies. Squid relies on URLs to cache pages. If the page served is computed from URLs + cookies, then you should not cache those pages in Squid.</li>
</ul>
<h2>How does the overall setup work</h2>
<p><div id="attachment_858" class="wp-caption alignnone" style="width: 484px"><img class="size-full wp-image-858 " title="Apache Squid Tomcat architecture" src="http://www.vineetmanohar.com/wp-content/uploads/2010/02/Apache-Squid-Tomcat-architecture1-e1266359786104.png" alt="Apache Squid Tomcat architecture" width="474" height="568" /><p class="wp-caption-text">Apache Squid Tomcat architecture</p></div><br />
Apache receives requests on port 80. Apache calls Squid with the request. Squid checks its cache to see if it has the response cached from before. If yes and if the response is not expired, it returns the cached response.In this case:</p>
<p>Squid will write the following header to the response:</p>
<pre name="code" class="xml">X-Cache: HIT from www.vineetmanohar.com</pre>
<p>If the response is not found in Squid&#8217;s cache, squid will make a call to Tomcat on port 8082. Tomcat&#8217;s proxy connector is listening on this port. It processes the request and sends the response back to Squid. Squid saves the response in its cache, unless caching is disabled for that URL. Squid returns the final response to Apache which sends the response back to the user.</p>
<h2>What if I don&#8217;t want to use Apache</h2>
<p>Using Apache is not required to use Squid. You can run Squid on port 80, and point your users directly to Squid. If that is the case, skip section one and directly jump to section 2 below.</p>
<h2>Step 1/3: Apache Httpd Config</h2>
<p>If you are using Apache as a front end, you need to instruct Apache to forward requests to Squid at port 3128. See the following code snippet. Change the server name and paths to reflect your real values.</p>
<p>Apache config file:</p>
<pre name="code" class="xml">/etc/httpd/conf/httpd.conf</pre>
<pre name="code" class="xml">&lt;VirtualHost x.x.x.x&gt;
ServerName www.vineetmanohar.com
DocumentRoot /home/webadmin/www.vineetmanohar.com/html
# forward requests to squid running on port 3128
ProxyPass / http://localhost:3128/
ProxyPassReverse / http://localhost:3128/
&lt;/VirtualHost&gt;</pre>
<p>In addition to the above, you also need <strong>mod_proxy</strong> installed. If you see the following in your httpd.conf, you probably already have mod_proxy installed. If you first need to <a href="http://www.google.com/search?q=installing+mod_proxy+apache" target="_blank">install mod_proxy</a>.</p>
<pre name="code" class="xml">LoadModule  proxy_module         modules/mod_proxy.so
LoadModule  proxy_http_module    modules/mod_proxy_http.so</pre>
<h2>Step 2/3: Squid Config</h2>
<p>First make sure that Squid is installed on your server. You can download Squid from <a href="http://www.squid-cache.org/Download/" target="_blank">here</a>.</p>
<p>The squid config file on Linux/Unix is located at this location.</p>
<pre name="code" class="xml">/etc/squid/squid.conf</pre>
<p>The config file is pretty long. Follow these instructions and set the values appropriately.</p>
<pre name="code" class="xml"># leave the port to 3128
http_port 3128

# how much memory cache do you want? depends on how much memory you have on the machine
cache_mem 200 MB

# what's the biggest page that you want stored in memory. If you home page is 100 KB and
# you want it stored in memory, you may set it to a number bigger than that.
maximum_object_size_in_memory 100 KB

# how much disk cache do you want. It is 6400 MB in the following example, change it as per
# your needs. Make sure you have that much disk space free.
cache_dir ufs /var/spool/squid 6400 16 256

# this is probably the most important config section. Here you can configure the cache life for
# each URL pattern. 

# Time is in minutes
# 1 day = 1440, 2 days = 2880, 7 days = 10080, 28 days = 40320

# do not cache url1
refresh_pattern ^http://127.0.0.1:8082/url1/           0     20%    0

# cache url2 for 1 day
refresh_pattern ^http://127.0.0.1:8082/url2/        1440     20%    1440 override-expire override-lastmod reload-into-ims ignore-reload

# cache css for 7 days
refresh_pattern ^http://127.0.0.1:8082/css         10080     20%   10080  override-expire override-lastmod reload-into-ims ignore-reload

# by default cache the whole website for 1 minute
refresh_pattern ^http://127.0.0.1:8082/                0     20%       0 override-expire override-lastmod reload-into-ims ignore-reload

# how long should the errors should be cached for. For example 404s, HTTP 500 errors
negative_ttl 0 seconds

# On which host does tomcat run. Set 127.0.0.1 for localhost
httpd_accel_host 127.0.0.1

# this is the proxy port as defined in Tomcat server.xml. By default it is "8082"
httpd_accel_port 8082

# set this to "on". Read more documentation if you want to change this.
httpd_accel_single_host on

# To access Squid stats via the manager interface, you need to enter a password here
cachemgr_passwd your_clear_text_password all

# Say "off" if you want the query string to appear in the squid logs.
strip_query_terms off</pre>
<h2>Step 3/3: Tomcat Config</h2>
<p>Make sure that the HTTP Proxy Connector is defined in <strong>TOMCAT_HOME/conf/server.xml</strong>.</p>
<pre name="code" class="xml">&lt;Service name="Catalina"&gt;</pre>
<pre name="code" class="xml">&lt;Connector port="8082"
 maxThreads="50" minSpareThreads="5" maxSpareThreads="10"
 enableLookups="false" acceptCount="100" connectionTimeout="20000"
 proxyName="www.vineetmanohar.com"
 compressableMimeType="text/html,text/xml,text/css,text/javascript,text/plain" compression="on"
 proxyPort="80" disableUploadTimeout="true" /&gt;</pre>
<p>If needed, see additional documentation on <a href="http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html" target="_blank">Tomcat proxy connector</a>.</p>
<h2>Squid Manager Interface</h2>
<p>You can access the Squid config and stats via the Squid Manger HTTP interface. Make sure that the &#8220;cachemgr.cgi&#8221; file which ships with squid installation is in your cgi-bin directory. More documentation on setting that up <a href="http://www.faqs.org/docs/securing/chap28sec235.html" target="_blank">here</a>.</p>
<p>Once you&#8217;ve set it up, you can access the cache manager via this URL:</p>
<pre name="code" class="xml">http://&lt;hostname&gt;/cgi-bin/cachemgr.cgi</pre>
<p>To continue enter the following values:</p>
<pre name="code" class="xml">Cache host: localhost
Cache port: 3128
Manager name: manager
Password: &lt;the value you entered for "cachemgr_passwd" in squid.conf&gt;</pre>
<ul>
<li><strong>Store Directory Stats</strong> shows you how much disk space is used by the disk cache.</li>
<li><strong>Cache Client List</strong> show you the cache HIT/MISS ratio as %. You should monitor this frequently and tune your cache to get a higher hit %.</li>
</ul>
<h2>Reload Squid Config without restarting</h2>
<p>Edit the squid config using &#8220;vi&#8221; or your favorite editor.</p>
<pre name="code" class="xml">vi /etc/squid/squid.conf</pre>
<p>Once you are done editing, reload the new config without restarting Squid.</p>
<pre name="code" class="xml">/usr/sbin/squid -k reconfigure</pre>
<h2>Clearing Squid Cache</h2>
<p>To clear Squid cache:</p>
<p>1) Set the memory cache to 4 MB (or a lower number)</p>
<pre name="code" class="xml">cache_mem 8 MB</pre>
<p>2) Set the disk cache to 8 MB (or a lower number). The disk cache must be higher that the memory cache.</p>
<pre name="code" class="xml">cache_dir ufs /var/spool/squid 20 16 256</pre>
<p>3) Reload squid config without restart as described in the previous section</p>
<p>4) You may need to wait a few hours for the cache to get cleared. Once the cache is clear, you may restore the previous cache sizes and reload the new config again. You can monitor the cache size through the Squid Manager HTTP interface.</p>
<h2>Bypassing Squid</h2>
<p>If for some reason you need to bypass Squid, reconfigure Apache to directly send requests to Tomcat. Edit the Apache config file <strong>/etc/httpd/conf/httpd.conf</strong></p>
<pre name="code" class="xml"># forward requests directly to Tomcat's proxy connector running on port 8082
ProxyPass        / http://localhost:8082/
ProxyPassReverse / http://localhost:8082/</pre>
<p>You will need to restart Apache after making this change.</p>
<pre name="code" class="xml">/etc/init.d/httpd restart</pre>
<h2>Conclusion</h2>
<p>Squid is a very powerful tool for caching. It is not for all applications. Please examine the need of your application and use squid appropriately. I&#8217;ve used squid for several years for caching the output from a Java data mashup application and am very satisfied with the ease of use and benefits. Hope you found this tutorial useful. Feel free to post a comment or share your experience with squid.</p>
<h2>References</h2>
<p><a title="Squid official website" href="http://www.squid-cache.org/" target="_blank">Squid official website</a></p>


<p>Related posts:<ol><li><a href='http://www.vineetmanohar.com/2010/06/howto-auto-recover-tomcat-crashes/' rel='bookmark' title='Permanent Link: How to automatically recover Tomcat from crashes'>How to automatically recover Tomcat from crashes</a></li><li><a href='http://www.vineetmanohar.com/2010/03/howto-rotate-tomcat-catalina-out/' rel='bookmark' title='Permanent Link: How to rotate Tomcat catalina.out'>How to rotate Tomcat catalina.out</a></li><li><a href='http://www.vineetmanohar.com/2009/12/publishing-to-maven-central-repo-in-5-steps/' rel='bookmark' title='Permanent Link: Publishing to Maven Central Repo in 5 steps'>Publishing to Maven Central Repo in 5 steps</a></li></ol></p><img src="http://feeds.feedburner.com/~r/vineetmanohar/~4/znWrrVye7zE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/03/cache-java-webapps-with-squid-reverse-proxy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.vineetmanohar.com/2010/03/cache-java-webapps-with-squid-reverse-proxy/</feedburner:origLink></item>
	</channel>
</rss>
