<?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>Techtracer &#187; Tutorials</title>
	<atom:link href="http://techtracer.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://techtracer.com</link>
	<description>Tracing the course of Web Technology</description>
	<lastBuildDate>Tue, 06 Jan 2009 12:14:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
  <link>http://techtracer.com</link>
  <url>http://techtracer.com/wp-includes/images/favicon.png</url>
  <title>Techtracer</title>
</image>
		<item>
		<title>The Great Hibernate Tutorial &#8211; a great jump start for beginners</title>
		<link>http://techtracer.com/2008/12/30/the-great-hibernate-tutorial-a-great-jump-start-for-beginners/</link>
		<comments>http://techtracer.com/2008/12/30/the-great-hibernate-tutorial-a-great-jump-start-for-beginners/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 05:42:17 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Beginner tutorial for hibernate]]></category>
		<category><![CDATA[Hibernate Tutorial]]></category>
		<category><![CDATA[steps for hibernate setup]]></category>

		<guid isPermaLink="false">http://techtracer.com/?p=278</guid>
		<description><![CDATA[Hibernate has become the de-facto ORM (Object Relational Mapping) framework for most of the organizations today. It provides a very simple framework to overcome the cumbersome techniques involved with core JDBC implementations. Whenever there is a project based on database intrinsic activities it is advisable to use Hibernate than do JDBC coding. It saves a [...]]]></description>
			<content:encoded><![CDATA[<p>Hibernate has become the de-facto <strong>ORM</strong> (<a href="http://en.wikipedia.org/wiki/Object-relational_mapping" target="_blank">Object Relational Mapping</a>) framework for most of the organizations today. It provides a very simple framework to overcome the cumbersome techniques involved with core <strong>JDBC</strong> implementations. Whenever there is a project based on database intrinsic activities it is <strong>advisable</strong> to use Hibernate than do JDBC coding. It saves a huge amount of time revolving around unnecessary chores. </p>
<p>Having said that, the major question which strikes anyone who does majorly JDBC is that how does a Hibernate DAO layer look like. Without looking at a practical implementation one cannot be easily convinced to work on it. This is the only compelling reason why I intended to write <strong>The</strong> <strong>Great Hibernate Tutorial</strong>.</p>
<p>This tutorial is aimed at those developers who want to get a<strong> </strong>quick breifing on <strong>how to implement a DAO layer using Hibernate</strong>. This tutorial does not cover the basics of ORM nor a detailed explanation of Hibernate configurations or api. It follows on the same route as the <a href="http://techtracer.com/2007/04/16/the-great-ant-tutorial-a-great-jump-start/" target="_self">Great Ant tutorial</a> which many readers liked.</p>
<p><strong>5 Steps to Designing a DAO in Hibernate:</strong></p>
<ol>
<li> Identify the tables which are required as entities in your project</li>
<li>Create the Hibernate Configuration file</li>
<li>Create the Hibernate entity mapping files (hbm) and entity classes</li>
<li>Make the DAO layer with the required functions</li>
<li>Test the DAO classes</li>
</ol>
<p><strong>Required Softwares</strong></p>
<p>The versions of the various open source software&#8217;s required for the implementation are</p>
<ul>
<li><a href="http://dev.mysql.com/downloads/mysql/5.1.html#win32" target=_blank>MySQL 5.0.5 for Windows</a></li>
<li><a href="http://dev.mysql.com/downloads/connector/j/5.0.html" target=_blank>MySQL ConnectorJ</a></li>
<li><a href="http://www.hibernate.org/6.html#A2" target=_blank>Hibernate Core 3.0</a></li>
<li><a href="http://java.sun.com/javase/downloads/index.jsp" target=_blank>JDK 1.5 or above</a></li>
<li><a href="http://www.eclipse.org/downloads/" target=_blank>Eclipse 3.3 or above</a></li>
</ul>
<p>So lets get going with<strong> the Great Hibernate Tutorial</strong>. The steps will explain you the specific details from the code while the actual code is present in the format of links at the <a href="#resources">bottom of this tutorial</a>. You can open the links in different tabs of your browser and then start reading the tutorial for getting a better understanding.</p>
<p><strong>Step 1. Identify the tables which are required as entities in your project</strong></p>
<p>For the tutorial I am designing a basic<strong> Attendance System</strong> for a company which currently has only two tables <strong>Employee</strong> and <strong>Dept</strong>. If your MySQL is not setup at the moment you may visit the tutorial on <a href="http://techtracer.com/2008/06/09/3-easy-steps-to-install-mysql-on-windows-xp/" target="_self">how to setup Mysql in windows XP</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`employee`</span> <span style="color: #FF00FF;">&#40;</span>                                                                                       
            <span style="color: #008000;">`psno`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">11</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">'0'</span><span style="color: #000033;">,</span>                                                                          
            <span style="color: #008000;">`name`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>                                                                              
            <span style="color: #008000;">`pass`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>                                                                              
            <span style="color: #008000;">`proj<span style="color: #008080; font-weight: bold;">_</span>cd`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>                                                                               
            <span style="color: #008000;">`dept<span style="color: #008080; font-weight: bold;">_</span>name`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>                                                                             
            <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #990099; font-weight: bold;">USING</span> <span style="color: #990099; font-weight: bold;">BTREE</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`psno`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>                                                                            
            <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`FK<span style="color: #008080; font-weight: bold;">_</span>employee<span style="color: #008080; font-weight: bold;">_</span>newfk`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`proj<span style="color: #008080; font-weight: bold;">_</span>cd`</span><span style="color: #000033;">,</span><span style="color: #008000;">`dept<span style="color: #008080; font-weight: bold;">_</span>name`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>                                                              
            <span style="color: #990099; font-weight: bold;">CONSTRAINT</span> <span style="color: #008000;">`employee<span style="color: #008080; font-weight: bold;">_</span>ibfk<span style="color: #008080; font-weight: bold;">_</span>1`</span> <span style="color: #990099; font-weight: bold;">FOREIGN KEY</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`proj<span style="color: #008080; font-weight: bold;">_</span>cd`</span><span style="color: #000033;">,</span> <span style="color: #008000;">`dept<span style="color: #008080; font-weight: bold;">_</span>name`</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">REFERENCES</span> <span style="color: #008000;">`dept`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`PROJ<span style="color: #008080; font-weight: bold;">_</span>CD`</span><span style="color: #000033;">,</span> <span style="color: #008000;">`DEPT<span style="color: #008080; font-weight: bold;">_</span>NAME`</span><span style="color: #FF00FF;">&#41;</span>  
          <span style="color: #FF00FF;">&#41;</span> 
&nbsp;
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`dept`</span> <span style="color: #FF00FF;">&#40;</span>                   
          <span style="color: #008000;">`PROJ<span style="color: #008080; font-weight: bold;">_</span>CD`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>       
          <span style="color: #008000;">`DEPT<span style="color: #008080; font-weight: bold;">_</span>NAME`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>     
          <span style="color: #008000;">`START<span style="color: #008080; font-weight: bold;">_</span>DATE`</span> <span style="color: #999900; font-weight: bold;">date</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>       
          <span style="color: #008000;">`TYPE`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>      
          <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`PROJ<span style="color: #008080; font-weight: bold;">_</span>CD`</span><span style="color: #000033;">,</span><span style="color: #008000;">`DEPT<span style="color: #008080; font-weight: bold;">_</span>NAME`</span><span style="color: #FF00FF;">&#41;</span>  
        <span style="color: #FF00FF;">&#41;</span></pre></div></div>

<p>The Employee and Dept have a one to many relationship. From the DDL it is evident that Dept table has composite keys. Usually <a href="http://codebetter.com/blogs/jeremy.miller/archive/2007/02/01/Composite-keys-are-evil.aspx" target="_blank">composite keys are considered evil</a> , but I am using it just for the sake of presenting a use case of <strong>configuring composite keys in hibernate</strong>.</p>
<p><strong>Step 2. Create the Hibernate Configuration file </strong></p>
<p>The Hibernate configuration file is where you provide all the connection level details. It is very straightforward configuration and appears similar to your JDBC connection statements. But unlike JDBC, you can specify many more things here like <strong>caching, dialects, debug queries</strong>. One important aspect of this configuration file is providing path of <strong>hbm</strong> files. Check the following two line of XML.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapping</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;com/abc/entities/Employee.hbm.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>     
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapping</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;com/abc/entities/Dept.hbm.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>These lines are important. They specify the paths to your entity mapping files. Entity mapping files are those <strong>XML files</strong> which tell hibernate as to how the entity classes relate to the tables. It defines how the data should flow from class properties to the table columns. But you have to be careful in mentioning the <strong>paths</strong> to the mapping files. It is not required that the files be kept in the packages as I have done but it is considered a convention.</p>
<p><strong>Step 3. Create the Hibernate entity mapping files (hbm) and entity classes</strong></p>
<p>In this step we would be actually defining the <strong>mapping</strong>. I have kept all the entities in the package <strong>com.abc.entities</strong> along with the mapping files. The first element is obvious <em>&lt;hibernate-mapping&gt;</em>. Within this element you would most of the times define 3 elements: Class, ID and Property.</p>
<p><strong>Class</strong> &#8211; the class for which mapping to the table is being defined</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;com.abc.entities.Employee&quot;</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">&quot;employee&quot;</span> <span style="color: #000066;">lazy</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p>One extra attribute of the element you would notice is lazy=&#8221;false&#8221;. This is the lazy loading technique of ORM the details of which are beyond the scope of this tutorial. You may even not mention it.</p>
<p><strong>ID &#8211; Primary key</strong> is an absolute must in hibernate mapped tables. Primary Keys are mapped to ID as follows</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;psno&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;psno&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generator</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;assigned&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Generator </strong>means how the primary key is populated. If it was <strong>auto generated</strong> in the table then the value should have been &#8220;<strong>auto</strong>&#8220;. The value &#8220;<strong>assigned</strong>&#8221; means we will set it in the application itself. In case of Dept, since composite key exists we should define it as</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite-id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;deptPK&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.abc.entities.DeptPK&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;projCode&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;PROJ_CD&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;deptName&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;DEPT_NAME&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Property</strong> &#8211; These are columns which would be made as properties having getters and setters in the class definition</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>this would map name property of Employee class to the name column of employee table.</p>
<p><span style="text-decoration: underline;"><strong>Associations in Hibernate</strong></span></p>
<p>The above 3 are majorly used. Apart from that you can also mention <strong>cardinality mapping</strong> if required as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;many-to-one</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dept&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.abc.entities.Dept&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;proj_cd&quot;</span> <span style="color: #000066;">not-null</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dept_name&quot;</span> <span style="color: #000066;">not-null</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/many-to-one<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Since I have a <strong>composite key</strong> in Dept table I have mentioned two columns in the above mapping. This mapping can be read as &#8220;<em>MANY Employees are related TO ONE Dept with help of COLUMNS proj_cd and dept_name</em>&#8220;. These mappings are called as <strong>Associations </strong>in hibernate.</p>
<p>In the Dept mapping file since one dept can return <strong>multiple</strong> Employees, they would be returned in the form of a<strong> set</strong>. Hence we would have to map the set of Employee as:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;employees&quot;</span> <span style="color: #000066;">inverse</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;proj_cd&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dept_name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;one-to-many</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.abc.entities.Employee&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The<strong> inverse=&#8221;true&#8221;</strong> says that the association is <strong>bidirectional</strong> which is another important concept in hibernate. In a bidirectional relationship you can reach an associated element from within one element and same applies the other way too. On the contrary you may even have <strong>unidirectional</strong> relationship in which you don&#8217;t specify mapping in the other classes.</p>
<p><span style="text-decoration: underline;"><strong>Defining Entity classes</strong></span></p>
<p>This is straight forward. Entity classes are simple <a href="http://en.wikipedia.org/wiki/JavaBeans" target="_blank">Java Beans</a>. You can view the class definition in the links provided at the bottom of this post. A <strong>no argument public constructor </strong>is a must in case you define a custom one.</p>
<p>One special case here would be for composite keys. Composite keys are defined in a <strong>separate class</strong>. After this, In the class where composite keys are required you would have to make a property of the composite-class-type.</p>
<p><strong>Step 4. Make the DAO layer with the required functions</strong></p>
<p>Finally we are the moment of salvation. The thing which we were waiting eagerly for implementing. The DAO layer. It is always a good practice to make a separate DAO class for holding utility functions. Hibernate requires that you always open a <strong>session</strong> before accessing the database and making <strong>transactions </strong>when you update the database. This requires repeatable lines of code.</p>
<p>So in order to avoid repeating ourselves its better to keep these lines of code in a DAO class as shown in the links below. Check for <em><strong>com.abc.dao.DAO.java</strong></em>. You may use the class as it is since it is a routine code. For coding your own classes to make use of the utility functions in the DAO extend your class with this <em><strong>DAO.</strong></em></p>
<p>Lets have a look at <em><strong>AdminDAO</strong></em>. Since I belive in interface based implementations I have provided <em><strong>AdminDAO</strong></em> as an interface and <em><strong>AdminDAOHibernateImpl</strong></em> as its implementation which extends <em><strong>DAO</strong></em>. The code is kept simple for understanding purposes. The things worth pondering are:</p>
<p>In functions which do an update on the tables you have to carry the following steps:</p>
<ol>
<li>begin();</li>
<li>getSession()&#8230;.; // save or update</li>
<li>commit();</li>
<li>rollback();  //in case of HibernateException and throw any custom business exception if required</li>
</ol>
<p>For fetching data you don&#8217;t need transactions so you don&#8217;t need to do the above steps. In this case you can just execute a query via the <em>getSession() </em>as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #003399; font-weight: bold;">Query</span> q = getSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Employee e inner join fetch e.dept where e.psno = :psno&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
q.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;psno&quot;</span>, psno.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Employee emp = <span style="color: #009900;">&#40;</span>Employee<span style="color: #009900;">&#41;</span> q.<span style="color: #006633;">uniqueResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span style="text-decoration: underline;"><strong>Hibernate Query Language</strong></span></p>
<p>The above query syntax is called <strong>HQL (Hibernate Query Language)</strong>. It is syntactically very similar to JDBC with the difference that HQL queries are based on objects and not on tables so the names are <strong>case sensitive</strong> and <strong>aliases</strong> to objects are a must.</p>
<p>In HQL, you can either fetch a single result when you know that there would be exactly one row fetched. When you know that mutiple records might be returned then you can fetch the list as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #003399; font-weight: bold;">Query</span> q = getSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Employee&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
List<span style="color: #339933;">&lt;</span>Employee<span style="color: #339933;">&gt;</span> list = q.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span> list<span style="color: #339933;">;</span></pre></div></div>

<p><span style="text-decoration: underline;"><strong>Paging in Hibernate</strong></span></p>
<p>You can obtain paging in Hibernate very easily without any additional efforts by applying a max results criteria</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">q.<span style="color: #006633;">setFirstResult</span><span style="color: #009900;">&#40;</span>firstResult<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
q.<span style="color: #006633;">setMaxResults</span><span style="color: #009900;">&#40;</span>maxResults<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Doesn&#8217;t it feel really good. JDBC users might feel jealous at this time1</p>
<p><strong>Step 5. Test the DAO classes</strong></p>
<p>Now, to our final strike. The testing can be done with POJO&#8217;s. For the tutorial I had created a service layer since I usally access teh DAO layer through the service layer. So the testing was done on the service layer instead of the DAO as this application was small. You can however test out directly the DAO functions.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">static</span> <span style="color: #006600; font-weight: bold;">void</span> listTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
		List<span style="color: #339933;">&lt;</span>Employee<span style="color: #339933;">&gt;</span> employees = adminService.<span style="color: #006633;">getAllEmployees</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000;  font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Employee emp: employees<span style="color: #009900;">&#41;</span>
			<span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>emp.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>AppException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Wasn&#8217;t that a breeze? I hope that it was. Once you gain a thorough knowledge of <strong>ORM concepts </strong>then you would appreciate working with <strong>Hibernate</strong> even more. For further knowledge, I would recommend you to go through the <a href="http://en.wikipedia.org/wiki/Object-Relational_impedance_mismatch" target="_blank">impedence mismatch theory</a> to know the fundamental flaws surrounding JDBC. Working with Hibernate would then be real fun.</p>
<p>Enjoy folks!<br />
<a name="resources"></a><br />
<u><strong>Resources for the tutorial</strong></u></p>
<p>The below files are required for running the above tutorial. Copy these to your eclipse project and add the required libraries of hibernate and mysql before running the project.</p>
<p><em>Configuration</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/hibernatecfg.xml' target=_blank>hibernate.cfg.xml</a></p>
<p><em>Package: com.abc.entities</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/employeejava.txt' target=_blank>com.abc.entities.Employee.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/employeehbm.xml' target=_blank>Employee.hbm.xml</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/deptjava.txt' target=_blank>com.abc.entities.Dept.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/deptpkjava.txt' target=_blank>com.abc.entities.DeptPK.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/depthbm.xml' target=_blank>Dept.hbm.xml</a></p>
<p><em>Package: com.abc.dao</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/daojava.txt' target=_blank>com.abc.dao.DAO.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/admindaojava.txt' target=_blank>com.abc.dao.AdminDAO.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/admindaohibernateimpljava.txt' target=_blank>com.abc.dao.AdminDAOHibernateImpl.java</a></p>
<p><em>Package: com.abc.service</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/adminservicejava.txt' target=_blank>com.abc.service.AdminService.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/adminserviceimpljava.txt' target=_blank>com.abc.service.AdminServiceImpl.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/deptservicejava.txt' target=_blank>com.abc.service.DeptService.java</a><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/deptserviceimpljava.txt' target=_blank>com.abc.service.DeptServiceImpl.java</a></p>
<p><em>Package: com.abc.exceptions</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/appexceptionjava.txt' target=_blank>com.abc.exceptions.AppException.java</a></p>
<p><em>Package: com.abc.tests</em><br />
<a href='http://techtracer.com/wp-content/uploads/2008/12/depttestjava.txt' target=_blank>com.abc.tests.DeptTest.java</a></p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/" rel="bookmark" title="Permanent Link: The Technique of Virtual Deployment in Tomcat">The Technique of Virtual Deployment in Tomcat</a></li><li><a href="http://techtracer.com/2007/04/16/the-great-ant-tutorial-a-great-jump-start/" rel="bookmark" title="Permanent Link: The Great Ant Tutorial &#8211; a great jump start">The Great Ant Tutorial &#8211; a great jump start</a></li><li><a href="http://techtracer.com/2008/01/09/impressive-google-chart-generator-scripts/" rel="bookmark" title="Permanent Link: Impressive Google Chart Generator Scripts">Impressive Google Chart Generator Scripts</a></li><li><a href="http://techtracer.com/2007/03/09/hello-world/" rel="bookmark" title="Permanent Link: Tracing the route of technology">Tracing the route of technology</a></li><li><a href="http://techtracer.com/2007/10/06/mozillas-new-killer-app-the-webrunner/" rel="bookmark" title="Permanent Link: Mozilla&#8217;s New Killer App &#8211; The WebRunner">Mozilla&#8217;s New Killer App &#8211; The WebRunner</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/12/30/the-great-hibernate-tutorial-a-great-jump-start-for-beginners/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>3 Easy Steps to Install MySQL on Windows XP</title>
		<link>http://techtracer.com/2008/06/09/3-easy-steps-to-install-mysql-on-windows-xp/</link>
		<comments>http://techtracer.com/2008/06/09/3-easy-steps-to-install-mysql-on-windows-xp/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 17:09:34 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://techtracer.com/?p=250</guid>
		<description><![CDATA[This article needed to be written from a long time and since it was not, I almost suffered the same hiccups during the installing of MySQL on Windows XP. Every single time I had to search the internet for the solutions which I often forgot over a period of time.

So today without any procrastination, I [...]]]></description>
			<content:encoded><![CDATA[<p>This article needed to be written from a long time and since it was not, I almost suffered the same hiccups during the <strong>installing of MySQL on Windows XP</strong>. Every single time I had to search the internet for the solutions which I often forgot over a period of time.</p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-251" title="logo_mysql_sun" src="http://techtracer.com/wp-content/uploads/2008/06/logo_mysql_sun.gif" alt="logo_mysql_sun" width="205" height="68" /></p>
<p>So today without any procrastination, I intend to put down the simplest of the steps to configure and run MySQL on Windows XP in the quickest of the time. First and foremost, as I always tend to follow a course is, break down the task into <strong>3 steps</strong>. They are:</p>
<p><strong><span style="text-decoration: underline;">Step 1: Getting the software</span><br />
</strong></p>
<p>Download the latest version of MySQL from the <a href="http://dev.mysql.com/downloads/" target="_blank">community site</a>. Unpack it into your desired folder. It is always a good practice to download the <strong>zipped archive</strong> of MySQL binary distribution since using the one click installer, you might sometimes lose the power of configuration manually.</p>
<p>Its also a better way to understand configuring manually since if you switch to a Unix based environment later on, you will have to carry out a similar procedure and there is usually no one click installer in such environments.</p>
<blockquote><p>I unpacked MySQL in <em>C:\Program Files\mysql-5.0.45-win32</em></p></blockquote>
<p><span style="text-decoration: underline;"><strong>Step 2 :  Configuring the environment</strong></span></p>
<p>While configuring in the Windows environment you have to do two things. One, putting a file having a name <strong>my.ini</strong> in the Windows folder of the operating system. Two, setting the path in your system environment variable. Here&#8217;s what you have to do:</p>
<p><strong>Creating Option File (my.ini)</strong></p>
<p>Go to your installation path of MySQL (In my case it is:  <em>C:\Program Files\mysql-5.0.45-win32</em>) and rename the file <strong>my-medium.ini</strong> to <strong>my.ini</strong>. Open the renamed file in notepad and add the following lines, just beneath the line which says, <strong># The MySQL server</strong> and above the line <strong>port = 3306</strong>:</p>
<blockquote><p>[mysqld]<br />
# set basedir to your installation path<br />
<strong> basedir</strong>=C:/Program Files/mysql-5.0.45-win32<br />
# set datadir to the location of your data directory<br />
<strong> datadir</strong>=D:/workspace/data</p></blockquote>
<p>The second line as shown above is, configuring your database directory. This means, the path which you assign to <strong>datadir </strong>will be the path where your databases will be created. You have to make sure that the path exists before you assign it. There will a data directory in the MySQL installed path. If you provide a <strong>different path</strong> to the data directory than this default one, you <strong>must copy</strong> the <strong>entire contents</strong> of the data directory in that path.</p>
<p>Finally, drop the my.ini file into your Windows directory. In my case, I copied the file into the path <strong>C:/Windows</strong></p>
<p><strong>Setting the environment variable</strong></p>
<p>After completing the above step, goto</p>
<blockquote><p>My Computer &gt; Properties &gt; Advanced &gt;Environment Variables &gt; System variables &gt; Path &gt; Edit</p></blockquote>
<p>In the <strong>Value</strong> box, goto the end of the line and put a <strong>semi colon</strong> and the path of the MySQL <strong>bin </strong>folder. In my case I have put it as:</p>
<blockquote><p>;C:\Program Files\mysql-5.0.45-win32\bin</p></blockquote>
<p>Click <strong>OK </strong>3 times and thats it with the configuration of MySQL. You are all set to test the installation.</p>
<p><span style="text-decoration: underline;"><strong>Step 3: Final Configurations and Running MySQL</strong></span></p>
<p>You are actually good to go for running mysql. For this, open up your command prompt and type in the command <strong>mysqld &#8211;console. </strong>This will start the mysql database server. Whenever you run this command henceforth you will see these lines at the end:</p>
<blockquote><p>[Note] mysqld: ready for connections.<br />
Version: &#8216;5.0.45-community-nt-log&#8217;  socket: &#8221;  port: 3306  MySQL Community Edit<br />
ion (GPL)</p></blockquote>
<p>When you see these lines, it means that mysql has started successfully. Its time to party!</p>
<p>Leave the command prompt open and start up another command prompt. For the first time you should do this:</p>
<blockquote><p>C:\&gt;<strong>mysql -u root -p</strong><br />
Enter password:</p></blockquote>
<p>When it will ask for a password, just hit Enter. It will allow access to you without a password and will show up a prompt as:</p>
<blockquote><p>Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 12<br />
Server version: 5.0.45-community-nt-log MySQL Community Edition (GPL)</p>
<p>Type &#8216;help;&#8217; or &#8216;\h&#8217; for help. Type &#8216;\c&#8217; to clear the buffer.</p>
<p>mysql&gt;</p></blockquote>
<p>Note that your database has <strong>anonymous</strong> access. It is not a secure thing to let it like that. You should always access the database with a password. So for setting up the password you will have to do the below steps. Put in the commands which are highlighted as shown:</p>
<blockquote><p>mysql&gt; <strong>update user set password=PASSWORD(&#8220;admin&#8221;) where User=&#8217;root&#8217;;</strong><br />
Query OK, 0 rows affected (0.00 sec)<br />
Rows matched: 3  Changed: 0  Warnings: 0</p>
<p>mysql&gt; <strong>flush privileges;</strong><br />
Query OK, 0 rows affected (0.00 sec)</p>
<p>mysql&gt; <strong>quit</strong><br />
Bye</p></blockquote>
<p>Once you have done this, try logging into the server again without a password. It must show the below error:</p>
<blockquote><p>C:\Documents and Settings\xpuser&gt;<strong>mysql -u root -p</strong><br />
Enter password:<br />
ERROR 1045 (28000): <strong>Access denied for user &#8216;root&#8217;@'localhost&#8217; (using password: NO)</strong></p></blockquote>
<p>This means, now your database is secure.You should be relieved that your mysql setup has got completed. Now every time you want to start in your database start the server in one command prompt and in the second command prompt login to the database server by doing:</p>
<blockquote><p>C:\&gt;<strong>mysql -u root -p</strong><br />
Enter password: <strong>admin</strong></p></blockquote>
<p>Thats it. Phew! I hope I remember the steps myself and now for my cup of cappuccino.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2008/01/13/how-to-install-windows-live-writer/" rel="bookmark" title="Permanent Link: How To Install Windows Live Writer">How To Install Windows Live Writer</a></li><li><a href="http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/" rel="bookmark" title="Permanent Link: Setting Up SSL on Tomcat In 3 Easy Steps">Setting Up SSL on Tomcat In 3 Easy Steps</a></li><li><a href="http://techtracer.com/2008/12/30/the-great-hibernate-tutorial-a-great-jump-start-for-beginners/" rel="bookmark" title="Permanent Link: The Great Hibernate Tutorial &#8211; a great jump start for beginners">The Great Hibernate Tutorial &#8211; a great jump start for beginners</a></li><li><a href="http://techtracer.com/2007/03/12/xp-installation-the-34-minute-hiccup/" rel="bookmark" title="Permanent Link: XP Installation &#8211; The 34 minute hiccup">XP Installation &#8211; The 34 minute hiccup</a></li><li><a href="http://techtracer.com/2007/11/05/feast-your-eyes-with-firefox-piclens/" rel="bookmark" title="Permanent Link: Feast Your Eyes With Firefox Piclens">Feast Your Eyes With Firefox Piclens</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/06/09/3-easy-steps-to-install-mysql-on-windows-xp/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
		<item>
		<title>Create Beautiful Collages Out Of Your Photos</title>
		<link>http://techtracer.com/2008/05/28/create-beautiful-collages-out-of-your-photos/</link>
		<comments>http://techtracer.com/2008/05/28/create-beautiful-collages-out-of-your-photos/#comments</comments>
		<pubDate>Wed, 28 May 2008 17:47:28 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://techtracer.com/?p=249</guid>
		<description><![CDATA[Did you always think about what creative stuff you can do with your photos? Well, I do most of the times and end up editing some of my most favorite ones and putting in some artistic touch. I always feel that, enriching the photos gives them a whole new dimension to look from. It might [...]]]></description>
			<content:encoded><![CDATA[<p>Did you always think about what creative stuff you can do with your photos? Well, I do most of the times and end up editing some of my most favorite ones and putting in some artistic touch. I always feel that, enriching the photos gives them a whole new dimension to look from. It might be either making it more attractive, more lovable or to enliven the sentiments you attached to them from a long time.</p>
<p>Whatever the reason may be, editing a photograph is no layman&#8217;s job. Sometime people give up half way through when they do not find the required results. I recently found a something which might make your spirit rise higher when you will notice the results you get out of it. The name of the tool is <a href="http://picasa.google.com/" target="_new">Picasa</a>. Its a tool from <strong>Google</strong>. I am sure you must have used it many time to upload your photos to the online <a href="http://picasaweb.google.com/nitinclicks" target="_new">Picasaweb</a>. But did you ever try making collages from it. <strong>Picasa</strong> can generate some really amazing collages out of your precious photos and make them really gift worthy or send it amongst friends as a memoir.</p>
<p style="text-align: center;"><img src="http://picasa.google.com/assets/logo.gif" alt="Picassa_Logo" /></p>
<p>So here&#8217;s how you can make collages out of your photos:</p>
<p style="text-align: center;"><a href="http://picasaweb.google.com/nitinclicks/WaterKingdom/photo#5205463216164148834" target="_new"><img src="http://lh4.ggpht.com/nitinclicks/SD2FNyLTlmI/AAAAAAAAA9A/ivu-ddNCh6E/collage-1.jpg?imgmax=512" alt="Picture_Pile_Collage" width="512" height="384" /></a></p>
<ul style="text-align: left;">
<li>Download and install Picasa if you don&#8217;t have it already <a href="http://picasa.google.com/download/" target="_new">from here</a></li>
<li>When you open it Picasa will start indexing all your image folders</li>
<li>Choose a folder of which you want to make a collage from</li>
<li>Now carefully <strong>select</strong> the photos which are your favorite and which you want inside the collage</li>
<li>Click the <strong>Collage</strong> button in the bottom bar</li>
<li>Your collage will be loaded in the dialog mode</li>
<li>You might not be satisfied with the collage at first so you can try one of the 2 tricks</li>
<li>Press<strong> Shift and drag</strong> your mouse pointer on the collage window. You will see a change in the<strong> layout</strong></li>
<li>Keep trying till you are satisfied with a layout</li>
<li>Sometimes, you might like a layout but not how the pictures are placed</li>
<li>In this case press <strong>Ctrl and drag</strong> the mouse pointer. The layout will be same but the pictures will start to<strong> randomize </strong>in their placement.</li>
<li>Once you are done, hit the <strong>Create</strong> Button and specify <strong>location</strong> as the &#8220;current folder&#8221;</li>
<li>The collage gets created and gives you a chance to <strong>edit</strong> the collage</li>
<li>Here you can try out interesting <strong>presets</strong> which include making the collage black and white or giving it a sepia tone or soft focusing it. You can have real fun over here.</li>
<li>After finishing with the effect choose <strong>file &gt; save</strong>. A backup of the original will automatically be made</li>
<li>So here you are with a amazing memorabilia of your treasured photos. Sounds simple isn&#8217;t it?<a href="http://picasaweb.google.com/nitinclicks/WaterKingdom/photo#5205463216164148834" target="_new"><br />
</a></li>
</ul>
<p style="text-align: left;">You can do different types of collages in Picassa. The one above is called the &#8220;<strong>Picture Pile</strong>&#8220;. The other types include:</p>
<p style="text-align: left;"><strong>Picture Grid</strong></p>
<p style="text-align: center;"><a href="http://picasaweb.google.com/nitinclicks/WaterKingdom/photo#5205463628481009266" target="_new"><img src="http://lh4.ggpht.com/nitinclicks/SD2FlyLTlnI/AAAAAAAAA9g/dtVuJZAVWKE/s288/collage1.jpg" alt="Contact_Sheet_Collage" /></a></p>
<p style="text-align: left;"><strong>Contact Sheet</strong></p>
<p style="text-align: center;"><a href="http://picasaweb.google.com/nitinclicks/WaterKingdom/photo#5205462254091474514" target="_new"><img src="http://lh4.ggpht.com/nitinclicks/SD2EVyLTllI/AAAAAAAAA84/BP5ona4_P6k/s288/collage1.jpg" alt="Picture_Grid_Collage" /></a></p>
<p style="text-align: left;">You can always edit the collage features after saving it. But however there is no provision to change the photos of it later. You would have to again do the above steps for making a new collage.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2007/11/05/feast-your-eyes-with-firefox-piclens/" rel="bookmark" title="Permanent Link: Feast Your Eyes With Firefox Piclens">Feast Your Eyes With Firefox Piclens</a></li><li><a href="http://techtracer.com/2008/06/15/best-tools-for-editing-your-photos-online/" rel="bookmark" title="Permanent Link: Best Tools For Editing Your Photos Online">Best Tools For Editing Your Photos Online</a></li><li><a href="http://techtracer.com/2007/12/20/goa-parade/" rel="bookmark" title="Permanent Link: GOA Parade!">GOA Parade!</a></li><li><a href="http://techtracer.com/contact/" rel="bookmark" title="Permanent Link: Contact">Contact</a></li><li><a href="http://techtracer.com/2007/10/13/hp-snapfish-india-for-cost-effective-printing/" rel="bookmark" title="Permanent Link: HP Snapfish India, For Cost Effective Printing">HP Snapfish India, For Cost Effective Printing</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/05/28/create-beautiful-collages-out-of-your-photos/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The Technique of Virtual Deployment in Tomcat</title>
		<link>http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/</link>
		<comments>http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 16:17:54 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/</guid>
		<description><![CDATA[The most common ways of deploying a web application to Tomcat are either straightaway copy the exploded war file structure to $CATALINA_HOME/webapps or to do the more cumbersome task of compiling the web application to a war file and then using the tomcat manager to upload it. Both ways are the most used ones. But [...]]]></description>
			<content:encoded><![CDATA[<p>The most common ways of deploying a web application to Tomcat are either straightaway copy the exploded <strong>war </strong>file structure to <strong>$CATALINA_HOME/webapps</strong> or to do the more cumbersome task of compiling the web application to a war file and then using the tomcat manager to upload it. Both ways are the most used ones. But did you know there are other ways to deploy a web application to Tomcat. If you consider production environments, then applications are deployed using the deployment commands, if at all Tomcat is used. They can be made more simpler using the <a href="http://techtracer.com/2007/04/16/the-great-ant-tutorial-a-great-jump-start/">ant tasks</a>.</p>
<p>But I am not going to discuss the production environment over here. The topic under scrutiny is how would you deploy your web application virtually to Tomcat. For that we have to know what is virtual deployment and learn about its advantages.</p>
<p><strong>What is virtual deployment?</strong></p>
<p>Virtual deployment in simple terms means deploying a web application from a different physical location. In this case, you are not required to put the web application in its exploded war structure to the <strong>webapps </strong>directory. Most of the beginners, tend to develop their web applications directly in the webapps directory itself. This technique might prove the most simplest and the quickest but it is the<strong> most hazardous</strong>. This is because the moment you <strong>Undeploy</strong> the web application from Tomcat&#8217;s manager the web application gets<strong> erased</strong> off completely from the webapps directory.</p>
<p>I had tried the same, for the very first time since I had not much information, and it proved fatal. All my work had vanished in an instant. From that day onwards I stuck to using a technique of using <a href="http://techtracer.com/2007/03/31/development-and-deployment-structures-the-perfect-way-to-build-a-web-application/">development structures and deployment structures</a> and used with Ant. But I found this, too cumbersome, if I had to learn a framework or try out a small sample code. I was not willing to write an Ant build file each time I had to try a web application nor I wanted to develop the web application straightaway in the webapps directory which had earlier destroyed my work. IDE&#8217;s might be of great help but I don&#8217;t usually have them when needed. For example at a friend&#8217;s place.</p>
<p>Coming back to the topic which I have to discuss, I recently found a good workaround for the above problem. Although I believe it might be used quite commonly to deploy web applications I am writing this for people who are facing the same problem as mine. The solution lies in deploying the web application virtually.</p>
<p><strong>How to virtually deploy a web application in Tomcat?</strong></p>
<p>When you virtually deploy a web application you are just saying to Tomcat that you have developed a web application which is lying in some other location and that the server should run it from that location itself. This is done by using a configuring element called <strong>Context</strong>. In Tomcat lingo Context is nothing but the web application itself.</p>
<p>So here is the technique of virtual deployment done in Tomcat. I am using <strong>Tomcat 6</strong> for this example.</p>
<ul>
<li>Let&#8217;s assume that Tomcat is configured at the location <strong>C:/Tomcat6</strong></li>
<li>Place the Web application at some other location. For example <strong>D:/workspace/WebApp</strong></li>
<li>Start Tomcat. This is to test the hot deployment of our Context</li>
<li>Now go to the path C:/Tomcat6/<strong>conf/</strong></li>
<li>Check if you have the directory <strong>Catalina</strong> and a subdirectory <strong>localhost</strong> within it</li>
<li>If you don&#8217;t have them then you must make the directories <strong>Catalina/localhost</strong> within C:/Tomcat6/conf/</li>
<li>Make a Context file and name it with any name, <strong>myapp.xml</strong> and place it within localhost</li>
<li>You have to put a single element within the <strong>myapp.xml</strong> as follows<br />
<blockquote><p>&lt;Context<br />
docBase=&#8221;D:/workspace/WebApp&#8221;<br />
reloadable=&#8221;true&#8221;/&gt;</p></blockquote>
</li>
<li>The &#8220;<strong>reloadable</strong>&#8221; attribute is optional. The &#8220;<strong>docBase</strong>&#8221; attribute is required. It is used to specify the physical location of the web app.</li>
<li>That&#8217;s it. Now you can do any kind of tests with your web application and happily see the changes with just a browser refresh.</li>
<li>Try undeploying your web app now. The moment you undeploy, myapp.xml gets <strong>deleted</strong> from Catalina/localhost but your application will be intact. Isn&#8217;t that wonderful?</li>
<li>For redeploying you would just have to make myapp.xml once again.</li>
</ul>
<p>If you want to learn more about configuring Contexts and look at its different attributes then go through the <a href="http://tomcat.apache.org/tomcat-6.0-doc/config/context.html" target="_blank">tomcat reference</a>. But before that, you would want to know what are the advantages of this technique.</p>
<p><strong>Advantages of Virtual Deployment</strong></p>
<p>When a context is configured, Tomcat runs it from the location directly where the web application is placed and not by making a copy in its webapps directory. In this case if you try to Undeploy the web application, Tomcat simply removes the context file from its directory and does not touch the physical web application. This is most convenient and easy way to deploy a web application to Tomcat without the fear of losing your work.</p>
<p>The <strong>second </strong>advantage of virtual deployment is that you don&#8217;t have to change anything in the <strong>server.xml</strong>. Whenever any change is made in server.xml the server has to be restarted for the changes to be applied. In case of using contexts the server <strong>automatically</strong> deploys your application when it finds any context newly configured with it.</p>
<p>The <strong>third</strong> advantage is that contexts can be even used to make your web applications <strong>classes</strong> hot deployable too. It is done as above using the  &#8220;<strong>reloadable</strong>&#8221; attribute. Tomcat picks up any changes done even to the classes if &#8220;reloadable&#8221; is set to &#8220;<strong>true</strong>&#8220;. This can be very helpful and a time savior if you don&#8217;t want to waste time in restarting Tomcat again and again. It is however <strong>heavy </strong>on resources but might be useful in simple tests.</p>
<p>The <strong>fourth</strong> advantage is that you can dynamically change the<strong> name</strong> of your application itself. For example change the name of &#8220;myapp.xml&#8221; to &#8220;BankApp.xml&#8221;. Go to Tomcat Manager URL and refresh it. You will see the application name as &#8220;BankApp&#8221; which earlier was &#8220;myapp&#8221;. It doesn&#8217;t matter what the folder name is where the actual application lies. In our case it was &#8220;WebApp&#8221;.</p>
<p>The <strong>fifth</strong> advantage is something I found it to be <strong>the best</strong> of all. Your application would run even if it actually present on a <strong>remote machine</strong>. What you need to do is to just share the application from one machine, set the <strong>docBase</strong> path as the <strong>network URI</strong> and then access it. It would run like a locally hosted application.</p>
<p>The last but not the least advantage is to test a sample code on <strong>multiple </strong>tomcat&#8217;s. Let&#8217;s assume you want to test a feature of servlets to find whether it is backward compatible or not. So you can have a new Tomcat and an old Tomcat running on different ports. Put the context in both Tomcat&#8217;s and simultaneously test it out. You would have to refer to the Tomcat documentation for configuring Context in the older versions.</p>
<p>Now that you know how the technique of virtual deployment try it out on different servers like <strong>Glassfish</strong> or <strong>JBoss</strong> and let me know how you went about it. Cheers!</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2007/03/31/development-and-deployment-structures-the-perfect-way-to-build-a-web-application/" rel="bookmark" title="Permanent Link: Development and Deployment Structures &#8211; the perfect way to build a web application">Development and Deployment Structures &#8211; the perfect way to build a web application</a></li><li><a href="http://techtracer.com/2007/04/16/the-great-ant-tutorial-a-great-jump-start/" rel="bookmark" title="Permanent Link: The Great Ant Tutorial &#8211; a great jump start">The Great Ant Tutorial &#8211; a great jump start</a></li><li><a href="http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/" rel="bookmark" title="Permanent Link: Setting Up SSL on Tomcat In 3 Easy Steps">Setting Up SSL on Tomcat In 3 Easy Steps</a></li><li><a href="http://techtracer.com/2007/04/07/annotations-in-pojo-a-boon-or-a-curse/" rel="bookmark" title="Permanent Link: Annotations in POJO &#8211; a boon or a curse?">Annotations in POJO &#8211; a boon or a curse?</a></li><li><a href="http://techtracer.com/2007/09/03/and-i-thought-i-knew-how-java-worked/" rel="bookmark" title="Permanent Link: And I thought I Knew How Java Worked!">And I thought I Knew How Java Worked!</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Implementing Websites For Internationalization</title>
		<link>http://techtracer.com/2008/03/02/implementing-websites-for-internationalization/</link>
		<comments>http://techtracer.com/2008/03/02/implementing-websites-for-internationalization/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 16:05:52 +0000</pubDate>
		<dc:creator>ninadgawad</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/03/02/implementing-websites-for-internationalization/</guid>
		<description><![CDATA[Most business in today’s open market are demanding their websites &#38; web application to have multilingual support. This is in order to attract non-English speaking audiences to increase their customer base and make people comfortable using the application in their native language. But for this, it would require an existing business application to be customized [...]]]></description>
			<content:encoded><![CDATA[<p>Most business in today’s open market are demanding their websites &amp; web application to have multilingual support. This is in order to attract non-English speaking audiences to increase their customer base and make people comfortable using the application in their native language. But for this, it would require an existing business application to be customized to support native locale. The process of producing an application that can be localized for a particular country without any changes to the program code is called <strong>Internationalization</strong>.</p>
<p style="text-align: center"><img src="http://techtracer.com/wp-content/uploads/2008/03/internationalization.gif" alt="Internationalization" /></p>
<p>Following are the list of things one needs to take care while making an application to implement Internationalization.</p>
<p><strong>1. Producing Content in Unicode </strong></p>
<p>You need to make sure that all files which contain the multilingual  content are in <strong>Unicode format</strong>. By default most text editors will store your file in <strong>ASCII</strong> which does not support other language characters. So after saving any content in ASCII format and loading it, your browser might not be able to display correct text in native language. Here you need to convert the file from ASCII to UTF format.</p>
<p>For example, the steps required for doing this if you are using Notepad are,</p>
<ul>
<li>Open your JavaScript or properties, etc. file in notepad</li>
<li>Go to &gt; File &gt; Save As &gt; Encoding</li>
<li>Change Encoding from ASCII to UTF-8</li>
</ul>
<p><strong>2. Files needed to be converted to UTF</strong></p>
<p><u><em><strong> .properties</strong></em></u></p>
<p>All your properties file should have a suffix based on the language in which the content is stored in this file. For example,</p>
<ul>
<li>For English, <strong>content_en.properties</strong> for French <strong>content_fr.properties </strong>and so on.</li>
<li>Most java frameworks like Struts, Spring have inbuilt support to detect JVM locale and select the corresponding properties file based on the extension of the file &amp; JVM/Browser setting. You don&#8217;t need to add any code to detect the setting and set the properties file</li>
</ul>
<p><u><em><strong>.java</strong></em></u></p>
<p>Make sure that your JVM has set the parameter <strong>-Dfile.encoding=UTF-8</strong></p>
<p><u><em><strong>.js</strong></em></u></p>
<p>Set charset attribute of the SCRIPT tag to &#8220;UTF-8&#8243;. For example,</p>
<blockquote><p>&lt;script type=&#8221;text/javascript&#8221; src=&#8221;./urscript.js&#8221; <strong>charset=&#8221;UTF-8&#8243;</strong>&gt;&lt;/script&gt;</p></blockquote>
<p><u><em><strong>.xml</strong></em></u></p>
<p>Use the steps as in the first example to make sure the content within the XML files in is UTF-8 format.</p>
<p><u><em><strong>.html/.htm</strong></em></u></p>
<p>Add this line to head of all html pages.</p>
<blockquote><p>&lt;meta name=&#8221;http-equiv&#8221; content=&#8221;Content-type: text/html; <strong>charset=UTF-8</strong>&#8220;/&gt;</p></blockquote>
<p><u><em><strong>.jsp</strong></em></u></p>
<p>Set Content-type explicitly through your server side scripts. To do this, add this line to all your jsp pages,</p>
<blockquote><p>&lt;%@page contentType=&#8221;text/html; <strong>charset=UTF-8</strong>&#8221; pageEncoding=&#8221;UTF-8&#8243;%&gt;</p></blockquote>
<blockquote></blockquote>
<p><strong>3. Configuring the Web Server</strong></p>
<p>Your Web Server has to be configured to set the Content-type of headers to UTF-8 since by default the web server will replace the Content-type-header to ISO-8859 encoding. For example:</p>
<ul>
<li>In Apache Web Server, edit <strong>httpd.conf</strong> to set <strong>AddDefaultCharset=Off</strong>.</li>
<li>In Tomcat Server set connector settings within the <strong>server.xml</strong> file to <strong>URIEncoding=&#8221;UTF-8&#8243;</strong></li>
</ul>
<p><strong>4. Handling Request &amp; Response Objects</strong></p>
<p>Make sure that before reading request parameters &amp; writing to response objects set character encoding type to UTF-8. This can be handled using <strong>filters</strong> where all the contents coming in and going out can be set to UTF-8 encoding. For example,</p>
<ul>
<li>request.setCharacterEncoding(&#8220;UTF-8&#8243;);</li>
<li>response.setContentType(&#8220;text/html&#8221;);</li>
<li>response.setCharacterEncoding(&#8220;UTF-8&#8243;);</li>
</ul>
<p><strong>5. Creating Database with Unicode encoding</strong></p>
<p>While using a database make sure that the database created has encoding set to UNICODE. Most of the database servers like Oracle, Postgress, MySQL and MSSQL have this support. In order to create databases with unicode encoding use the following query,</p>
<blockquote><p>CREATE DATABASE MyWebApps DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;</p></blockquote>
<p>Once all the above steps are implemented your web application will work smoothly for all UTF-8 supported languages. In some cases, you will have to take care of <a href="http://java.sun.com/docs/books/tutorial/i18n/format/numberFormat.html" target="_blank">NumberFormat</a>, <a href="http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html" target="_blank">DecimalFormat</a> and <a href="http://java.sun.com/docs/books/tutorial/i18n/format/dateFormatSymbols.html" target="_blank">DateFormat</a>. There are some <a href="http://java.sun.com/javase/technologies/core/basic/intl/faq.jsp" target="_blank">FAQ&#8217;s on internationalization provided by Sun</a> to get you started. But feel free to put in your doubts related to internationalization via comments. I will be glad to help you out.</p>
<p><em>(<strong>Ninad Gawad</strong> is a Java EE Developer who blogs at <a href="http://ninadgawad.wordpress.com/" target="_blank">Technology Discussion</a>)</em></p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2007/12/26/techtracer-20-is-coming/" rel="bookmark" title="Permanent Link: Techtracer 2.0 is Coming">Techtracer 2.0 is Coming</a></li><li><a href="http://techtracer.com/2008/02/16/power-of-xray-for-web-designers/" rel="bookmark" title="Permanent Link: Power of XRAY for Web Designers">Power of XRAY for Web Designers</a></li><li><a href="http://techtracer.com/2007/11/05/feast-your-eyes-with-firefox-piclens/" rel="bookmark" title="Permanent Link: Feast Your Eyes With Firefox Piclens">Feast Your Eyes With Firefox Piclens</a></li><li><a href="http://techtracer.com/2007/06/03/the-struts-framework-why-choose-it/" rel="bookmark" title="Permanent Link: The Struts Framework &#8211; Why choose it?">The Struts Framework &#8211; Why choose it?</a></li><li><a href="http://techtracer.com/2007/07/30/plagiarism-black-listing-of-sites-is-a-must/" rel="bookmark" title="Permanent Link: Plagiarism &#8211; Black Listing of Sites is a Must">Plagiarism &#8211; Black Listing of Sites is a Must</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/03/02/implementing-websites-for-internationalization/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The Power of JavaScript Favelets</title>
		<link>http://techtracer.com/2008/01/27/the-power-of-javascript-favelets/</link>
		<comments>http://techtracer.com/2008/01/27/the-power-of-javascript-favelets/#comments</comments>
		<pubDate>Sun, 27 Jan 2008 14:25:52 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/01/27/the-power-of-javascript-favelets/</guid>
		<description><![CDATA[Favelets are bookmarks which contain JavaScript code. The code is used in many forms either for fun purposes or for reducing routine tasks. In present times, you won&#8217;t require favelets much since browser&#8217;s have got upgraded to include plugins or come with inbuilt features. But still, if you are stuck with a browser which does [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Favelets</strong> are bookmarks which contain <strong>JavaScript</strong> code. The code is used in many forms either for fun purposes or for reducing routine tasks. In present times, you won&#8217;t require favelets much since browser&#8217;s have got upgraded to include plugins or come with inbuilt features. But still, if you are stuck with a browser which does not have such features or plugin facilities then favelets can be your saviour.</p>
<p style="text-align: center"><img src="http://techtracer.com/wp-content/uploads/2008/01/favelet.gif" alt="Favelet" /></p>
<p>A couple of days ago I was in such a situation. I am addicted to <strong>Firefox</strong> and already have a lot of plugins which increase my <strong>productivity</strong>. But in those couple of days, I was left with the dreadful <strong>Internet Explorer 6.0</strong>. Life became more difficult for me when I found myself opening up the Google homepage every time I wanted to search something. I did not have the rights to download the Google toolbar. But since I knew about Favelets I quickly made some and later found that even getting stuck with IE 6.0 did not matter any more.</p>
<p><strong>How to make a favelet?</strong></p>
<p>Suppose you are in a similar situation as mine and suppose you tend to search more in Google than do any other work. Without <strong>Google toolbar</strong> you would be just helpless. So I would explain here how to make a simple Google Search Favelet and a word-meaning finder.</p>
<p>Making a Favelet is not a difficult task. For a simple example, copy paste this line directly in your browser&#8217;s address bar.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello World&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>When you hit enter it would show you the prompt with the message. You can do this in any browser.</p>
<p>Now that the idea is clear lets start with our Google Search favelet. Do the below steps:</p>
<ul>
<li>Create a new bookmark in your browser and name it &#8220;Google Search&#8221;</li>
<li>Put the below code in your bookmark location (the place where you put in the URL):</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">var</span> keyword <span style="color: #339933;">=</span> <span style="color: #000066;">prompt</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Enter Keyword'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>if<span style="color: #009900;">&#40;</span>keyword<span style="color: #339933;">!=</span><span style="color: #3366CC;">''</span><span style="color: #339933;">&amp;</span>keyword<span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>window.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://www.google.com/search?hl=en&amp;q='</span> <span style="color: #339933;">+</span> keyword <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;btnG=Google+Search&amp;meta='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>void <span style="color: #CC0000;">0</span></pre></div></div>

<ul>
<li>Remember to make the bookmark toolbar visible from your browsers menu for easier access.</li>
<li>Try it out, When you click it , a prompt will appear for keyword entry and on entry it will open a window to show you the results.</li>
<li>If you couldn&#8217;t make it, click <a href="javascript:var keyword = prompt('Enter Keyword','');if(keyword!=''&#038;keyword!=null)window.open('http://www.google.com/search?hl=en&#038;q=' + keyword + '&#038;btnG=Google+Search&#038;meta=');void 0" target="_blank">this link</a> or drag and drop the link on your bookmark toolbar.</li>
</ul>
<p><strong>Meaning Finder</strong></p>
<p>Suppose you are in a habit to find out the meanings of difficult words when you are surfing the web. You would find it distracting to open Google on another window and search the meaning of the word by copy pasting it. Having a favelet which can just catch the highlighted word on the page and then open up Google and automatically do a search on the word would be something you would crave for. Let&#8217;s try to extend the above created favelet to make this happen. The two additional things which are required in this case are:</p>
<ul>
<li>Using the <a href="http://techtracer.com/2008/01/06/10-most-amazing-google-search-tricks/">Google Trick</a> <strong>define:keyword</strong></li>
<li>JavaScript function <strong>document.getSelection();</strong></li>
<li>Create a new Favelet &#8220;Define&#8221; and put in the below code:</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">var</span> keyword <span style="color: #339933;">=</span> document.<span style="color: #660066;">getSelection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>if<span style="color: #009900;">&#40;</span>keyword<span style="color: #339933;">!=</span><span style="color: #3366CC;">''</span><span style="color: #339933;">&amp;</span>keyword<span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>window.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://www.google.com/search?hl=en&amp;q=define%3A'</span> <span style="color: #339933;">+</span> keyword <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;btnG=Google+Search'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>void <span style="color: #CC0000;">0</span></pre></div></div>

<ul>
<li>Drag n drop <a href="javascript:var keyword = document.getSelection();if(keyword!=''&#038;keyword!=null)window.open('http://www.google.com/search?hl=en&#038;q=define%3A' + keyword + '&#038;btnG=Google+Search');void 0" target="_blank">the link</a> to try the favelet. Select some word for which you want the meaning and then click the favelet on your bookmark toolbar. </li>
</ul>
<p><strong>Points to Ponder</strong></p>
<p>If you are a JavaScript veteran, you can try out many interesting and complex favelets which can reduce many of your tasks. But you have to remember that since JavaScript behaves differently in different browsers, you would have to make the necessary changes in your Favelets in order to make them generic to all browsers.</p>
<p>Many of the social networking site often have a <strong>bookmarklet </strong>(same as favelets) which help you to bookmark a page into their network. Some examples are:</p>
<ul>
<li><a href="http://reddit.com/bookmarklets" title="http://reddit.com/bookmarklets" target="_blank">Reditt Bookmarklets</a></li>
<li><a href="http://del.icio.us/help/buttons" title="http://del.icio.us/help/buttons" target="_blank">Del.icio.us Help Buttons</a></li>
</ul>
<p>Some other useful favelets which I have found from the web:</p>
<ul>
<li><a href="http://validator.w3.org/favelets.html" title="http://validator.w3.org/favelets.html" target="_blank">W3C Validator Favelets</a></li>
<li><a href="http://www.pixy.cz/pixylophone/favelets/" title="http://www.pixy.cz/pixylophone/favelets/" target="_blank">Web Design Test Favelets</a></li>
<li><a href="http://vedbaba.spaces.live.com/Blog/cns!C74A27CA0FF67D0D!146.entry" title="http://vedbaba.spaces.live.com/Blog/cns!C74A27CA0FF67D0D!146.entry" target="_blank">Favelets for Fun</a></li>
</ul>
<p>I hope you found this article interesting and if you create any interesting favelet don&#8217;t forget to mention it here.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2008/02/16/power-of-xray-for-web-designers/" rel="bookmark" title="Permanent Link: Power of XRAY for Web Designers">Power of XRAY for Web Designers</a></li><li><a href="http://techtracer.com/2008/01/09/impressive-google-chart-generator-scripts/" rel="bookmark" title="Permanent Link: Impressive Google Chart Generator Scripts">Impressive Google Chart Generator Scripts</a></li><li><a href="http://techtracer.com/google-search/" rel="bookmark" title="Permanent Link: Search Results">Search Results</a></li><li><a href="http://techtracer.com/2007/03/27/ajax-frameworks-server-side-versus-client-side/" rel="bookmark" title="Permanent Link: Ajax Frameworks &#8211; Server side versus Client side">Ajax Frameworks &#8211; Server side versus Client side</a></li><li><a href="http://techtracer.com/2007/04/29/ajax-exposed-myth-and-reality/" rel="bookmark" title="Permanent Link: Ajax Exposed &#8211; Myth and Reality">Ajax Exposed &#8211; Myth and Reality</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/01/27/the-power-of-javascript-favelets/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How To Install Windows Live Writer</title>
		<link>http://techtracer.com/2008/01/13/how-to-install-windows-live-writer/</link>
		<comments>http://techtracer.com/2008/01/13/how-to-install-windows-live-writer/#comments</comments>
		<pubDate>Sun, 13 Jan 2008 05:24:09 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://techtracer.com/2008/01/13/how-to-install-windows-live-writer/</guid>
		<description><![CDATA[I am writing this article for the first time using Windows Live Writer. The interface of the tool is amazing and the installation has given me a new kind of energy to get more productive. I am starting with my blogging stint from Live Writer by writing a post on how to install Live Writer [...]]]></description>
			<content:encoded><![CDATA[<p>I am writing this article for the first time using <strong>Windows Live Writer</strong>. The interface of the tool is amazing and the installation has given me a new kind of energy to get more productive. I am starting with my blogging stint from Live Writer by writing a post on how to install Live Writer on your system.</p>
<p><strong>What is Windows Live Writer?</strong></p>
<p>Live Writer is a <strong>power blogging tool</strong> which helps in offline blogging. If you are a regular blogger then you might have used the <a href="https://addons.mozilla.org/en-US/firefox/addon/1730" target="_blank">ScribeFire Firefox addon</a>. But Windows Live Writer is not just an addon its a full fledged blogging platform with many blog rich features. The features are fully in synch with the Wordpress platform.</p>
<p>The best part of blogging in Live Writer is that, it has a facility of providing you the actual template from the blog layout while you blog. This makes you feel as if you are directly writing on your blog layout than in the standard <strong>Wordpress TinyMCE editor.</strong></p>
<p style="text-align: center"><img src="http://techtracer.com/wp-content/uploads/2008/01/windows_live_writer.gif" alt="Windows Live Writer" /></p>
<p><strong>Installation Steps</strong></p>
<ul>
<li>For installation of Live Writer make sure you have the following <a href="http://get.live.com/writer/sysreq" target="_blank">system requirements</a>. More important that it requires a <strong>.Net Framework</strong>.</li>
<li>Download the Live Tools Installer. This installer is not the Live Writer Installer. Instead it is general purpose installer and lets you select more products to install if needed.</li>
<li>Start the installation from <strong>WLinstaller.exe</strong></li>
<li><strong>Accept</strong> the agreement policy.</li>
<li>Uncheck all the check boxes. They are optional utilities.</li>
<li>The installer then downloads the Live Writer installation. Please be patient as it takes quite a lot of time if you have slow connection.</li>
<li>You don&#8217;t have to do check anything. The installation would immediately after the download is complete.</li>
<li>Follow the further steps which include putting the login credentials, blog URL.</li>
<li><strong>Allow </strong>the installation to detect the blog layout settings and post a temporary post to verify. It won&#8217;t affect your blog since no test post is published.</li>
<li>Start the Writer and blast away with your writing. Enjoy!</li>
</ul>
<p>Live Writer makes you feel as if you are working in the Wordpress environment itself. Blogging with it will surely enthral you. Try it out and you will see the difference for yourself.</p>
<p>Also do check out the gallery of <a href="http://wlwplugins.com/" target="_blank">Live Writer Plugins</a> and also the <a href="http://www.codeplex.com/WLWPlugins" target="_blank">CodePlex development zone</a> to make your blogging experience even more enjoyable.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2008/02/18/go-live-with-yahoo-live/" rel="bookmark" title="Permanent Link: Go Live with Yahoo! Live">Go Live with Yahoo! Live</a></li><li><a href="http://techtracer.com/2007/03/12/xp-installation-the-34-minute-hiccup/" rel="bookmark" title="Permanent Link: XP Installation &#8211; The 34 minute hiccup">XP Installation &#8211; The 34 minute hiccup</a></li><li><a href="http://techtracer.com/2007/03/25/techtracer-goes-live-from-today/" rel="bookmark" title="Permanent Link: TechTracer goes Live from today!">TechTracer goes Live from today!</a></li><li><a href="http://techtracer.com/2007/09/06/google-reader-search-goes-live/" rel="bookmark" title="Permanent Link: Google Reader Search Goes Live!">Google Reader Search Goes Live!</a></li><li><a href="http://techtracer.com/2007/11/05/feast-your-eyes-with-firefox-piclens/" rel="bookmark" title="Permanent Link: Feast Your Eyes With Firefox Piclens">Feast Your Eyes With Firefox Piclens</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2008/01/13/how-to-install-windows-live-writer/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The Power Of Google Chart API</title>
		<link>http://techtracer.com/2007/12/17/the-power-of-google-chart-api/</link>
		<comments>http://techtracer.com/2007/12/17/the-power-of-google-chart-api/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 17:14:13 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://techtracer.com/2007/12/17/the-power-of-google-graph-api/</guid>
		<description><![CDATA[What do you do when you want to show the reports of some particular analysis in your website? Some of the answers to this question would  probably be:

Use a server side framework to code in the chart
Use a database to collect the report data and  then code for the  framework integration
Insert chart [...]]]></description>
			<content:encoded><![CDATA[<p>What do you do when you want to show the reports of some particular analysis in your website? Some of the answers to this question would  probably be:</p>
<ul>
<li>Use a server side framework to code in the chart</li>
<li>Use a database to collect the report data and  then code for the  framework integration</li>
<li>Insert chart image after generating a chart in a software</li>
<li>Use some heavy JavaScript libraries which add to the loading time of the page</li>
</ul>
<p style="text-align: center"><img src="http://techtracer.com/wp-content/uploads/2007/12/google_chart_api.gif" alt="Google Graph API" /></p>
<p>But if you had only a few outcomes and wished to show a simple chart in your web page to the readers of your website or blog then probably you would be fixed in a situation like this. The main reasons being:</p>
<ul>
<li>Use of an HTML only website or blog which does not allow server side scripting</li>
<li>Lack of knowledge of using a chart framework even if you had server side scripting</li>
<li>Burden of the process in creating a simple chart.</li>
<li>Wastage of your precious time.</li>
</ul>
<p>But with the power of <a href="http://code.google.com/apis/chart/" target="_blank">Google Chart API</a> in your hands all you need to know is to <strong>insert an image in your web page</strong> and watch your chart come to life.  But if you are thinking that what could be the use of using a static image for showing a chart then you are wrong. The <strong>Google Chart</strong><strong> API</strong> is so simple yet so powerful that can give you some amazing features:</p>
<ul>
<li>Create charts simply by using <strong>URL</strong> with some <strong>parameters</strong></li>
<li>Inserting the chart is as simple as you would be inserting an image</li>
<li>The chart is created on the fly <strong>dynamically</strong></li>
<li>No need of <strong>server side </strong>coding</li>
<li>No need of <strong>JavaScript</strong> to code or view your chart</li>
<li>Any resolution of the chart with only a change in URL parameters</li>
<li>Manipulating the parameters of the URL would change the chart</li>
<li>A variety of styles to choose as per your tastes.</li>
</ul>
<p>Doesn&#8217;t this sound pretty much magical. If the above features excite you then probably the process of showing you how to create a simple chart right in this article itself will be enchanting. So lets proceed ahead.</p>
<p><strong>Creating a chart</strong><strong> with the Google Chart API<br />
</strong></p>
<p>Lets take a simple case study for our chart. Suppose you are writing an article on the trends in the usage of browser&#8217;s and instead of showing the data in<strong> tabular format </strong>you could show present the data with some visual cues. <strong>Charts</strong> are the perfect way to do it. You must have already been at a site which shows amazing chart representations for some reports. Google however does not have anything sleek yet in their chart varieties but hey they surely have simple and sweet ones.</p>
<p>I am taking the <strong>browser usage trends</strong> of my blog readers. According to the statistics the trends show that 60% of my blog readers use Firefox, 25% use MSIE, 10% Safari and 5% the rest.</p>
<p>So if I have to represent this data in the form of a chart then first of all I simply need to choose the chart type according to my liking from <a href="http://code.google.com/apis/chart/#chart_type" target="_blank">the various Google Chart Types</a>.  From all, I will choose the <strong>3D pie chart</strong>. So for drawing the chart we will have to build a URL with in this fashion:</p>
<blockquote><p> http://chart.apis.google.com/chart?<strong>&lt;parameter 1&gt;</strong>&amp;<strong>&lt;parameter 2&gt;</strong>&amp;<strong>&lt;parameter n&gt; </strong></p></blockquote>
<p>Select the particular chart name, In my case it is <strong>p3</strong>. So the first parameter of the URL will be:</p>
<blockquote><p>cht=<strong>p3</strong></p></blockquote>
<p>Now for the data, I will use the <a href="http://code.google.com/apis/chart/#simple" target="_blank">Simple Encoding technique</a> which is indeed, simple. According to the technique my data representation would be done as follows:</p>
<blockquote><p> chd=s:<strong>8ZKF </strong><em>(Four characters for the value indicate the four divisons in the chart</em><em>)</em></p></blockquote>
<p>We have to specify the resolution for the chart. According to my blog layout I would choose a height of 200px and the width of 400px. So the parameter would be,</p>
<blockquote><p>chs=<strong>400</strong>x<strong>200</strong></p></blockquote>
<p>Titles have to be given to the data representation. So, for each of the four characters above in the data we would have to give its equivalent number of pipe delimited titles as follows,</p>
<blockquote><p> chl=<strong>FireFox</strong>|<strong>MSIE</strong>|<strong>Safari</strong>|<strong>Others</strong></p></blockquote>
<p>Finally we come to the coloring part. You can specify any color you require. The API automatically shades the other chart divisions if the appropriate number of colors are not provided. I want my chart to have shades of 2 colors, blue and green so I would give the last parameter as follows:</p>
<blockquote><p> chco=<strong>1B75DF</strong>,<strong>92BF23     </strong><em>(Colors have to be in hexadecimal format)</em></p></blockquote>
<p>Our chart is complete! Don&#8217;t believe it?. You just have to combine the URL with the parameters and put in your browser&#8217;s address bar or <a href="http://chart.apis.google.com/chart?cht=p3&amp;chd=s:8ZKF&amp;chs=400x200&amp;chl=FireFox|MSIE|Safari|Others&amp;chco=1B75DF,92BF23" target="_blank">click here</a>. Google will do the rest of the stuff for you.</p>
<blockquote><p> http://chart.apis.google.com/chart?<strong>cht=p3</strong>&amp;<strong>chd=s:8ZKF</strong>&amp;<strong>chs=400&#215;200</strong><br />
&amp;<strong>chl=FireFox|MSIE|Safari|Others</strong>&amp;<strong>chco=1B75DF,92BF23</strong></p></blockquote>
<p><strong>Inserting the chart</strong><strong> into your web site or blog</strong></p>
<p>It is very simple to insert the chart into your blog or website. Since the resulting output of the URL is an image (<strong>.png</strong>) you just have to copy the entire URL and encapsulate it into an image tag as follows:</p>
<blockquote><p>&lt;img src=&#8221;<strong>http://chart.apis.google.com/chart?cht=p3&amp;chd=s:8ZKF&amp;chs=400&#215;200<br />
&amp;chl=FireFox|MSIE|Safari|Others&amp;chco=1B75DF,92BF23</strong>&#8221; title=&#8221;Browser Stats&#8221; alt=&#8221;Browser Stats&#8221;/&gt;</p></blockquote>
<p style="text-align: center"><img src="http://chart.apis.google.com/chart?cht=p3&amp;chd=s:8ZKF&amp;chs=400x200&amp;chl=FireFox|MSIE|Safari|Others&amp;chco=1B75DF,92BF23" title="Browser Stats" alt="Browser Stats" /></p>
<p>You are seeing the live representation of the chart above. Isn&#8217;t this concept just fantastic? Now go ahead and start creating some visual presentations in your article and let me know about your creations. <img src='http://techtracer.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2008/01/09/impressive-google-chart-generator-scripts/" rel="bookmark" title="Permanent Link: Impressive Google Chart Generator Scripts">Impressive Google Chart Generator Scripts</a></li><li><a href="http://techtracer.com/google-search/" rel="bookmark" title="Permanent Link: Search Results">Search Results</a></li><li><a href="http://techtracer.com/2007/10/14/unleash-the-power-in-your-blog-with-google-custom-search/" rel="bookmark" title="Permanent Link: Unleash the Power in Your Blog with Google Custom Search">Unleash the Power in Your Blog with Google Custom Search</a></li><li><a href="http://techtracer.com/2008/01/06/10-most-amazing-google-search-tricks/" rel="bookmark" title="Permanent Link: 10 Most Amazing Google Search Tricks">10 Most Amazing Google Search Tricks</a></li><li><a href="http://techtracer.com/2008/03/10/5-most-exciting-search-tricks-with-google-operators/" rel="bookmark" title="Permanent Link: 5 Most Exciting Search Tricks with Google Operators">5 Most Exciting Search Tricks with Google Operators</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2007/12/17/the-power-of-google-chart-api/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Setting Up SSL on Tomcat In 3 Easy Steps</title>
		<link>http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/</link>
		<comments>http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/#comments</comments>
		<pubDate>Wed, 12 Sep 2007 17:15:40 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/</guid>
		<description><![CDATA[Setting up SSL on Tomcat is easy and you don&#8217;t have to do much for converting your web application to work with the Https protocol. But however, the problem you would find to set up SSL is the documentation available over the web. The documentation source is available on the Apache site but it starts [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up <strong>SSL</strong> on <strong>Tomcat</strong> is easy and you don&#8217;t have to do much for converting your web application to work with the <strong>Https</strong> protocol. But however, the problem you would find to set up SSL is the documentation available over the web. The documentation source is available on the <a href="http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html" target="_blank">Apache</a> site but it starts off good and ends with a lot of confusion. Especially I was confused on the <strong>OpenSSL</strong> part where it says to use OpenSSL.</p>
<p>It might be good in a production environment to use OpenSSL but if you just want to test out SSL with Tomcat alone then it is more than enough to just have your JDK and Tomcat setups. So I would make you walk through the same steps which I did while getting SSL up and running and building a secured web app within a matter of <strong>minutes</strong>.</p>
<p>The things which I have used to setup SSL consists of:</p>
<ul>
<li>JDK 1.6</li>
<li>Tomcat 6</li>
</ul>
<p>Even though I have used the latest version I don&#8217;t see any problems which you might face in carrying out the<strong> same </strong>set of steps for JDK 1.5 which I am about to explain. JDK comes shipped with a <strong>keytool </strong>executable which is required to generate a <strong>keystore</strong>. The keytool can be found in the earlier version of JDK too. The 3 steps which would make you to get started with setting up SSL are:</p>
<ol>
<li>Generating the Keystore file</li>
<li>Configuring Tomcat for using the Keystore file</li>
<li>Configuring your web application to work with SSL</li>
</ol>
<p>Let&#8217;s get this party started now.</p>
<p><strong>1. Generating the KeyStore file</strong></p>
<p>The keystore file is the one which would store the details of the <strong>certificates</strong> necessary to make the protocol secured. Certificates contain the information as to who is the source from which you are receiving the application data and to authenticate whether it is the intended party or not. To make this keystore you would have to use the <strong>keytool</strong>. So open command prompt in Windows or the shell in Linux and type:</p>
<blockquote><p>cd %JAVA_HOME%/bin on Windows</p>
<p>cd $JAVA_HOME/bin on Linux</p></blockquote>
<p>You would land up in the Java bin directory. Now time to run the keytool command. You have to provide some parameters to the command as follows :</p>
<blockquote><p>keytool -genkey -alias <strong>techtracer</strong> -keypass <strong>ttadmin</strong> -keystore <strong>techtracer.bin</strong> -storepass <strong>ttadmin</strong></p></blockquote>
<p>The highlighted words are the ones which you would have to change according to your requirements. But keep one thing in mind that both the <strong>keypass </strong>and <strong>storepass</strong> passwords should be the same. The <strong>.bin</strong> file is actually your keystore file. It would now start a questionnaire. So fill in the <strong>relevant </strong>details accordingly. Look below for a reference as to what to answer for the questions.</p>
<blockquote><p>What is your first and last name?<br />
[Unknown]:  <strong>nitin pai</strong><br />
What is the name of your organizational unit?<br />
[Unknown]:  <strong>home</strong><br />
What is the name of your organization?<br />
[Unknown]:  <strong>techtracer</strong><br />
What is the name of your City or Locality?<br />
[Unknown]:  <strong>mumbai</strong><br />
What is the name of your State or Province?<br />
[Unknown]:  <strong>maharashtra</strong><br />
What is the two-letter country code for this unit?<br />
[Unknown]:  <strong>IN</strong><br />
Is CN=nitin pai, OU=home, O=techtracer, L=mumbai, ST=maharashtra, C=IN correct?<br />
[no]: <strong>yes </strong></p></blockquote>
<p>The command would then conclude. It would make a .bin file with the name you had provided inside the bin directory itself. In my case it was <strong>techtracer.bin</strong> which was located in</p>
<blockquote><p>C:\Program Files\Java\jdk1.6.0_02\bin\</p></blockquote>
<p>Put the .bin file in the <strong>webapps</strong> directory of Tomcat. This is required to avoid the need to give an absolute path of the file in the next step.</p>
<p><strong>2.  Configuring Tomcat for using the Keystore file</strong></p>
<p>Here we would be making some changes to the server.xml file inside tomcat to tell it to use the keystore which was created in the earlier step for configuring SSL. Open the file <strong>server.xml</strong> which can be found as:</p>
<blockquote><p><em>&lt;CATALINA_HOME&gt;</em>/conf/server.xml</p></blockquote>
<p>Now you have to modify it. Find the <strong>Connector</strong> element which has <strong>port=&#8221;8443&#8243;</strong> and uncomment it if already not done. Add two lines. The highlighted lines are the newly added ones.</p>
<blockquote><p>    &lt;Connector port=&#8221;8443&#8243;<br />
maxThreads=&#8221;150&#8243; minSpareThreads=&#8221;25&#8243; maxSpareThreads=&#8221;75&#8243;<br />
enableLookups=&#8221;true&#8221; disableUploadTimeout=&#8221;true&#8221;<br />
acceptCount=&#8221;100&#8243; debug=&#8221;0&#8243; scheme=&#8221;https&#8221; secure=&#8221;true&#8221;<br />
clientAuth=&#8221;false&#8221; sslProtocol=&#8221;TLS&#8221;<br />
<strong> keystoreFile</strong>=&#8221;../webapps/techtracer.bin&#8221;<br />
<strong>keystorePass</strong>=&#8221;ttadmin&#8221; /&gt;</p></blockquote>
<p>You can notice that I have given the path to the keystoreFile property as <strong>relative </strong>to tomcat bin directory because the startup command will look for the .bin file. Now all you have to do is start your server and check the working of SSL by pointing your browser to the URL to:</p>
<blockquote><p><strong>https</strong>://localhost:<strong>8443</strong>/</p></blockquote>
<p>Now that you have your tomcat running in the SSL mode you are ready to deploy an application to test its working. You must note that<strong> still</strong> your tomcat can run in normal mode too at the same time i.e on port<strong> 8080</strong> with <strong>http</strong>. So it is but obvious that any application deployed to the server will be running on http and https at the <strong>same time</strong>. This is something that we don&#8217;t want. We want our application to run <strong>only</strong> in the secured mode.</p>
<p><strong> 3. Configuring your web application to work with SSL</strong></p>
<p>In order to do this for our test, take any application which has already been deployed <strong>successfully</strong> in Tomcat and first access it through http and https to see if it works fine. If yes, then open the <strong>web.xml</strong> of that application and just add this XML fragment <strong>before</strong> web-app ends i.e <strong>&lt;/web-app&gt;</strong></p>
<blockquote><p>&lt;security-constraint&gt;<br />
&lt;web-resource-collection&gt;<br />
&lt;web-resource-name&gt;securedapp&lt;/web-resource-name&gt;<br />
&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br />
&lt;/web-resource-collection&gt;<br />
&lt;user-data-constraint&gt;<br />
&lt;transport-guarantee&gt;<strong>CONFIDENTIAL</strong>&lt;/transport-guarantee&gt;<br />
&lt;/user-data-constraint&gt;<br />
&lt;/security-constraint&gt;</p></blockquote>
<p>Explanation of the fragment is beyond the scope of this tutorial but all you should notice is that the <strong>/* </strong>indicates that now, any resource in your application can be accessed only with <strong>https</strong> be it Servlets or JSP&#8217;s. The term <strong>CONFIDENTIAL </strong> is the term which tells the server to make the application work on SSL. If you want to turn the SSL mode for this application off then just turn don&#8217;t delete the fragment. Just put the value as <strong>NONE</strong> instead of <strong>CONFIDENTIAL</strong>. That&#8217;s it!</p>
<p><strong>Conclusion</strong></p>
<p>These were the 3 easy steps in which you can make Tomcat to work in the SSL mode and also it tells you how easily you can turn the SSL mode on and off. If you find any difficulty or are not clear on any of the above steps feel free to drop in your queries. If you like this tutorial it would be nice of you to drop in a comment of appreciation or feedback as to how this tutorial can be improved.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2008/04/26/the-technique-of-virtual-deployment-in-tomcat/" rel="bookmark" title="Permanent Link: The Technique of Virtual Deployment in Tomcat">The Technique of Virtual Deployment in Tomcat</a></li><li><a href="http://techtracer.com/2008/03/02/implementing-websites-for-internationalization/" rel="bookmark" title="Permanent Link: Implementing Websites For Internationalization">Implementing Websites For Internationalization</a></li><li><a href="http://techtracer.com/2008/06/09/3-easy-steps-to-install-mysql-on-windows-xp/" rel="bookmark" title="Permanent Link: 3 Easy Steps to Install MySQL on Windows XP">3 Easy Steps to Install MySQL on Windows XP</a></li><li><a href="http://techtracer.com/2007/04/16/the-great-ant-tutorial-a-great-jump-start/" rel="bookmark" title="Permanent Link: The Great Ant Tutorial &#8211; a great jump start">The Great Ant Tutorial &#8211; a great jump start</a></li><li><a href="http://techtracer.com/2007/08/26/eclipse-europa-has-ruined-my-day/" rel="bookmark" title="Permanent Link: Eclipse Europa Has Ruined My Day">Eclipse Europa Has Ruined My Day</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/feed/</wfw:commentRss>
		<slash:comments>173</slash:comments>
		</item>
		<item>
		<title>JAX-WS + JAXP Tutorial &#8211; Building A StockQuote Web Service Client</title>
		<link>http://techtracer.com/2007/08/15/jax-ws-jaxp-tutorial-building-a-stockquote-web-service-client/</link>
		<comments>http://techtracer.com/2007/08/15/jax-ws-jaxp-tutorial-building-a-stockquote-web-service-client/#comments</comments>
		<pubDate>Wed, 15 Aug 2007 17:24:02 +0000</pubDate>
		<dc:creator>nitinpai</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://techtracer.com/2007/08/15/jax-ws-jaxp-tutorial-building-a-stockquote-web-service-client/</guid>
		<description><![CDATA[In this tutorial you will learn how to make a standalone Web Service client using JAX-WS. JAX-WS and JAXP API together, provide an easy way to develop a web service client. This tutorial makes use of an existing online web service instead of creating one from scratch just for making a client. For this tutorial [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial you will learn how to make a standalone Web Service client using JAX-WS. JAX-WS and JAXP API together, provide an easy way to develop a web service client. This tutorial makes use of an existing online web service instead of creating one from scratch just for making a client. For this tutorial you would need the following:</p>
<ul>
<li><strong>JWSDP 2.0</strong> pack</li>
<li><strong>JDK 1.5</strong> or above</li>
<li>The required Web Service <strong>WSDL</strong></li>
<li><strong>Eclipse</strong> 3.1 or above</li>
</ul>
<p>The procedure for creating the client have been broken down into <strong>3 easy steps</strong> which are:</p>
<ol>
<li>Creating the Stubs from <strong>WSDL</strong></li>
<li>Building the Web Service Client using <strong>JAX-WS</strong></li>
<li>Parsing the Output using <strong>JAXP</strong></li>
</ol>
<p><u><strong>JAXWS &amp; JAXP</strong></u></p>
<p><strong>JAX-WS</strong> is an API for creating as well as invoking web services. It succeeds the JAX RPC API and makes it easier by reducing the XML configurations, through the use of annotations available in Java 5. However you don&#8217;t need annotations for this tutorial.</p>
<p><strong>JAXP</strong> is a <strong>wrapper</strong> API over the legacy XML parsing API&#8217;s such as <strong>DOM</strong> and<strong> SAX</strong> and leverages their usage through its generic interfaces. JAXP is typically used in a web service which is implemented with a <strong>Document Literal </strong>style. This is because such web services return an <strong>XML document</strong> and not a simple String Value. The XML Document then has to be parsed using the JAXP API.</p>
<p>So let us begin with the tutorial.</p>
<p><u><strong>1. Creating the Stubs from WSDL</strong></u></p>
<p>For this tutorial, I am going to use the<strong> Stock Quote Service</strong> available at <a href="http://www.webservicex.net/stockquote.asmx?op=GetQuote" target="_blank">webservicex.net</a>. The web service demo shows you an XML document being returned when you enter in a stock ticker in the text box provided. The client which you will create in JAX-WS will invoke the <strong>GetQuote</strong> service and receive the same document which we will then parse using JAXP.</p>
<p>In order to invoke the GetQuote service you first need to have the <strong>stubs</strong>. The stubs can be created easily using the <strong>import.bat</strong> utility provided in the JWSDP pack. The path where you can find this utility is &lt;JWSDP_HOME&gt;/<strong>jaxws/bin. </strong>For using this utility you must set the <strong>JAXWS_HOME </strong>environment variable which points to the JAX-WS directory. For example I have set mine as:</p>
<pre lang="">
C:\tomcat50-jwsdp\jaxws
</pre>
<p>Open the command prompt and go the path &lt;JWSDP_HOME&gt;/<strong>jaxws/bin. </strong>Use the <a href="http://www.webservicex.net/stockquote.asmx?WSDL" target="_blank">WSDL path</a> of the GetQuote Web Service and type in the following command,</p>
<pre lang="">
C:\tomcat50-jwsdp\jaxws\bin>wsimport -s . http://www.webservicex.net/stockquote.
asmx?WSDL
</pre>
<p>This command generates the stubs which are required for invoking the web service, in the current directory. The  <strong>-s switch</strong> is to generate source code of the stubs. We need to use these generated classes in the client.</p>
<p>Now open <strong>Eclipse</strong> and make a new <strong>Java Project</strong>. Name it whatever you like. Next, <strong>import</strong> all the above generated classes into the project. Remember all the classes have to be in the same package as they were generated i.e <strong>net.webservicex</strong></p>
<p><u><strong>2. Building the Web Service Client using JAX-WS</strong> </u></p>
<p>Create a package <strong>com.ws.client</strong> where we will place our client code. Make a Java Class called <strong>StockQuoteClient. </strong>You would now have to import a large set of JAR&#8217;s which would be required for running the client. The JAR&#8217;s which are needed are:</p>
<ul>
<li><em>jaxws-api.jar, jaxws-rt.jar, jsr181-api.jar</em> present in  <strong>jaxws/lib</strong></li>
<li><em>jaxb-api.jar, jaxb-impl.jar  </em>present in <strong>jaxb/lib</strong></li>
<li><em>saaj-api.jar, saaj-impl.jar </em>present in <strong>saaj/lib</strong></li>
<li><em>resolver.jar, activation.jar </em>present in <strong>jwsdp-shared/lib</strong></li>
<li><em>jsr173_api.jar, sjsxp.jar </em>present in <strong>sjsxp/lib</strong></li>
<li><em>jaxp-api.jar</em> present in <strong>jaxp/lib</strong></li>
</ul>
<p>That&#8217;s too much indeed! But trust me, you wouldn&#8217;t have your web service client running without these libraries. Now write the following code inside the main method of  <strong>StockQuoteClient</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"> StockQuote service = <span style="color: #000000; font-weight: bold;">new</span> StockQuote<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 StockQuoteSoap port = service.<span style="color: #006633;">getStockQuoteSoap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #003399; font-weight: bold;">String</span> quote = port.<span style="color: #006633;">getQuote</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INFY&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
 <span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>quote<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The code is simple. You first create a service instance of <strong>StockQuote</strong>. Then you get the <strong>port </strong>on which you want the function to be invoked. Here I have invoked the <strong>StockQuoteSoap </strong>port. </p>
<p>Once you get the port you are ready to invoke the service which is done by calling <strong>port.getQuote(&#8220;INFY&#8221;)</strong> where <strong>INFY</strong> is the stock ticker symbol for the company INFOSYS.</p>
<p>Now run this program as a <strong>Java Application </strong>in Eclipse. You would see a long running line of XML returned as a string which contains the details related to INFY stock.</p>
<p><u><strong>3. Parsing the Output using JAXP</strong></u></p>
<p>The returned XML output is undesirable since it cannot be read out easily. So now we have to use some API which would easily help us to get the required details in a nice and clean manner. This is where we would use <strong>JAXP</strong>. Now instead of printing out the output as it is, make a function <strong>parseQuote</strong> with which we will parse the XML returned.  For this, in the main method, change</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>quote<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> items = <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Last&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Date&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Time&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
items.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Change&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
parseQuote<span style="color: #009900;">&#40;</span>quote, items<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You may be wondering what the <strong>List</strong> of items is used for. Well, instead of making the method for displaying all the information contained within the XML fragment, we would create the method more nicer, which will only display the contents of the tags actually needed. Hence we pass the tag names in a <em>List</em> as a second argument.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #006600; font-weight: bold;">void</span> parseQuote<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> quote, List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> items<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">Exception</span><span style="color: #009900;">&#123;</span>	
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Its been made static so as to access it directly. You can either throw an Exception from the method or implement a try-catch inside the method. Use the below code inside the <strong>parseQuote</strong> method.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">&nbsp;
<span style="color: #003399; font-weight: bold;">DocumentBuilderFactory</span> factory = <span style="color: #003399; font-weight: bold;">DocumentBuilderFactory</span>.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
factory.<span style="color: #006633;">setValidating</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399; font-weight: bold;">DocumentBuilder</span> builder = factory.<span style="color: #006633;">newDocumentBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the code <em>DocumentBuilderFactory </em>and <em>DocumentBuilder</em> instances are used to get hold the document which we want to parse. The document is nothing but the XML output stored in the <strong>quote</strong> object. But in order to read the string, we would require to use it as</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #003399; font-weight: bold;">Document</span> document = builder.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">InputSource</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">StringReader</span><span style="color: #009900;">&#40;</span>quote<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>and not directly. If used directly you would get a <strong>java.net.MalformedURLException</strong> exception. After getting a hold of the document we use a <a href="http://techtracer.com/2007/05/16/looping-through-collections-is-fun-in-java-6/">for in loop</a> to check which items are required to be displayed.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000;  font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">String</span> content:items<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003399; font-weight: bold;">NodeList</span> list = document.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span>content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399; font-weight: bold;">Node</span> item = list.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>content + <span style="color: #0000ff;">&quot; : &quot;</span> + item.<span style="color: #006633;">getTextContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The function to look out for is getElementsByTagName() which itself finds the tag names and gives the content within them. Remember for using this function, the tag name provided, <strong>must</strong> be any leaf element or else you would get a <strong>javax.xml.stream.XMLStreamException </strong>error.</p>
<p><u><strong>Final Words</strong></u></p>
<p>This is a very basic way in which you can build a web service client using JAX-WS and JAXP. The tutorial is aimed for getting started with these two API&#8217;s together. Further down from here, you can begin exploring in depth the wonderful features that these API&#8217;s provide.</p>
<p>You can copy paste the entire code <a href='http://techtracer.com/wp-content/uploads/2007/08/stockquoteclientjava.txt' title='StockQuoteClient.java'>provided here</a> and use directly in your application.</p>
<h2>Related posts:</h2><ul><li><a href="http://techtracer.com/2007/08/19/working-with-jax-ws-in-jdk-16/" rel="bookmark" title="Permanent Link: Working With JAX-WS in JDK 1.6">Working With JAX-WS in JDK 1.6</a></li><li><a href="http://techtracer.com/2007/03/15/scdjws-preparation-a-kick-start-guide/" rel="bookmark" title="Permanent Link: SCDJWS preparation &#8211; a kick start guide">SCDJWS preparation &#8211; a kick start guide</a></li><li><a href="http://techtracer.com/2007/03/27/ajax-frameworks-server-side-versus-client-side/" rel="bookmark" title="Permanent Link: Ajax Frameworks &#8211; Server side versus Client side">Ajax Frameworks &#8211; Server side versus Client side</a></li><li><a href="http://techtracer.com/2007/01/29/scdjws-mission-accomplished/" rel="bookmark" title="Permanent Link: SCDJWS &#8211; mission accomplished">SCDJWS &#8211; mission accomplished</a></li><li><a href="http://techtracer.com/2007/08/26/eclipse-europa-has-ruined-my-day/" rel="bookmark" title="Permanent Link: Eclipse Europa Has Ruined My Day">Eclipse Europa Has Ruined My Day</a></li></ul><br /><a href="http://techtracer.com/">Techtracer.com</a> Copyright &copy; 2008<br /> ]]></content:encoded>
			<wfw:commentRss>http://techtracer.com/2007/08/15/jax-ws-jaxp-tutorial-building-a-stockquote-web-service-client/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
