<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Other Side</title>
	<atom:link href="http://dyutiman.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dyutiman.wordpress.com</link>
	<description>the other world. other existence.</description>
	<lastBuildDate>Thu, 19 Jan 2012 06:45:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dyutiman.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/3273680b92f7913f46deed7dfad31763?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>The Other Side</title>
		<link>http://dyutiman.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dyutiman.wordpress.com/osd.xml" title="The Other Side" />
	<atom:link rel='hub' href='http://dyutiman.wordpress.com/?pushpress=hub'/>
		<item>
		<title>IceFaces Cancel Button with immediate true</title>
		<link>http://dyutiman.wordpress.com/2011/11/24/icefaces-cancel-button-with-immediate-true/</link>
		<comments>http://dyutiman.wordpress.com/2011/11/24/icefaces-cancel-button-with-immediate-true/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 13:14:19 +0000</pubDate>
		<dc:creator>dyutiman</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[icefaces]]></category>

		<guid isPermaLink="false">http://dyutiman.wordpress.com/?p=223</guid>
		<description><![CDATA[Putting &#8216;immediate=&#8221;true&#8221;&#8216; in a cancel button in an icefaces form will pass the validation process. But to get old form values in place we have to do something in our back end. After searching a whole lot of pages I found two articles to get the solution. https://cwiki.apache.org/confluence/display/MYFACES/Clear+Input+Components https://cwiki.apache.org/confluence/display/MYFACES/How+the+immediate+attribute+works One way to do this is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=223&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Putting &#8216;immediate=&#8221;true&#8221;&#8216; in a cancel button in an icefaces form will pass the validation process. But to get old form values in place we have to do something in our back end.<br />
After searching a whole lot of pages I found two articles to get the solution.</p>
<p><a href="https://cwiki.apache.org/confluence/display/MYFACES/Clear+Input+Components" target="_blank">https://cwiki.apache.org/confluence/display/MYFACES/Clear+Input+Components</a><br />
<a href="https://cwiki.apache.org/confluence/display/MYFACES/How+the+immediate+attribute+works" target="_blank">https://cwiki.apache.org/confluence/display/MYFACES/How+the+immediate+attribute+works</a></p>
<p>One way to do this is to re render the view to get old form values. But in my case the composite view has so many flags to set particular rendering of the components. So just to refresh the page was not working for me. What I did is to set the backing bean value to its old values and call a clear() method on all my UI components needed to be reset.</p>
<p><pre class="brush: java;">
public void cancelCustomer(ActionEvent event) {
	Customer customer = orderEditBackingBean.getSelected().getCustomer();

	orderEditBackingBean.getSelected().setCustomerId(customer.getCustomerId());
	orderEditBackingBean.getSelected().setContactName(customer.getCustomerFirst());
	orderEditBackingBean.getSelected().setCompanyName(customer.getCompanyName());
	orderEditBackingBean.getSelected().setContactPhone(customer.getContactPhone());
	orderEditBackingBean.getSelected().setAddress1(customer.getAddress1());
	orderEditBackingBean.getSelected().setAddress2(customer.getAddress2());
	orderEditBackingBean.getSelected().setCity(customer.getCity());
	orderEditBackingBean.getSelected().setState(customer.getStateCode());
	orderEditBackingBean.getSelected().setZip(customer.getZipCode());
	orderEditBackingBean.getSelected().setCorpNode(customer.getCorpNode());
	
    event.getComponent().getParent().getParent().getParent().getChildren().clear();
    
	orderEditBackingBean.getSelected().setCustomerDisable(true);
	orderEditBackingBean.getSelected().setEditButtonVisible(true);
	orderEditBackingBean.getSelected().setSubmitButtonVisible(false);
}
</pre></p>
<br />Filed under: <a href='http://dyutiman.wordpress.com/category/tech/java/'>java</a>, <a href='http://dyutiman.wordpress.com/category/tech/'>tech</a> Tagged: <a href='http://dyutiman.wordpress.com/tag/icefaces/'>icefaces</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyutiman.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyutiman.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyutiman.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyutiman.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyutiman.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyutiman.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyutiman.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyutiman.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyutiman.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyutiman.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyutiman.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyutiman.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyutiman.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyutiman.wordpress.com/223/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=223&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyutiman.wordpress.com/2011/11/24/icefaces-cancel-button-with-immediate-true/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59f02d533359c629986db3fa9d5d976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dyutiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Pentaho Dashboard &#8211; Show Message if No Data Available</title>
		<link>http://dyutiman.wordpress.com/2011/07/20/pentaho-dashboard-show-message-if-no-data-available/</link>
		<comments>http://dyutiman.wordpress.com/2011/07/20/pentaho-dashboard-show-message-if-no-data-available/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 14:03:38 +0000</pubDate>
		<dc:creator>dyutiman</dc:creator>
				<category><![CDATA[dashboard]]></category>
		<category><![CDATA[pentaho]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[action sequence]]></category>
		<category><![CDATA[pentaho dashboard]]></category>
		<category><![CDATA[xaction]]></category>

		<guid isPermaLink="false">http://dyutiman.wordpress.com/?p=220</guid>
		<description><![CDATA[I do not know how to achieve this in &#8216;jFreeChartComponent&#8217; or in the CCC (community chart component). My solutions are built with action sequence and that&#8217;s where I needed to have this feature. The concept is simple. After getting the result set from the database through &#8216;SQLLookupRule&#8217; component, I am checking if the result set [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=220&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I do not know how to achieve this in &#8216;jFreeChartComponent&#8217; or in the CCC (community chart component). My solutions are built with action sequence and that&#8217;s where I needed to have this feature.</p>
<p>The concept is simple. After getting the result set from the database through &#8216;SQLLookupRule&#8217; component, I am checking if the result set length is greater than zero or not. The &#8216;JavascriptRule&#8217; component is used to determine the length of the result set. And then using the &#8216;if&#8217; condition I am generating the chart or just a simple string saying &#8216;No Result Found&#8217;.</p>
<p>So my action sequence output will be<br />
<pre class="brush: xml;">
&lt;outputs&gt; 
	&lt;image-tag type=&quot;string&quot;/&gt;  
	&lt;output type=&quot;string&quot;/&gt;
&lt;/outputs&gt;
</pre><br />
The &#8216;JavascriptRule&#8217; component to check the result set is simple<br />
<pre class="brush: xml;">
&lt;action-definition&gt;
	&lt;component-name&gt;JavascriptRule&lt;/component-name&gt;
	&lt;action-type&gt;JavaScript&lt;/action-type&gt;
	&lt;action-inputs&gt;
		&lt;queryResult type=&quot;result-set&quot; mapping=&quot;query_result&quot;/&gt; 
	&lt;/action-inputs&gt;
	&lt;action-outputs&gt;
		&lt;noData type=&quot;string&quot;/&gt;
	&lt;/action-outputs&gt;
	&lt;component-definition&gt;
		&lt;script&gt;&lt;![CDATA[noData = &quot;false&quot;;
		if(queryResult.getRowCount() == 0){
			noData = &quot;true&quot;;
		}]]&gt;&lt;/script&gt;
	&lt;/component-definition&gt;
&lt;/action-definition&gt;
</pre><br />
So depending upon the result set name my output variable &#8216;noData&#8217; will be &#8220;true&#8221; or &#8220;false&#8221;. And based on the &#8216;noData&#8217; value I am generating respective output<br />
<pre class="brush: xml;">
&lt;actions&gt; 
	&lt;condition&gt;&lt;![CDATA[noData == &quot;false&quot;]]&gt;&lt;/condition&gt;  
	&lt;action-definition&gt; 
		&lt;component-name&gt;ChartComponent&lt;/component-name&gt;
		&lt;action-type&gt;Pie Chart&lt;/action-type&gt;
		&lt;action-inputs&gt; 
			&lt;chart-data type=&quot;result-set&quot; mapping=&quot;query_result&quot;/&gt;  
		&lt;/action-inputs&gt;
		&lt;action-outputs&gt; 
			&lt;image-tag type=&quot;string&quot;/&gt; 
		&lt;/action-outputs&gt;
		&lt;component-definition&gt; 
			&lt;chart-attributes&gt; 
			&lt;chart-type&gt;PieChart&lt;/chart-type&gt;  
			&lt;title&gt;chartTitle&lt;/title&gt;  
			&lt;title-position&gt;top&lt;/title-position&gt;  
			&lt;display-labels&gt;false&lt;/display-labels&gt;  
			&lt;url-template&gt;javascript:;&lt;/url-template&gt;  
			&lt;paramName&gt;label&lt;/paramName&gt;  
			&lt;width&gt;350&lt;/width&gt;  
			&lt;height&gt;350&lt;/height&gt; 
			&lt;/chart-attributes&gt; 
		&lt;/component-definition&gt; 
	&lt;/action-definition&gt;
&lt;/actions&gt;
  
&lt;actions&gt;
	&lt;condition&gt;&lt;![CDATA[noData == &quot;true&quot;]]&gt;&lt;/condition&gt;
	&lt;action-definition&gt;
		&lt;component-name&gt;JavascriptRule&lt;/component-name&gt;
		&lt;action-type&gt;JavaScript&lt;/action-type&gt;
		&lt;action-outputs&gt;
			&lt;output type=&quot;string&quot;/&gt;
		&lt;/action-outputs&gt;
		&lt;component-definition&gt;
			&lt;script&gt;&lt;![CDATA[output = &quot;No Result Found&quot;;]]&gt;&lt;/script&gt;
		&lt;/component-definition&gt;
	&lt;/action-definition&gt;
&lt;/actions&gt;
</pre></p>
<br />Filed under: <a href='http://dyutiman.wordpress.com/category/tech/pentaho/dashboard/'>dashboard</a>, <a href='http://dyutiman.wordpress.com/category/tech/pentaho/'>pentaho</a>, <a href='http://dyutiman.wordpress.com/category/tech/'>tech</a> Tagged: <a href='http://dyutiman.wordpress.com/tag/action-sequence/'>action sequence</a>, <a href='http://dyutiman.wordpress.com/tag/pentaho/'>pentaho</a>, <a href='http://dyutiman.wordpress.com/tag/pentaho-dashboard/'>pentaho dashboard</a>, <a href='http://dyutiman.wordpress.com/tag/xaction/'>xaction</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyutiman.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyutiman.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyutiman.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyutiman.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyutiman.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyutiman.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyutiman.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyutiman.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyutiman.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyutiman.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyutiman.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyutiman.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyutiman.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyutiman.wordpress.com/220/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=220&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyutiman.wordpress.com/2011/07/20/pentaho-dashboard-show-message-if-no-data-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59f02d533359c629986db3fa9d5d976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dyutiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Pentaho Dashboard &#8211; Export Chart Data</title>
		<link>http://dyutiman.wordpress.com/2011/07/20/pentaho-dashboard-export-chart-data/</link>
		<comments>http://dyutiman.wordpress.com/2011/07/20/pentaho-dashboard-export-chart-data/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 13:20:56 +0000</pubDate>
		<dc:creator>dyutiman</dc:creator>
				<category><![CDATA[dashboard]]></category>
		<category><![CDATA[pentaho]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[action sequence]]></category>
		<category><![CDATA[pentaho dashboard]]></category>
		<category><![CDATA[xaction]]></category>

		<guid isPermaLink="false">http://dyutiman.wordpress.com/?p=215</guid>
		<description><![CDATA[To give user an option to export any chart data in csv format is very easy when you use &#8216;jFreeChartComponent&#8217; to generate the chart. The &#8216;caption&#8217; option in the chart configuration is used to put a &#8216;detail&#8217; link beneath every chart. The &#8216;detail&#8217; link opens up the options to export the chart data and some others. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=215&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>To give user an option to export any chart data in csv format is very easy when you use &#8216;jFreeChartComponent&#8217; to generate the chart. The &#8216;caption&#8217; option in the chart configuration is used to put a &#8216;detail&#8217; link beneath every chart. The &#8216;detail&#8217; link opens up the options to export the chart data and some others.</p>
<p>I didn&#8217;t like the  &#8217;jFreeChartComponent&#8217; because of many reasons. If I do not use mdx queries, I have to expose my normal sql queries in javascript while using &#8216;jFreeChartComponent&#8217;. Also I am not sure how I can make some reusable components while I use &#8216;jFreeChartComponent&#8217;.</p>
<p>So I was looking for a good solution where I can give my dashboard users option to download the chart data in csv format while I generate those chart using action sequences (xaction chartcomponent). I could have used the new Pentaho CCC (community chart component), but my solution was too complex to use CCC&#8217;s auto generated code. I searched for a solution in Pentaho&#8217;s forums but there was no solutions for this. I started one thread there asking for a suggestion, but nobody could come up with any solution. So then I started thinking for a solution by myself.</p>
<p>It was not possible that the same action sequence will be able to provide me the chart as well as the option to generate csv file from the data. So I broke down the solution into three different parts.</p>
<ol>
<li>One action sequence is generating the result set querying the database (chartData.xaction)</li>
<li>One action sequence is using &#8216;SubActionComponent&#8217; and getting the result set from (1) and then generating the chart based on the data using &#8216;ChartComponent&#8217; (chart.xaction)</li>
<li>The other action sequence is again using &#8216;SubActionComponent&#8217; to get the result set from (1) and then  using &#8216;JFreeReportComponent&#8217; to generate the csv file. (csvChart.xaction)</li>
</ol>
<p>So the part of my action sequence generating the chart looks like</p>
<p><pre class="brush: xml;">
&lt;action-definition&gt;
	&lt;component-name&gt;SubActionComponent&lt;/component-name&gt;
	&lt;action-type&gt;Render current Data&lt;/action-type&gt;
	&lt;action-inputs/&gt;
	&lt;action-outputs&gt;
		&lt;query_result type=&quot;result-set&quot; mapping=&quot;query_result&quot;/&gt;
	&lt;/action-outputs&gt;
	&lt;component-definition&gt;
		&lt;solution&gt;&lt;![CDATA[app]]&gt;&lt;/solution&gt;
		&lt;path&gt;&lt;![CDATA[dashboards/SingleChart]]&gt;&lt;/path&gt;
		&lt;action&gt;&lt;![CDATA[currentData.xaction]]&gt;&lt;/action&gt;
	&lt;/component-definition&gt;
&lt;/action-definition&gt;

&lt;action-definition&gt;
	&lt;component-name&gt;ChartComponent&lt;/component-name&gt;
	&lt;action-type&gt;Pie Chart&lt;/action-type&gt;
	&lt;action-inputs&gt;
		&lt;chart-data type=&quot;result-set&quot; mapping=&quot;query_result&quot;/&gt;
	&lt;/action-inputs&gt;
	&lt;action-outputs&gt;
		&lt;image-tag type=&quot;string&quot;/&gt;
	&lt;/action-outputs&gt;
	&lt;component-definition&gt;
		&lt;chart-attributes&gt;
			&lt;chart-type&gt;PieChart&lt;/chart-type&gt;
			&lt;title&gt;chartTitle&lt;/title&gt;
			&lt;title-position&gt;top&lt;/title-position&gt;
			&lt;display-labels&gt;false&lt;/display-labels&gt;
			&lt;url-template&gt;javascript:;&lt;/url-template&gt;
			&lt;paramName&gt;label&lt;/paramName&gt;
			&lt;width&gt;350&lt;/width&gt;
			&lt;height&gt;350&lt;/height&gt;
		&lt;/chart-attributes&gt;
	&lt;/component-definition&gt;
&lt;/action-definition&gt;
</pre></p>
<p>Like the same way the part of the action sequence  generating the csv looks like</p>
<p><pre class="brush: xml;">
&lt;action-definition&gt;
	&lt;component-name&gt;SubActionComponent&lt;/component-name&gt;
	&lt;action-type&gt;Render current Data&lt;/action-type&gt;
	&lt;action-inputs/&gt;
	&lt;action-outputs&gt;
		&lt;query_result type=&quot;result-set&quot; mapping=&quot;query_result&quot;/&gt;
	&lt;/action-outputs&gt;
	&lt;component-definition&gt;
		&lt;solution&gt;&lt;![CDATA[app]]&gt;&lt;/solution&gt;
		&lt;path&gt;&lt;![CDATA[dashboards/SingleChart]]&gt;&lt;/path&gt;
		&lt;action&gt;&lt;![CDATA[currentData.xaction]]&gt;&lt;/action&gt;
	&lt;/component-definition&gt;
&lt;/action-definition&gt;

&lt;action-definition&gt;
	&lt;component-name&gt;JFreeReportComponent&lt;/component-name&gt;
	&lt;action-type&gt;Pentaho Report&lt;/action-type&gt;
	&lt;action-inputs&gt;
		&lt;data type=&quot;result-set&quot; mapping=&quot;query_results&quot;/&gt;
	&lt;/action-inputs&gt;
	&lt;action-resources&gt;
		&lt;report-definition type=&quot;resource&quot;/&gt;
	&lt;/action-resources&gt;
	&lt;action-outputs&gt;
		&lt;report type=&quot;content&quot;/&gt;
	&lt;/action-outputs&gt;
	&lt;component-definition&gt;
		&lt;output-type&gt;csv&lt;/output-type&gt;
	&lt;/component-definition&gt;
&lt;/action-definition&gt;
</pre></p>
<p>So as the action sequences are ready I have to call them in my template file. I am here using &#8216;ExecuteXaction&#8217; component to call the csvChart.xaction, but before that rendering the chart from the template file is very straight forward.<br />
<pre class="brush: jscript;">
components[components.length] = {
	name : &quot;currentChart&quot;,
	type : &quot;XactionComponent&quot;,
	solution : solution,
	path : path,
	action : &quot;chart.xaction&quot;,
	listeners : [],
	parameters : [],
	htmlObject : &quot;renderedChart&quot;,
	executeAtStart : true,
	postExecution: function(){
		Dashboards.fireChange(csvListner, &quot;csvListner&quot;);
	}
};
</pre><br />
and the &#8216;ExecuteXaction&#8217; is listening the &#8216;csvListner&#8217; and fires the event as soon as the chart is loaded.<br />
<pre class="brush: jscript;">
components[components.length] = {
	name : &quot;chartCsv&quot;,
	type : &quot;ExecuteXaction&quot;,
	solution : solution,
	path : path,
	action : &quot;csvCchart.xaction&quot;,
	listeners : [currentCsvListner],
	parameters : [],
	htmlObject : &quot;downLoadData&quot;,
	label: &quot;Download Data&quot;,
	executeAtStart : false
};
</pre><br />
The &#8216;ExecuteXaction&#8217; renders a button saying &#8216;Download Data&#8217; and once clicked the csv download option comes and asks user to save the file.</p>
<br />Filed under: <a href='http://dyutiman.wordpress.com/category/tech/pentaho/dashboard/'>dashboard</a>, <a href='http://dyutiman.wordpress.com/category/tech/pentaho/'>pentaho</a>, <a href='http://dyutiman.wordpress.com/category/tech/'>tech</a> Tagged: <a href='http://dyutiman.wordpress.com/tag/action-sequence/'>action sequence</a>, <a href='http://dyutiman.wordpress.com/tag/pentaho/'>pentaho</a>, <a href='http://dyutiman.wordpress.com/tag/pentaho-dashboard/'>pentaho dashboard</a>, <a href='http://dyutiman.wordpress.com/tag/xaction/'>xaction</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyutiman.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyutiman.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyutiman.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyutiman.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyutiman.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyutiman.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyutiman.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyutiman.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyutiman.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyutiman.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyutiman.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyutiman.wordpress.com/215/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyutiman.wordpress.com/215/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyutiman.wordpress.com/215/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=215&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyutiman.wordpress.com/2011/07/20/pentaho-dashboard-export-chart-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59f02d533359c629986db3fa9d5d976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dyutiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Facebook Canvas App Authentication &#8211; Java</title>
		<link>http://dyutiman.wordpress.com/2011/04/15/facebook-canvas-app-authentication-java/</link>
		<comments>http://dyutiman.wordpress.com/2011/04/15/facebook-canvas-app-authentication-java/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 07:56:09 +0000</pubDate>
		<dc:creator>dyutiman</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[social network app]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[social network]]></category>

		<guid isPermaLink="false">http://dyutiman.wordpress.com/?p=209</guid>
		<description><![CDATA[Facebook will stop supporting canvas FBML apps very soon. So this article only talks about iFrame apps build in Java and using OAuth 2.0 protocol. The basic flow of authentication procedure can be found at facebook&#8217;s developer section. When user is logged in Facebook and access to your app, it sends a signed request to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=209&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Facebook will <a href="http://developers.facebook.com/roadmap/">stop supporting canvas FBML apps</a> very soon. So this article only talks about iFrame apps build in Java and using OAuth 2.0 protocol. The basic flow of authentication procedure can be found at facebook&#8217;s <a href="http://developers.facebook.com/docs/guides/canvas/#auth">developer section</a>.</p>
<p>When user is logged in Facebook and access to your app, it sends a <a href="http://developers.facebook.com/docs/authentication/signed_request/">signed request</a> to the canvas page of the app using POST method. So in your servlet you have to handle the request in doPost method. Check for the presence of Oauth token in the signed request. If that is not present ask for it.</p>
<p>The signed request is a base64url encoded Json object. Now I couldn&#8217;t find anywhere a mapping class which can be mapped to the Json object after base64url decoded signed request. So I had to write it by myself.<br />
<pre class="brush: java;">
public class FacebookSignedRequest {

	private String algorithm;
	private Long expires;
	private Long issued_at;
	private String oauth_token;
	private Long user_id;
	private FacebookSignedRequestUser user;
	
	public String getAlgorithm() {
		return algorithm;
	}
	
	public void setAlgorithm(String algorithm) {
		this.algorithm = algorithm;
	}
	
	public Long getExpires() {
		return expires;
	}
	
	public void setExpires(Long expires) {
		this.expires = expires;
	}
	
	public Long getIssued_at() {
		return issued_at;
	}
	
	public void setIssued_at(Long issued_at) {
		this.issued_at = issued_at;
	}
	
	public String getOauth_token() {
		return oauth_token;
	}
	
	public void setOauth_token(String oauth_token) {
		this.oauth_token = oauth_token;
	}
	
	public Long getUser_id() {
		return user_id;
	}
	
	public void setUser_id(Long user_id) {
		this.user_id = user_id;
	}

	public FacebookSignedRequestUser getUser() {
		return user;
	}

	public void setUser(FacebookSignedRequestUser user) {
		this.user = user;
	}
	
	public static class FacebookSignedRequestUser {

		private String country;
		private String locale;
		private FacebookSignedRequestUserAge age;
		
		public String getCountry() {
			return country;
		}

		public void setCountry(String country) {
			this.country = country;
		}

		public String getLocale() {
			return locale;
		}

		public void setLocale(String locale) {
			this.locale = locale;
		}

		public FacebookSignedRequestUserAge getAge() {
			return age;
		}

		public void setAge(FacebookSignedRequestUserAge age) {
			this.age = age;
		}

		public static class FacebookSignedRequestUserAge{
			private int min;
			private int max;

			public int getMin() {
				return min;
			}

			public void setMin(int min) {
				this.min = min;
			}

			public int getMax() {
				return max;
			}

			public void setMax(int max) {
				this.max = max;
			}
		}
	}
}
</pre><br />
Now I write a Facebook util class which works as a configuration set up for Facebook app<br />
<pre class="brush: java;">
public class FacebookAuthService {

	private static final String apiKey = &quot;APP_KEY&quot;;
	private static final String appSecret = &quot;APP_SECRET&quot;;
	private static final String appId = &quot;APP_ID&quot;;
	
	private static final String redirect_uri = &quot;https://apps.facebook.com/YOUR_APP_PATH&quot;;
	
	private static final String[] perms = new String[] {&quot;publish_stream&quot;, &quot;email&quot;};
	
	public static String getAPIKey() {
		return apiKey;
	}

	public static String getSecret() {
		return appSecret;
	}

	public static String getLoginRedirectURL() {
		return &quot;https://graph.facebook.com/oauth/authorize?client_id=&quot; + appId
				+ &quot;&amp;display=page&amp;redirect_uri=&quot; + redirect_uri + &quot;&amp;scope=&quot;
				+ StringUtils.join(perms);
	}

	public static String getAuthURL(String authCode) {
		return &quot;https://graph.facebook.com/oauth/access_token?client_id=&quot;
				+ appId + &quot;&amp;redirect_uri=&quot; + redirect_uri + &quot;&amp;client_secret=&quot;
				+ appSecret + &quot;&amp;code=&quot; + authCode;
	}
	
	public static String getAuthURL() {
		return &quot;https://www.facebook.com/dialog/oauth?client_id=&quot;
				+ appId + &quot;&amp;redirect_uri=&quot; + redirect_uri + &quot;&amp;scope=&quot;
				+ StringUtils.join(perms);
	}
	
	public static FacebookSignedRequest getFacebookSignedRequest(String signedRequest) throws Exception{
		
		String payLoad = signedRequest.split(&quot;[.]&quot;, 2)[1];
		payLoad = payLoad.replace(&quot;-&quot;, &quot;+&quot;).replace(&quot;_&quot;, &quot;/&quot;).trim();
		
		String jsonString = new String(Base64.decodeBase64(payLoad));
		return new ObjectMapper().readValue(jsonString, FacebookSignedRequest.class);
	}
}
</pre><br />
I&#8217;ve used <a href="http://jackson.codehaus.org/">Jackson</a> to map Json to Object here. But any other API can be used too.</p>
<p>Now in my entry servlet (my canvas URL) I check for it in the doPost method like<br />
<pre class="brush: java;">
String signedRequest = (String) request.getParameter(&quot;signed_request&quot;);

FacebookSignedRequest facebookSignedRequest = FacebookAuthService.getFacebookSignedRequest(signedRequest);
PrintWriter writer = response.getWriter();
if (facebookSignedRequest.getOauth_token() == null) {
	response.setContentType(&quot;text/html&quot;);
	writer.print(&quot;&lt;script&gt; top.location.href='&quot;	+ FacebookAuthService.getAuthURL() + &quot;'&lt;/script&gt;&quot;);
	writer.close();
} else {
	request.setAttribute(&quot;accessToken&quot;,	facebookSignedRequest.getOauth_token());
	RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher(&quot;/YOUR_NEXT_PATH&quot;);
	requestDispatcher.forward(request, response);
}
</pre><br />
So, if the Oauth token is not present in the signed request the servlet redirects user to get the app permission. Once user allows the app the servlet gets the Oauth token in the signed request and pass it to the next page of the app.</p>
<br />Filed under: <a href='http://dyutiman.wordpress.com/category/tech/java/'>java</a>, <a href='http://dyutiman.wordpress.com/category/tech/social-network-app/'>social network app</a>, <a href='http://dyutiman.wordpress.com/category/tech/'>tech</a> Tagged: <a href='http://dyutiman.wordpress.com/tag/facebook/'>facebook</a>, <a href='http://dyutiman.wordpress.com/tag/social-network/'>social network</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyutiman.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyutiman.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyutiman.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyutiman.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyutiman.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyutiman.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyutiman.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyutiman.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyutiman.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyutiman.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyutiman.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyutiman.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyutiman.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyutiman.wordpress.com/209/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=209&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyutiman.wordpress.com/2011/04/15/facebook-canvas-app-authentication-java/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59f02d533359c629986db3fa9d5d976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dyutiman</media:title>
		</media:content>
	</item>
		<item>
		<title>REST Template Using Apache HttpClient</title>
		<link>http://dyutiman.wordpress.com/2011/04/13/rest-template-using-apache-httpclient/</link>
		<comments>http://dyutiman.wordpress.com/2011/04/13/rest-template-using-apache-httpclient/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 13:22:51 +0000</pubDate>
		<dc:creator>dyutiman</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[webservice]]></category>
		<category><![CDATA[httpclient]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://dyutiman.wordpress.com/?p=207</guid>
		<description><![CDATA[Calling REST web services using Spring&#8217;s RestTemplate has been already covered in the other post. Here is a template which can be used out side of Spring. A generalize REST template using Apache&#8217;s HttpClient API. And it can be used like Filed under: java, rest, tech, webservice Tagged: httpclient, rest, web service<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=207&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Calling REST web services using Spring&#8217;s RestTemplate has been already covered in the other post. Here is a template which can be used out side of Spring. A generalize REST template using Apache&#8217;s <a href="http://hc.apache.org/httpcomponents-client-ga/">HttpClient</a> API.</p>
<p><pre class="brush: java;">
package com.your.package.name;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.protocol.HTTP;

public class RestClient {
	public static final int HTTP_OK = 200;
	public static final String SERVER_URL = &quot;BASE URL OF THE REST SERVER&quot;;

	public static String doGet(final String url) throws HttpException,
			IOException, URISyntaxException {

		final HttpClient httpClient = new DefaultHttpClient();
		HttpConnectionParams
				.setConnectionTimeout(httpClient.getParams(), 10000);
		HttpGet httpget = new HttpGet(SERVER_URL + url);
		HttpResponse response = httpClient.execute(httpget);
		HttpEntity entity = response.getEntity();
		InputStream instream = entity.getContent();
		return read(instream);
	}

	public static String doPost(final String url, final String POSTText)
			throws URISyntaxException, HttpException, IOException {

		final HttpClient httpClient = new DefaultHttpClient();
		HttpConnectionParams
				.setConnectionTimeout(httpClient.getParams(), 10000);

		HttpPost httpPost = new HttpPost(SERVER_URL + url);
		StringEntity entity = new StringEntity(POSTText, &quot;UTF-8&quot;);
		BasicHeader basicHeader = new BasicHeader(HTTP.CONTENT_TYPE,
				&quot;application/json&quot;);
		httpPost.getParams().setBooleanParameter(
				&quot;http.protocol.expect-continue&quot;, false);
		entity.setContentType(basicHeader);
		httpPost.setEntity(entity);
		HttpResponse response = httpClient.execute(httpPost);
		InputStream instream = response.getEntity().getContent();
		return read(instream);
	}

	public static boolean doPut(final String url, final String PUTText)
			throws URISyntaxException, HttpException, IOException {
		final HttpClient httpClient = new DefaultHttpClient();
		HttpConnectionParams
				.setConnectionTimeout(httpClient.getParams(), 10000);

		HttpPut httpPut = new HttpPut(SERVER_URL + url);
		httpPut.addHeader(&quot;Accept&quot;, &quot;application/json&quot;);
		httpPut.addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);
		StringEntity entity = new StringEntity(PUTText, &quot;UTF-8&quot;);
		entity.setContentType(&quot;application/json&quot;);
		httpPut.setEntity(entity);
		HttpResponse response = httpClient.execute(httpPut);
		int statusCode = response.getStatusLine().getStatusCode();
		return statusCode == HTTP_OK ? true : false;
	}

	public static boolean doDelete(final String url) throws HttpException,
			IOException, URISyntaxException {
		final HttpClient httpClient = new DefaultHttpClient();
		HttpConnectionParams
				.setConnectionTimeout(httpClient.getParams(), 10000);

		HttpDelete httpDelete = new HttpDelete(SERVER_URL + url);
		httpDelete.addHeader(&quot;Accept&quot;,
				&quot;text/html, image/jpeg, *; q=.2, */*; q=.2&quot;);
		HttpResponse response = httpClient.execute(httpDelete);
		int statusCode = response.getStatusLine().getStatusCode();
		return statusCode == HTTP_OK ? true : false;
	}

	private static String read(InputStream in) throws IOException {
		StringBuilder sb = new StringBuilder();
		BufferedReader r = new BufferedReader(new InputStreamReader(in), 1000);
		for (String line = r.readLine(); line != null; line = r.readLine()) {
			sb.append(line);
		}
		in.close();
		return sb.toString();
	}
}
</pre></p>
<p>And it can be used like<br />
<pre class="brush: java;">
RestClient.doDelete(&quot;/registration/&quot; + userToken);
RestClient.doGet(&quot;/me/profile?ct=&quot; + userToken);
</pre></p>
<br />Filed under: <a href='http://dyutiman.wordpress.com/category/tech/java/'>java</a>, <a href='http://dyutiman.wordpress.com/category/tech/webservice/rest/'>rest</a>, <a href='http://dyutiman.wordpress.com/category/tech/'>tech</a>, <a href='http://dyutiman.wordpress.com/category/tech/webservice/'>webservice</a> Tagged: <a href='http://dyutiman.wordpress.com/tag/httpclient/'>httpclient</a>, <a href='http://dyutiman.wordpress.com/tag/rest/'>rest</a>, <a href='http://dyutiman.wordpress.com/tag/web-service/'>web service</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyutiman.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyutiman.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyutiman.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyutiman.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyutiman.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyutiman.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyutiman.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyutiman.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyutiman.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyutiman.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyutiman.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyutiman.wordpress.com/207/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyutiman.wordpress.com/207/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyutiman.wordpress.com/207/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=207&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyutiman.wordpress.com/2011/04/13/rest-template-using-apache-httpclient/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59f02d533359c629986db3fa9d5d976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dyutiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Extract Text from HTML using NekoHTML and Dom4j</title>
		<link>http://dyutiman.wordpress.com/2010/12/13/extract-text-from-html-using-nekohtml-and-dom4j/</link>
		<comments>http://dyutiman.wordpress.com/2010/12/13/extract-text-from-html-using-nekohtml-and-dom4j/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 06:34:34 +0000</pubDate>
		<dc:creator>dyutiman</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[dom4j]]></category>
		<category><![CDATA[nekohtml]]></category>

		<guid isPermaLink="false">http://dyutiman.wordpress.com/?p=204</guid>
		<description><![CDATA[Consider the link http://www.cdw.com/shop/search/results.aspx?wclss=C3&#38;enkwrd=laptop&#38;searchscope=ALL. Lets extract the total search result and title of each item to keep the example simple enough. We will be using XPath to find each element in the HTML page. Here is the code Remember to use uppercase for any HTML tag. Filed under: java, tech Tagged: dom4j, nekohtml<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=204&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Consider the link <a href="http://www.cdw.com/shop/search/results.aspx?wclss=C3&amp;enkwrd=laptop&amp;searchscope=ALL">http://www.cdw.com/shop/search/results.aspx?wclss=C3&amp;enkwrd=laptop&amp;searchscope=ALL</a>.<br />
Lets extract the total search result and title of each item to keep the example simple enough. We will be using XPath to find each element in the HTML page.<br />
Here is the code<br />
<pre class="brush: java;">
package com.asc.dyutiman.html;

import java.io.IOException;
import java.util.List;

import org.cyberneko.html.parsers.DOMParser;
import org.dom4j.Node;
import org.dom4j.io.DOMReader;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class Parse {
	
	public static void main(String[] args){
		
		String url = &quot;http://www.cdw.com/shop/search/results.aspx?wclss=C3&amp;enkwrd=laptop&amp;searchscope=ALL&quot;;
		try {
			DOMParser parser = new DOMParser();
			parser.parse(url);
			
			Document document = parser.getDocument();
			DOMReader reader = new DOMReader();
			org.dom4j.Document doc = reader.read(document);
			
			Node totalResultNode = doc.selectSingleNode(&quot;//SPAN[@id='lblShowingResultsTop']/B[3]&quot;);
			
			@SuppressWarnings(&quot;unchecked&quot;)
			List&lt;Node&gt; itemList =  doc.selectNodes(&quot;//DIV[@class = 'searchrow']&quot;);

			System.out.println(&quot;Showing &quot; + itemList.size() + &quot; out of &quot; + totalResultNode.getText());
			for(Node itemNode : itemList){
				Node itemTitle = itemNode.selectSingleNode(&quot;DIV[@class = 'searchrow-description']/A&quot;);
				System.out.println(itemTitle.getText());
			}
		} catch (SAXException e) {
			System.out.println(e.getMessage());
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}
}
</pre><br />
Remember to use uppercase for any HTML tag.</p>
<br />Filed under: <a href='http://dyutiman.wordpress.com/category/tech/java/'>java</a>, <a href='http://dyutiman.wordpress.com/category/tech/'>tech</a> Tagged: <a href='http://dyutiman.wordpress.com/tag/dom4j/'>dom4j</a>, <a href='http://dyutiman.wordpress.com/tag/nekohtml/'>nekohtml</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyutiman.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyutiman.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyutiman.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyutiman.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyutiman.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyutiman.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyutiman.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyutiman.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyutiman.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyutiman.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyutiman.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyutiman.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyutiman.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyutiman.wordpress.com/204/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=204&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyutiman.wordpress.com/2010/12/13/extract-text-from-html-using-nekohtml-and-dom4j/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59f02d533359c629986db3fa9d5d976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dyutiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple REST Web Service &#8211; Spring</title>
		<link>http://dyutiman.wordpress.com/2010/12/09/simple-rest-web-service-spring/</link>
		<comments>http://dyutiman.wordpress.com/2010/12/09/simple-rest-web-service-spring/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 11:59:57 +0000</pubDate>
		<dc:creator>dyutiman</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[webservice]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://dyutiman.wordpress.com/?p=195</guid>
		<description><![CDATA[The Service : Create a project with Maven for Eclipse Dynamic Web Project from here. Here I have used Spring Annotation up to my knowledge. I believe there are more things which can be annotated. The Deployment Descriptor (web.xml) is the simplest So we must have the person-servlet.xml We use org.springframework.oxm.xstream.XStreamMarshaller for converting Java Object [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=195&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><em>The Service :</em></strong><br />
Create a project with Maven for Eclipse Dynamic Web Project from <a href="http://dyutiman.wordpress.com/2010/12/07/create-a-project-with-maven-for-eclipse/">here</a>.</p>
<p>Here I have used Spring Annotation up to my knowledge. I believe there are more things which can be annotated.</p>
<p>The Deployment Descriptor (web.xml) is the simplest<br />
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; xmlns:web=&quot;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
	version=&quot;2.5&quot; id=&quot;WebApp_1291891438549&quot;&gt;

  	&lt;display-name&gt;Spring REST Example1&lt;/display-name&gt;
  	&lt;servlet&gt;
		&lt;servlet-name&gt;person&lt;/servlet-name&gt;
		&lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;person&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
	
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;
&lt;/web-app&gt;
</pre><br />
So we must have the person-servlet.xml<br />
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
	xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xmlns:oxm=&quot;http://www.springframework.org/schema/oxm&quot;
	xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
				http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
				http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd&quot;&gt;

	&lt;context:component-scan base-package=&quot;com.dyuti.spring.rest&quot; /&gt;

	&lt;!-- Format Output --&gt;
	&lt;bean class=&quot;org.springframework.web.servlet.view.BeanNameViewResolver&quot; /&gt;
	&lt;bean id=&quot;personXmlView&quot;
		class=&quot;org.springframework.web.servlet.view.xml.MarshallingView&quot;&gt;
		&lt;constructor-arg&gt;
			&lt;bean class=&quot;org.springframework.oxm.xstream.XStreamMarshaller&quot;&gt;
				&lt;property name=&quot;autodetectAnnotations&quot; value=&quot;true&quot; /&gt;
			&lt;/bean&gt;
		&lt;/constructor-arg&gt;
	&lt;/bean&gt;
	&lt;!--          --&gt;

	&lt;!-- Convert Input --&gt;
	&lt;bean
		class=&quot;org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping&quot; /&gt;
	&lt;bean
		class=&quot;org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter&quot;&gt;
		&lt;property name=&quot;messageConverters&quot;&gt;
			&lt;list&gt;
				&lt;ref bean=&quot;marshallingHttpMessageConverter&quot; /&gt;
			&lt;/list&gt;
		&lt;/property&gt;
	&lt;/bean&gt;

	&lt;bean id=&quot;marshallingHttpMessageConverter&quot;
		class=&quot;org.springframework.http.converter.xml.MarshallingHttpMessageConverter&quot;&gt;
		&lt;property name=&quot;marshaller&quot; ref=&quot;jaxb2Marshaller&quot; /&gt;
		&lt;property name=&quot;unmarshaller&quot; ref=&quot;jaxb2Marshaller&quot; /&gt;
	&lt;/bean&gt;

	&lt;bean id=&quot;jaxb2Marshaller&quot; class=&quot;org.springframework.oxm.jaxb.Jaxb2Marshaller&quot;&gt;
		&lt;property name=&quot;classesToBeBound&quot;&gt;
			&lt;list&gt;
				&lt;value&gt;com.dyuti.spring.rest.domain.Person&lt;/value&gt;
			&lt;/list&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
	&lt;!--          --&gt;

	&lt;bean id=&quot;myDataSource&quot; class=&quot;org.apache.commons.dbcp.BasicDataSource&quot;&gt;
		&lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot; /&gt;
		&lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost/person&quot; /&gt;
		&lt;property name=&quot;username&quot; value=&quot;root&quot; /&gt;
		&lt;property name=&quot;password&quot; value=&quot;*****&quot; /&gt;
	&lt;/bean&gt;

	&lt;bean id=&quot;mySessionFactory&quot;
		class=&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;&gt;
		&lt;property name=&quot;dataSource&quot; ref=&quot;myDataSource&quot; /&gt;
		&lt;property name=&quot;annotatedClasses&quot;&gt;
			&lt;list&gt;
				&lt;value&gt;com.dyuti.spring.rest.domain.Person&lt;/value&gt;
			&lt;/list&gt;
		&lt;/property&gt;
		&lt;property name=&quot;hibernateProperties&quot;&gt;
			&lt;value&gt;hibernate.dialect=org.hibernate.dialect.MySQLDialect&lt;/value&gt;
		&lt;/property&gt;
	&lt;/bean&gt;

	&lt;bean id=&quot;personDao&quot; class=&quot;com.dyuti.spring.rest.dao.PersonDaoHibImpl&quot;&gt;
		&lt;property name=&quot;sessionFactory&quot; ref=&quot;mySessionFactory&quot; /&gt;
	&lt;/bean&gt;
&lt;/beans&gt;
</pre><br />
We use org.springframework.oxm.xstream.XStreamMarshaller for converting Java Object to XML for sending through HTTP, and also converting HTTP XML data to corresponding Java Object.</p>
<p>The simple Person objec<br />
<pre class="brush: java;">
package com.dyuti.spring.rest.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XmlRootElement
@XStreamAlias(&quot;person&quot;)
@Entity
@Table(name = &quot;person&quot;)
public class Person implements Serializable {

	private static final long serialVersionUID = 2675617253130859687L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	@Column
	private String name;
	@Column
	private int age;

	// Generate getter &amp; setter here
}
</pre><br />
Now the DAO and the Hibernate Implementation<br />
<pre class="brush: java;">
package com.dyuti.spring.rest.dao;

import com.dyuti.spring.rest.domain.Person;

public interface PersonDao {
	
	public boolean save(Person person);
	
	public Person get(int id);
}
</pre><br />
<pre class="brush: java;">
package com.dyuti.spring.rest.dao;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.dyuti.spring.rest.domain.Person;

@Repository(&quot;personDao&quot;)
public class PersonDaoHibImpl extends HibernateDaoSupport implements PersonDao {

	@Override
	public boolean save(Person person) {
		int id = (Integer) getHibernateTemplate().save(person);
		return id &gt; 0 ? true : false;
	}

	@Override
	public Person get(int id) {
		return (Person) getHibernateTemplate().get(Person.class, id);
	}
}
</pre></p>
<p>And the service and its implementation<br />
<pre class="brush: java;">
package com.dyuti.spring.rest.service;

import com.dyuti.spring.rest.domain.Person;

public interface PersonService {

	public boolean savePerson(Person p);
	
	public Person getPerson(int id);
}
</pre><br />
<pre class="brush: java;">
package com.dyuti.spring.rest.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dyuti.spring.rest.dao.PersonDao;
import com.dyuti.spring.rest.domain.Person;

@Service(&quot;personService&quot;)
public class PersonServiceImpl implements PersonService {

	@Autowired
	private PersonDao personDao;

	@Override
	public boolean savePerson(Person person) {
		return personDao.save(person);
	}

	@Override
	public Person getPerson(int id) {
		return personDao.get(id);
	}
}
</pre><br />
The controller is the entry point and also the provider of the web service.<br />
<pre class="brush: java;">
package com.dyuti.spring.rest.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.dyuti.spring.rest.domain.Person;
import com.dyuti.spring.rest.service.PersonService;

@Controller
public class PersonController {

	@Autowired
	private PersonService personService;

	@RequestMapping(value = &quot;/{id}&quot;, method = RequestMethod.GET)
	public ModelAndView getPerson(@PathVariable int id) {
		Person person = personService.getPerson(id);
		return new ModelAndView(&quot;personXmlView&quot;, BindingResult.MODEL_KEY_PREFIX
				+ &quot;person&quot;, person);
	}

	@RequestMapping(value = &quot;/add&quot;, method = RequestMethod.POST)
	public ModelAndView addPerson(@RequestBody Person person) {
		boolean result = personService.savePerson(person);
		return new ModelAndView(&quot;personXmlView&quot;, BindingResult.MODEL_KEY_PREFIX
				+ &quot;person&quot;, result);
	}
}
</pre><br />
Finally the pom.xml<br />
<pre class="brush: xml;">
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;groupId&gt;com.dyuti.spring.rest&lt;/groupId&gt;
	&lt;artifactId&gt;SpringREST&lt;/artifactId&gt;
	&lt;packaging&gt;war&lt;/packaging&gt;
	&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
	&lt;name&gt;SpringREST&lt;/name&gt;
	&lt;url&gt;http://maven.apache.org&lt;/url&gt;

	&lt;build&gt;
		&lt;finalName&gt;SpringREST&lt;/finalName&gt;
		&lt;sourceDirectory&gt;${basedir}/src/main/java&lt;/sourceDirectory&gt;

		&lt;resources&gt;
			&lt;resource&gt;
				&lt;directory&gt;${basedir}/src/main/resources&lt;/directory&gt;
			&lt;/resource&gt;
		&lt;/resources&gt;

		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
				&lt;version&gt;2.0.2&lt;/version&gt;
				&lt;configuration&gt;
					&lt;source&gt;1.6&lt;/source&gt;
					&lt;target&gt;1.6&lt;/target&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;

			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
				&lt;executions&gt;
					&lt;execution&gt;
						&lt;id&gt;copy-dependencies&lt;/id&gt;
						&lt;phase&gt;package&lt;/phase&gt;
						&lt;goals&gt;
							&lt;goal&gt;copy-dependencies&lt;/goal&gt;
						&lt;/goals&gt;
						&lt;configuration&gt;
							&lt;!-- configure the plugin here --&gt;
						&lt;/configuration&gt;
					&lt;/execution&gt;
				&lt;/executions&gt;
			&lt;/plugin&gt;

			&lt;plugin&gt;
				&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
				&lt;version&gt;2.0&lt;/version&gt;
				&lt;configuration&gt;
					&lt;webResources&gt;
						&lt;resource&gt;
							&lt;directory&gt;${basedir}/src/main/webapp&lt;/directory&gt;
							&lt;filtering&gt;false&lt;/filtering&gt;
							&lt;excludes&gt;
								&lt;exclude&gt;WEB-INF/lib/*&lt;/exclude&gt;
							&lt;/excludes&gt;
						&lt;/resource&gt;
					&lt;/webResources&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;

	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;javax.servlet&lt;/groupId&gt;
			&lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
			&lt;version&gt;2.4&lt;/version&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;commons-beanutils&lt;/groupId&gt;
			&lt;artifactId&gt;commons-beanutils&lt;/artifactId&gt;
			&lt;version&gt;${commons.beanutils.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;commons-collections&lt;/groupId&gt;
			&lt;artifactId&gt;commons-collections&lt;/artifactId&gt;
			&lt;version&gt;${commons.collections.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;commons-lang&lt;/groupId&gt;
			&lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
			&lt;version&gt;${commons.lang.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;commons-io&lt;/groupId&gt;
			&lt;artifactId&gt;commons-io&lt;/artifactId&gt;
			&lt;version&gt;${commons.io.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;commons-digester&lt;/groupId&gt;
			&lt;artifactId&gt;commons-digester&lt;/artifactId&gt;
			&lt;version&gt;1.6&lt;/version&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;xml-apis&lt;/groupId&gt;
					&lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;commons-logging&lt;/groupId&gt;
			&lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
			&lt;version&gt;1.1.1&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
			&lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
			&lt;version&gt;1.2.1&lt;/version&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;xml-apis&lt;/groupId&gt;
					&lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;xerces&lt;/groupId&gt;
					&lt;artifactId&gt;xerces&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;commons-pool&lt;/groupId&gt;
			&lt;artifactId&gt;commons-pool&lt;/artifactId&gt;
			&lt;version&gt;1.2&lt;/version&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;xml-apis&lt;/groupId&gt;
					&lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;xerces&lt;/groupId&gt;
					&lt;artifactId&gt;xerces&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
			&lt;artifactId&gt;hibernate&lt;/artifactId&gt;
			&lt;version&gt;${hibernate.version}&lt;/version&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;artifactId&gt;ehcache&lt;/artifactId&gt;
					&lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;artifactId&gt;commons-collections&lt;/artifactId&gt;
					&lt;groupId&gt;commons-collections&lt;/groupId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
			&lt;artifactId&gt;hibernate-annotations&lt;/artifactId&gt;
			&lt;version&gt;${hibernate.annotations.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
			&lt;artifactId&gt;hibernate-commons-annotations&lt;/artifactId&gt;
			&lt;version&gt;${hibernate.annotations.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;mysql&lt;/groupId&gt;
			&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
			&lt;version&gt;5.1.8&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.openejb&lt;/groupId&gt;
			&lt;artifactId&gt;commons-dbcp-all&lt;/artifactId&gt;
			&lt;version&gt;1.3&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;javax.persistence&lt;/groupId&gt;
			&lt;artifactId&gt;persistence-api&lt;/artifactId&gt;
			&lt;version&gt;${jpa.version}&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;javax.validation&lt;/groupId&gt;
			&lt;artifactId&gt;validation-api&lt;/artifactId&gt;
			&lt;version&gt;1.0.0.GA&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-context&lt;/artifactId&gt;
			&lt;version&gt;${spring.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-core&lt;/artifactId&gt;
			&lt;version&gt;${spring.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-web&lt;/artifactId&gt;
			&lt;version&gt;${spring.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
			&lt;version&gt;${spring.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
			&lt;version&gt;${spring.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-oxm&lt;/artifactId&gt;
			&lt;version&gt;${spring.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
			&lt;version&gt;${spring.version}&lt;/version&gt;
		&lt;/dependency&gt;
		

		&lt;dependency&gt;
			&lt;groupId&gt;com.thoughtworks.xstream&lt;/groupId&gt;
			&lt;artifactId&gt;xstream&lt;/artifactId&gt;
			&lt;version&gt;1.3.1&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;junit&lt;/groupId&gt;
			&lt;artifactId&gt;junit&lt;/artifactId&gt;
			&lt;version&gt;3.8.1&lt;/version&gt;
			&lt;scope&gt;test&lt;/scope&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;

	&lt;properties&gt;
		&lt;spring.version&gt;3.0.0.RELEASE&lt;/spring.version&gt;
		&lt;java.version&gt;1.6&lt;/java.version&gt;
		&lt;servlet-api.version&gt;2.5.0&lt;/servlet-api.version&gt;
		&lt;hibernate.annotations.version&gt;3.3.0.ga&lt;/hibernate.annotations.version&gt;
		&lt;hibernate.version&gt;3.2.6.ga&lt;/hibernate.version&gt;
		&lt;jpa.version&gt;1.0&lt;/jpa.version&gt;
		&lt;commons.beanutils.version&gt;1.7.0&lt;/commons.beanutils.version&gt;
		&lt;commons.collections.version&gt;3.2&lt;/commons.collections.version&gt;
		&lt;commons.io.version&gt;1.3.2&lt;/commons.io.version&gt;
		&lt;commons.lang.version&gt;2.3&lt;/commons.lang.version&gt;
	&lt;/properties&gt;
&lt;/project&gt;
</pre><br />
So, the project is set up and deploy it on Tomcat.</p>
<p><strong><em>The client :</em></strong><br />
The RestClient provided by Spring makes life very simple creating REST consumer.<br />
Create another project (not necessary a web project, client can be anything, even if Ajax). </p>
<p>Create the same Person object from above.<br />
Lets create the Spring context file, resides in the same package of the loader class under resource folder.<br />
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
	xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xmlns:oxm=&quot;http://www.springframework.org/schema/oxm&quot;
	xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
				http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
				http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd&quot;&gt;

	&lt;context:component-scan base-package=&quot;com.dyuti.spring.rest&quot; /&gt;

	&lt;bean id=&quot;personSave&quot; class=&quot;com.dyuti.spring.rest.controller.SavePerson&quot;&gt;
		&lt;property name=&quot;restTemplate&quot;&gt;
			&lt;ref bean=&quot;restTemplate&quot; /&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
	&lt;bean id=&quot;restTemplate&quot; class=&quot;org.springframework.web.client.RestTemplate&quot;&gt;&lt;/bean&gt;
&lt;/beans&gt;
</pre><br />
And the client class<br />
<pre class="brush: java;">
package com.dyuti.spring.rest.controller;

import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import com.dyuti.spring.rest.domain.Person;

@Component
public class SavePerson {

	private RestTemplate restTemplate;

	private String restURL = &quot;http://localhost:8080/SpringREST/&quot;;

	public void sendPerson() {
		Person person = new Person();
		person.setName(&quot;client&quot;);
		person.setAge(12);
		person.setId(3);

		Person p = restTemplate.getForObject(restURL + &quot;2&quot;, Person.class);
		System.out.println(p.getName());

		String result = restTemplate.postForObject(restURL + &quot;add&quot;, person,
				String.class);
		System.out.println(result);
	}

	public void setRestTemplate(RestTemplate restTemplate) {
		this.restTemplate = restTemplate;
	}
}
</pre><br />
Run the client<br />
<pre class="brush: java;">
package com.dyuti.spring.rest.controller;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class RunRest {

	public static void main(String[] args) {
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
				&quot;applicationContext.xml&quot;, RunRest.class);
		SavePerson savePerson = applicationContext.getBean(&quot;personSave&quot;,
				SavePerson.class);
		savePerson.sendPerson();
	}
}
</pre><br />
I have used the same pom.xml for this project, which may require less packages.</p>
<br />Filed under: <a href='http://dyutiman.wordpress.com/category/tech/java/'>java</a>, <a href='http://dyutiman.wordpress.com/category/tech/webservice/rest/'>rest</a>, <a href='http://dyutiman.wordpress.com/category/tech/java/spring/'>spring</a>, <a href='http://dyutiman.wordpress.com/category/tech/'>tech</a>, <a href='http://dyutiman.wordpress.com/category/tech/webservice/'>webservice</a> Tagged: <a href='http://dyutiman.wordpress.com/tag/annotation/'>annotation</a>, <a href='http://dyutiman.wordpress.com/tag/maven/'>maven</a>, <a href='http://dyutiman.wordpress.com/tag/rest/'>rest</a>, <a href='http://dyutiman.wordpress.com/tag/spring/'>spring</a>, <a href='http://dyutiman.wordpress.com/tag/web-service/'>web service</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyutiman.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyutiman.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyutiman.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyutiman.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyutiman.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyutiman.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyutiman.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyutiman.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyutiman.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyutiman.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyutiman.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyutiman.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyutiman.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyutiman.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=195&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyutiman.wordpress.com/2010/12/09/simple-rest-web-service-spring/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59f02d533359c629986db3fa9d5d976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dyutiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Create a Project with Maven for Eclipse</title>
		<link>http://dyutiman.wordpress.com/2010/12/07/create-a-project-with-maven-for-eclipse/</link>
		<comments>http://dyutiman.wordpress.com/2010/12/07/create-a-project-with-maven-for-eclipse/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 11:39:22 +0000</pubDate>
		<dc:creator>dyutiman</dc:creator>
				<category><![CDATA[maven]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[eclipse]]></category>

		<guid isPermaLink="false">http://dyutiman.wordpress.com/?p=192</guid>
		<description><![CDATA[Install &#38; configure Maven from http://maven.apache.org/download.html. Go to eclipse workspace and run the following command -DartifactId is your project name and -DgrouipId is your package. Change the &#8216;com.mycompany.app&#8217; and &#8216;my-app&#8217; as you want them to be. The command will download necessary poms &#38; jars and create the folder architecture with a very basic pom.xml file. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=192&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Install &amp; configure Maven from <a href="http://maven.apache.org/download.html">http://maven.apache.org/download.html</a>.</p>
<p>Go to eclipse workspace and run the following command<br />
<pre class="brush: plain;">
mvn archetype:create -DgroupId=com.mycompany.projectname -DartifactId=projectname -DarchetypeArtifactId=maven-archetype-webapp
</pre><br />
-DartifactId is your project name and -DgrouipId is your package.<br />
Change the &#8216;com.mycompany.app&#8217; and &#8216;my-app&#8217; as you want them to be.<br />
The command will download necessary poms &amp; jars and  create the folder architecture with a very basic pom.xml file.</p>
<p>Now, we will make it an eclipse project so that we can import it from eclipse. Go to the project folder. Run<br />
<pre class="brush: plain;">
cd my-app
mvn eclipse:eclipse -Dwtpversion=2.0
</pre><br />
This will generate eclipse .classpath &amp; .project file. So open eclipse and just import the project.</p>
<p>To make a web project change jar to war in pom.xml and run<br />
<pre class="brush: plain;">
mvn eclipse:clean eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true -Dwtpversion=2.0
</pre></p>
<p>Refer <a href="http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html">this article</a> for more.</p>
<br />Filed under: <a href='http://dyutiman.wordpress.com/category/tech/maven/'>maven</a>, <a href='http://dyutiman.wordpress.com/category/tech/'>tech</a> Tagged: <a href='http://dyutiman.wordpress.com/tag/eclipse/'>eclipse</a>, <a href='http://dyutiman.wordpress.com/tag/maven/'>maven</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyutiman.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyutiman.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyutiman.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyutiman.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyutiman.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyutiman.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyutiman.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyutiman.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyutiman.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyutiman.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyutiman.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyutiman.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyutiman.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyutiman.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=192&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyutiman.wordpress.com/2010/12/07/create-a-project-with-maven-for-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59f02d533359c629986db3fa9d5d976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dyutiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple JNI Example</title>
		<link>http://dyutiman.wordpress.com/2010/11/29/simple-jni-example/</link>
		<comments>http://dyutiman.wordpress.com/2010/11/29/simple-jni-example/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 12:51:18 +0000</pubDate>
		<dc:creator>dyutiman</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jni]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://dyutiman.wordpress.com/?p=188</guid>
		<description><![CDATA[Make a native method in java and call it. Compile it with javac Filename.java Now run the following command to make the header(.h) file javah -jni Filename It will generate a header file with proper name and will have native method signature in it. Now as the header file is created and the method signature [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=188&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Make a native method in java and call it.<br />
<pre class="brush: java;">
static {
	System.loadLibrary(&quot;multiply&quot;);
}

public native int multiply(int a, int b);

public static void main(String[] args) {

	GetPhotoData getPhotoData = new GetPhotoData();

	int a = 8;
	int b = 6;

	int c = getPhotoData.multiply(a, b);
	System.out.println(c);
}
</pre><br />
Compile it with<br />
<strong><em>javac Filename.java</em></strong></p>
<p>Now run the following command to make the header(.h) file<br />
<strong><em>javah -jni Filename</em></strong></p>
<p>It will generate a header file with proper name and will have native method signature in it.<br />
<pre class="brush: cpp;">
/* DO NOT EDIT THIS FILE - it is machine generated */
#include &lt;jni.h&gt;
/* Header for class com_financial_inclusive_jni_GetPhotoData */

#ifndef _Included_com_financial_inclusive_jni_GetPhotoData
#define _Included_com_financial_inclusive_jni_GetPhotoData
#ifdef __cplusplus
extern &quot;C&quot; {
#endif
/*
 * Class:     com_financial_inclusive_jni_GetPhotoData
 * Method:    multiply
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_com_financial_inclusive_jni_GetPhotoData_multiply
  (JNIEnv *, jobject, jint, jint);

#ifdef __cplusplus
}
#endif
#endif
</pre><br />
Now as the header file is created and the method signature of the native method to be implemented is there, make a C file which implements the method. Include the header file so it can find it.<br />
<pre class="brush: cpp;">
#include &quot;com_financial_inclusive_jni_GetPhotoData.h&quot;

JNIEXPORT jint JNICALL Java_com_financial_inclusive_jni_GetPhotoData_multiply
  (JNIEnv *env, jobject thisobject, jint ja, jint jb){
	return ja*jb;
}
</pre><br />
I did it on windows. So I had to make a dll file and keep it under C:/WINDOWS/System32 which is added to my %path% system variable.</p>
<p>I&#8217;ve used <a href="http://altd.embarcadero.com/download/bcppbuilder/freecommandLinetools.exe">Borland compiler</a> to generate the dll by running<br />
<pre class="brush: plain;">
D:\Borland\BCC55\Bin&gt;bcc32 -WD d:\workspace\FinancialIncl\src\multiply.c
</pre><br />
When first time compiled it will throw an error and quite. </p>
<p>Here you see that the C method created has two more extra arguments than we passed. The first one is the pointer to JVM environment and the second one is the reference object to the class.  In our case we do not use those variables in our C implementation. So the compiler just gives warning about it and exits. We have to suppress these warnings to create the dll.<br />
<pre class="brush: plain;">
D:\Borland\BCC55\Bin&gt;bcc32 -WD -w-par d:\workspace\FinancialIncl\src\multiply.c
</pre></p>
<p>Here is a nice <a href="http://jainakj.blogspot.com/2009/11/jni-java-native-interface-generating.html">reference</a> from where I got all the resources.<br />
And for Borland command options, please refer <a href="http://www.januszg.hg.pl/bcc55/parametry_bcc32.html">this</a>.</p>
<br />Filed under: <a href='http://dyutiman.wordpress.com/category/tech/java/'>java</a>, <a href='http://dyutiman.wordpress.com/category/tech/java/jni/'>jni</a>, <a href='http://dyutiman.wordpress.com/category/tech/'>tech</a> Tagged: <a href='http://dyutiman.wordpress.com/tag/jni/'>jni</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyutiman.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyutiman.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyutiman.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyutiman.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyutiman.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyutiman.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyutiman.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyutiman.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyutiman.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyutiman.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyutiman.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyutiman.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyutiman.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyutiman.wordpress.com/188/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=188&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyutiman.wordpress.com/2010/11/29/simple-jni-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59f02d533359c629986db3fa9d5d976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dyutiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Web Service for Lucene Search on Tomcat</title>
		<link>http://dyutiman.wordpress.com/2010/10/01/web-service-for-lucene-search-on-tomcat/</link>
		<comments>http://dyutiman.wordpress.com/2010/10/01/web-service-for-lucene-search-on-tomcat/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 08:51:49 +0000</pubDate>
		<dc:creator>dyutiman</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://dyutiman.wordpress.com/?p=185</guid>
		<description><![CDATA[The SearchUtil class is created to search on Lucene. This also uses a stop words file to eliminate those words and/or numbers. The class returns ids matched to a table for related search results. The next class is the web service which takes various search criterion. To enable the web service on Tomcat we have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=185&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The SearchUtil class is created to search on Lucene. This also uses a stop words file to eliminate those words and/or numbers. The class returns ids matched to a table for related search results.<br />
<pre class="brush: java;">
public class SearchUtil {

    private String stopWordsFile = &quot;/mnt/lucene/bmindex/stopwords.txt&quot;;

    public int[] search(int clientId, int keywordId, String searchStr, int offset, int hitPerPage) throws IOException, ParseException{

        IndexSearcher searcher = getSearcher(clientId);
        File stopWords = new File(stopWordsFile);
        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT, stopWords);
        QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, &quot;contents&quot;, analyzer);
        Query query = qp.parse(searchStr);
        int limit = offset + hitPerPage;

        TopDocs topDocs = null;
        if(keywordId &gt; 0){
            Filter filter = NumericRangeFilter.newIntRange(&quot;keyword_id&quot;, keywordId, keywordId, true, true);
            topDocs = searcher.search(query, filter, limit);
        }else{
            topDocs = searcher.search(query, limit);
        }
        int lastIndex = limit &gt; topDocs.totalHits ? topDocs.totalHits : limit;
        int startIndex = offset;

        int[] searchedIds = new int[hitPerPage+1];
        searchedIds[0] = topDocs.totalHits;

        for (int i = startIndex; i &lt; lastIndex; i++) {
            Document doc = searcher.doc(topDocs.scoreDocs[i].doc);
            searchedIds[i] = Integer.parseInt(doc.get(&quot;id&quot;));
        }
        return searchedIds;
    }

    private IndexSearcher getSearcher(int clientId) throws IOException {
        Directory dir = FSDirectory.open(new File(indexDir(clientId)));
        IndexReader reader = IndexReader.open(dir, true);
        return new IndexSearcher(reader);
    }

    private String indexDir(int clientId){
        return &quot;/mnt/lucene/bmindex/&quot; + &quot;client_index_&quot; + new Integer(clientId).toString();
    }
}
</pre><br />
The next class is the web service which takes various search criterion.<br />
<pre class="brush: java;">
@WebService()
public class SearchIndex {

    @WebMethod(operationName = &quot;searchLucene&quot;)
    public int[] searchLucene(
                            @WebParam(name=&quot;clientId&quot;)int clientId,
                            @WebParam(name=&quot;keywordId&quot;)int keywordId,
                            @WebParam(name=&quot;searchStr&quot;)String searchStr,
                            @WebParam(name=&quot;startLimit&quot;)int startLimit,
                            @WebParam(name=&quot;hitPerPage&quot;)int hitPerPage) throws IOException, ParseException{

        SearchUtil su = new SearchUtil();
        int[] searchIds = su.search(clientId, keywordId, searchStr, startLimit, hitPerPage);

        return searchIds;
    }
}
</pre><br />
To enable the web service on Tomcat we have to map it as a Servlet in web.xml file.<br />
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;web-app xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
	 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	 xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot;
	 version=&quot;3.0&quot;&gt;

    &lt;listener&gt;
        &lt;listener-class&gt;com.sun.xml.ws.transport.http.servlet.WSServletContextListener&lt;/listener-class&gt;
    &lt;/listener&gt;

   &lt;servlet&gt;
        &lt;servlet-name&gt;jax-ws&lt;/servlet-name&gt;
        &lt;servlet-class&gt;com.sun.xml.ws.transport.http.servlet.WSServlet&lt;/servlet-class&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
        &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;jax-ws&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/SearchIndex&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;session-config&gt;
        &lt;session-timeout&gt;
            30
        &lt;/session-timeout&gt;
    &lt;/session-config&gt;
    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
        &lt;/welcome-file-list&gt;
&lt;/web-app&gt;
</pre><br />
There is one more configuration in Tomcat we have to do to make the web service working. Details of that can be found at <a href="http://puretech.paawak.com/2010/03/09/running-jax-ws-with-tomcat/" target="_blank">Running JAX-WS with Tomcat</a></p>
<br />Filed under: <a href='http://dyutiman.wordpress.com/category/tech/java/'>java</a>, <a href='http://dyutiman.wordpress.com/category/tech/'>tech</a> Tagged: <a href='http://dyutiman.wordpress.com/tag/lucene/'>lucene</a>, <a href='http://dyutiman.wordpress.com/tag/tomcat/'>tomcat</a>, <a href='http://dyutiman.wordpress.com/tag/web-service/'>web service</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dyutiman.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dyutiman.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dyutiman.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dyutiman.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dyutiman.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dyutiman.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dyutiman.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dyutiman.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dyutiman.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dyutiman.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dyutiman.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dyutiman.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dyutiman.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dyutiman.wordpress.com/185/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dyutiman.wordpress.com&amp;blog=7668585&amp;post=185&amp;subd=dyutiman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dyutiman.wordpress.com/2010/10/01/web-service-for-lucene-search-on-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59f02d533359c629986db3fa9d5d976?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dyutiman</media:title>
		</media:content>
	</item>
	</channel>
</rss>
