<?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>Naresh&#039;s Blog</title>
	<atom:link href="http://bsnaresh.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bsnaresh.wordpress.com</link>
	<description>past, present and future...</description>
	<lastBuildDate>Mon, 30 Nov 2009 13:13:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='bsnaresh.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/cd75cd976101e8fb84207a6ec0596075?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Naresh&#039;s Blog</title>
		<link>http://bsnaresh.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://bsnaresh.wordpress.com/osd.xml" title="Naresh&#039;s Blog" />
	<atom:link rel='hub' href='http://bsnaresh.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The Nov&#8217;09 Changes in My Life</title>
		<link>http://bsnaresh.wordpress.com/2009/11/30/the-nov09-changes-in-my-life/</link>
		<comments>http://bsnaresh.wordpress.com/2009/11/30/the-nov09-changes-in-my-life/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 13:01:02 +0000</pubDate>
		<dc:creator>bsnaresh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://bsnaresh.wordpress.com/?p=41</guid>
		<description><![CDATA[This November, I saw some major changes in my professional life. This is the month, I served my last working day at Sun Microsystems. I had to undergo a lot of mental struggle in deciding whether or not to leave this great organization. But considering my personal commitments and career ambitions I had to take [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=41&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This November, I saw some major changes in my professional life. This is the month, I served my <a href="http://blogs.sun.com/naresh/entry/my_last_day_sun">last working day</a> at <strong>Sun Microsystems</strong>. I had to undergo a lot of mental struggle in deciding whether or not to leave this great organization. But considering my personal commitments and career ambitions I had to take this tough decision.</p>
<p>I have joined a cloud computing startup, <strong><a href="http://www.sonoasystems.com/">Sonoa Systems</a></strong>. There&#8217;s a sudden understandable change in the work environment &#8211; from a company with 30000+ people to a company with less that 100 employees. <strong>It might be a small organization, but is one with a great vision</strong>.</p>
<p>I&#8217;m happy that the new job would let me put in practice all that I have learned throughout the past five years of my career, specially, the SOAP and REST web services that  I got a chance to work on when at Sun.</p>
<p>One great coincidence is that I have joined Sonoa on the 27th of Nov, the same day on which I joined my Engineering College nine years back. I hope the coming days would be as lovely and fruitful as my college days <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bsnaresh.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bsnaresh.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bsnaresh.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bsnaresh.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bsnaresh.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bsnaresh.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bsnaresh.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bsnaresh.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bsnaresh.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bsnaresh.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bsnaresh.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bsnaresh.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bsnaresh.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bsnaresh.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=41&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bsnaresh.wordpress.com/2009/11/30/the-nov09-changes-in-my-life/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f020f91ab495200ee6910b93cf363688?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bsnaresh</media:title>
		</media:content>
	</item>
		<item>
		<title>JTF: Running tests against an app deployed on a staging server</title>
		<link>http://bsnaresh.wordpress.com/2009/11/11/jtf-running-tests-against-an-app-deployed-on-a-staging-server/</link>
		<comments>http://bsnaresh.wordpress.com/2009/11/11/jtf-running-tests-against-an-app-deployed-on-a-staging-server/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 19:44:46 +0000</pubDate>
		<dc:creator>bsnaresh</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[jersey]]></category>

		<guid isPermaLink="false">http://bsnaresh.wordpress.com/?p=24</guid>
		<description><![CDATA[Few days back I saw somebody asking whether the Jersey Test Framework allows you to run your tests on an application which is deployed on a staging server. The answer was NO at that point of time. Then I realized that this is a common use case and that it would be good to add [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=24&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Few days back I saw somebody asking whether the Jersey Test Framework allows you to run your tests on an application which is deployed on a staging server. The answer was <strong>NO</strong> at that point of time. Then I realized that this is a common use case and that it would be good to add this support.</p>
<p>With this release of <a title="http://blogs.sun.com/sandoz/entry/jersey_1_1_4_is" href="http://blogs.sun.com/sandoz/entry/jersey_1_1_4_is">Jersey 1.1.4</a>, the Jersey Test Framework now lets you run your tests against your application deployed on a staging server. All that you have to do is just set this property <strong><em>JERSEY_HOST_NAME</em></strong> to the IP Address or the domain name of the machine, i.e., the staging server, on which your application is pre-deployed.</p>
<p>Lets say you have your application deployed on a machine with IP 129.132.212.54, tests could be run using the following command on your local machine:</p>
<pre> mvn clean test
<a href="http://com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory">-Dtest.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory</a> 
-DJERSEY_HOST_NAME=129.132.212.54 -DJERSEY_HTTP_PORT=&lt;http_port&gt;</pre>
<ul>
<li> The support for specifying the JERSEY_HOST_NAME is limited only to the external container types.</li>
<li>Apart from the JERSEY_HOST_NAME you would also need to set the JERSEY_HTTP_PORT to the port on which your server is listening.</li>
<li>For more information on the various container types supported by the framework, please refer the previous <a title="http://blogs.sun.com/naresh/entry/jersey_test_framework_re_visited" href="/naresh/entry/jersey_test_framework_re_visited">blog entry</a> on the framework.</li>
</ul>
<br /> Tagged: jersey, REST <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bsnaresh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bsnaresh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bsnaresh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bsnaresh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bsnaresh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bsnaresh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bsnaresh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bsnaresh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bsnaresh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bsnaresh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bsnaresh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bsnaresh.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bsnaresh.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bsnaresh.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=24&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bsnaresh.wordpress.com/2009/11/11/jtf-running-tests-against-an-app-deployed-on-a-staging-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f020f91ab495200ee6910b93cf363688?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bsnaresh</media:title>
		</media:content>
	</item>
		<item>
		<title>Hudson: A Continous Integration Tool</title>
		<link>http://bsnaresh.wordpress.com/2009/11/04/hudson-a-continous-integration-tool/</link>
		<comments>http://bsnaresh.wordpress.com/2009/11/04/hudson-a-continous-integration-tool/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 01:36:16 +0000</pubDate>
		<dc:creator>bsnaresh</dc:creator>
				<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://bsnaresh.wordpress.com/2009/11/04/hudson-a-continous-integration-tool/</guid>
		<description><![CDATA[Continuous Integration Tools &#160;&#160;&#160;&#160; A continuous integration tool is an automated build system that checks out the most current code from the source code repository, builds it, and makes the resulting artifacts available for download. Such tools come handy when your application has multiple modules and there are multiple engineers working on them. These tools [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=9&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Continuous Integration Tools</h3>
<p>&nbsp;&nbsp;&nbsp;&nbsp; A continuous integration tool is an automated build system that<br />
checks out the most current code from the source code repository,<br />
builds it, and makes the resulting artifacts available for download. Such tools come handy when your application has multiple modules and there are multiple engineers working on them. These tools could be used to integrate these various modules, build the system and also maybe run some tests to ensure that everything is fine. </p>
<h3>Hudson: What is it?</h3>
<p>&nbsp;&nbsp;&nbsp;&nbsp; Hudson is an open-source continous integration tool, which has become very popular for some time now. It provides various features like options for checking out the source code from various version controlling systems like CVS, SVN, etc., setting the version of Java to be used, the machine(s) on which to run the integrations/builds, notifying an user or a group of users about a build failure, scheduling the job execution, etc. More information can be obtained from the Hudson project site at <a href="http://hudson-ci.org/">http://hudson-ci.org/. </a></p>
<h3>Master-Slave Configuration</h3>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; One interesting feature of Hudson is its provision to run a job in a master-slave configuration, i.e., there would be a Hudson master machine which would take up all the requests like defining a job, configuring it, triggering it, etc., while there will be a set of slave machines on which the executions would actually happen.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Lets say you want to define a job which has to be run on more than one platform. You define it in the Hudson master, the interface for all your configurations, and then tie it to all the machines that you would want to run the job on. The underlying mechanism of Hudson takes care of all the communication between the Hudson master and each of the slaves which are registered with it.</p>
<p><a href="http://hudson-ci.org/"></a> &nbsp; &nbsp; &nbsp; &nbsp; Now, we will see how to setup Hudson &#8211; the master and slave(s).</p>
<h3>Setting up the Hudson Master</h3>
<p>&nbsp;&nbsp;&nbsp; The master could be setup on any OS, for convenience lets assume we are setting it up on Linux.</p>
<ul>
<li>If you are using Ubuntu, be sure to upgrade to 8.04 to avoid<br />
problems with RSA keys (keys generated by keygenerator in 7.10 are<br />
blacklisted!) </li>
<li> Login as someone with root role (e.g. uadmin)
</li>
<li> <code>sudo useradd -d /space/hudson -m hudson</code> &#8211; this creates user <i>hudson</i> with home in <i>/space/hudson</i> (Folder <i>hudson</i> does not need to exist)
</li>
<li> <code>sudo passwd hudson</code> changes the password for user <i>hudson</i> </li>
<li> Login as <i>hudson</i> user
</li>
<li> Create folder <i>$HOME/jdks</i> and install there jdk1.6.0
</li>
<li> <code>ssh-keygen -t rsa</code> generate public / private RSA key, public key is used for ssh login to slaves without passwords
</li>
<li> =touch /space/hudsonserver/master = &#8211; creates foo file <i>master</i> as a <b>workaround</b> for <a href="https://hudson.dev.java.net/issues/show_bug.cgi?id=936" target="_top">hudson issue #936</a>- parent project occuppies executor on slave
</li>
<li> Download <i>hudson.war</i> bits the Hudson site at <a href="http://hudson-ci.org/">http://hudson-ci.org/</a></li>
<li> Install webserver (e.g. tomcat) and deploy Hudson
</li>
<li> If you do not want to run Hudson in Tomcat, use built-in server Winstone:
<ul>
<li> run <code>java -jar hudson.war</code> to start Hudson master on port 8080
</li>
<li> NOTE: best idea is to use something like this script (we use in<br />
this script non-default port 18080 because this is second instance of<br />
Hudson on the same machine):
</li>
</ul>
</li>
</ul>
<pre>               #!/bin/bash
# kill running hudson
kill `ps aux|awk '$13 == "./hudson.war" {print $2}'` 2&gt; /dev/null
# nohup new hudson
nohup /space/jdks/jdk1.6.0_05/bin/java -jar ./hudson.war --httpPort=18080 --ajp13Port=18009 &amp;
</pre>
</p>
<ul>
<li>Once you have the war file deployed, you could launch the application.</li>
<li> Various settings like different JDKs, MAVEN_HOME could be made at the &quot;Manage Hudson&quot; page by clicking on the &quot;Manage Hudson&quot; link in the side pane.</li>
</ul>
<h3>Setting up the Hudson Slave</h3>
<p> The following steps could be used to create a slave on a linux/solaris machine:</p>
<ul>
<li> Create an user &quot;hudson&quot; with home in /space/hudson.
<ul>
<li> sudo useradd -d /space/hudson -m hudson
</li>
</ul>
</li>
<li> Set a password for this user
<ul>
<li> sudo passwd hudson
</li>
</ul>
</li>
<li> Login as user &quot;hudson&quot;.
</li>
<li> Create folders &quot;ant&quot; and &quot;jdks&quot; in /space/hudson.
</li>
<li> Download and unzip ant into folder &quot;ant&quot;.
</li>
<li> Download and unzip various versions of jdk into jdks.
</li>
<li> Copy the id_rsa.pub of the Hudson master to file<br />
/space/hudson/.ssh/authorized_keys. This enables the Hudson master to<br />
establish a remote connection to the slave without having to enter the<br />
login credentials. To do this:</p>
<ul>
<li> Setup a FTP connection to the Hudson master.
</li>
<li> Get the id_rsa.pub file from the hidden folder &quot;.ssh&quot;.
</li>
<li> Close the FTP connection.
</li>
<li> Copy this id_rsa.pub file to /space/hudson/.ssh/authorized_keys. Create the directory .ssh if it doesn&#8217;t exist already.
</li>
<li> To verify that the Hudson master&#8217;s key is successfully added to<br />
this slave&#8217;s &quot;ssh&quot; keys, try setting up a ssh connection from the<br />
Hudson master to this slave node, as &quot;ssh hudson@your_hudson_slave&quot;.<br />
This should setup a connection without prompting for a password.
</li>
</ul>
</li>
<li> Copy the slave agent &quot;slave.jar&quot; to /space/hudson. The jar file<br />
can be obtained from the archive &quot;hudson.war&quot; which has been downloaded<br />
to setup the Hudson master. The hudson.war file may be downloaded from<br />
the site http://hudson.dev.java.net.
</li>
<li> Write a small shell script which sets the various paths and starts<br />
the slave agent. Name it runSlave.sh. A typical script file would be<br />
like:</p>
<ul style="direction:ltr;">
<li> cat /space/hudson/runSlave.sh
</li>
<li>echo &quot;Starting the slave agent on the node XYZ&#8230;&quot;
</li>
<li>export JAVA_HOME=/space/hudson/jdks/jdk1.6.0_06
</li>
<li>export ANT_HOME=/space/hudson/ant/apache-ant-1.7.1
</li>
<li>export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH
</li>
<li>java -jar slave.jar
</li>
<li>echo &quot;Slave agent started&#8230;&quot;
<ul>
<li> This shell script would be called by the Hudson master. Running<br />
the script directly would not start the slave agent, this gets started<br />
only when run from the Hudson master. </li>
</ul>
</li>
</ul>
</li>
<li> Register this slave machine with the Hudson master in the &quot;Manage Hudson&quot; page.</li>
</ul>
<p>You have your Hudson Master/Slave configuration ready. Now, you could just go ahead and define, configure and schedule your jobs to run according to your choice.</p>
<p>&nbsp;In case you have any queries you could consider sending a mail to the Hudson user&#8217;s mailing list &#8211; <a href="mailto:users@hudson.dev.java.net">users@hudson.dev.java.net</a>&nbsp; which is a pretty active mailing list.</p>
<p></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bsnaresh.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bsnaresh.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bsnaresh.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bsnaresh.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bsnaresh.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bsnaresh.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bsnaresh.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bsnaresh.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bsnaresh.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bsnaresh.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bsnaresh.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bsnaresh.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bsnaresh.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bsnaresh.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=9&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bsnaresh.wordpress.com/2009/11/04/hudson-a-continous-integration-tool/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f020f91ab495200ee6910b93cf363688?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bsnaresh</media:title>
		</media:content>
	</item>
		<item>
		<title>Jersey Test Framework re-visited!</title>
		<link>http://bsnaresh.wordpress.com/2009/08/26/jersey-test-framework-re-visited/</link>
		<comments>http://bsnaresh.wordpress.com/2009/08/26/jersey-test-framework-re-visited/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 01:23:00 +0000</pubDate>
		<dc:creator>bsnaresh</dc:creator>
				<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://bsnaresh.wordpress.com/2009/08/26/jersey-test-framework-re-visited/</guid>
		<description><![CDATA[&#160;&#160; One of the previous entries introduced the Jersey Test Framework, which has since been adopted and used by a good number of developers. However, there has been some feedback suggesting ways for making the framework a better one. Based on all this feedback, we have worked on making some changes in the framework. With [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=10&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&nbsp;&nbsp; One of the previous entries introduced the <a href="/naresh/entry/jersey_test_framework_makes_it" title="http://blogs.sun.com/naresh/entry/jersey_test_framework_makes_it">Jersey Test Framework</a>, which has since been adopted and used by a good number of developers. However, there has been some feedback suggesting ways for making the framework a better one.</p>
<p>Based on all this feedback, we have worked on making some changes in the framework. With the release of Jersey 1.1.2-ea, we have this new version of the framework which is better than the previous version in the following ways:</p>
<ul>
<li>Introduced the concept of test container factories</li>
<li>Various test container types, defined by the different test container factory implementations</li>
<li>Support for the new In-Memory or In-Process test container</li>
<li>Loosely-coupled with the test container factory implementations</li>
<li>Loose coupling allows the definition and pluggability of custom test container factory implementations</li>
<li>Support for running tests on an application pre-deployed on an external container</li>
</ul>
<p>But, there have been some major changes in the API, which seemed obvious for the cause.</p>
<p>This entry will describe what are the API changes, and how an user test can be defined, etc.</p>
<p> <span style="background:#ffff00 none repeat scroll 0 0;">Breaking changes from 1.1.1-ea to<br />
1.1.2-ea</span></p>
<ul>
<li>The maven project groupId has changed from<br />
“com.sun.jersey.test.framework” to “com.sun.jersey”.&nbsp;</li>
</ul>
<div>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;dependency&gt;</pre>
</div>
<div>
<pre>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;</pre>
</div>
<div>
<pre>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;artifactId&gt;jersey-test-framework&lt;/artifactId&gt;&nbsp;</pre>
</div>
<div>
<pre> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;version&gt;1.1.2-ea&lt;/version&gt;</pre>
</div>
<div>
<pre>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &lt;dependency&gt;</pre>
</div>
<ul>
<li>The extending of Jersey unit test and configuration has changed.</li>
</ul>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The test class has to just pass an instance of <a href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/AppDescriptor.html" title="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/AppDescriptor.html">AppDescriptor</a>. For instance, the constructor of the <a href="http://download.java.net/maven/2/com/sun/jersey/samples/spring-annotations/1.1.2-ea/spring-annotations-1.1.2-ea-project.zip" title="http://download.java.net/maven/2/com/sun/jersey/samples/spring-annotations/1.1.2-ea/spring-annotations-1.1.2-ea-project.zip">spring-annotations</a> sample test, passes this information as follows:</p>
<pre> public SpringAnnotationsWebAppTest() throws Exception {
&nbsp;&nbsp; &nbsp;&nbsp; super(new WebAppDescriptor.Builder("com.sun.jersey.samples.springannotations.resources.jerseymanaged")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .contextPath("spring")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .contextParam("contextConfigLocation", "classpath:applicationContext.xml")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .servletClass(SpringServlet.class)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .contextListenerClass(ContextLoaderListener.class)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .build());
&nbsp;&nbsp;&nbsp; }
</pre>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;       Note the use of the Builder design pattern, which makes it really easy to define an instance of the AppDescriptor while defining all the application attributes.</p>
<ul>
<li>The test container type with which to run the tests has to be specified using the System Property <font face="courier new,courier,monospace">test.containerFactory</font>. Note that it used to be <font face="courier new,courier,monospace">container.type</font> till the previous version.</li>
<li>Unlike the previous implementation, the test container type value is not a string which maps to the container type, but the fully qualified class name of the test container factory is passed as value for the property <font face="courier new,courier,monospace">test.containerFactory</font>.</li>
<pre> &nbsp; mvn test -Dtest.containerFactory=com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory
</pre>
</ul>
<p><b>About the AppDescriptor</b> </p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AppDescriptor is an abstract class which is extended by two classes &#8211; the <a href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/LowLevelAppDescriptor.html" title="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/LowLevelAppDescriptor.html">LowLevelAppDescriptor</a> and the <a href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/WebAppDescriptor.html" title="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/WebAppDescriptor.html">WebAppDescriptor</a>. These classes allow the definition of the various attributes of the application &#8211; like its<br />
context-path, url-pattern, root resource classes or packages, etc. While the LowLevelAppDescriptor can be used is cases were tests are to be run on light-weight containers like Grizzly or HTTPServer, the WebAppDescriptor is used in cases where tests could be run on the web-based containers like EmbeddedGlassFish, Grizzly Web Container, and the light-weight containers as well*.</p>
</p>
<p><b>Test Container Factories</b></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The test framework comes with a set of test container factory implementations which are responsible for creating the test container(s). </p>
<p>
The following low-level test container factories are provided:
</p>
<ul>
<li><a title="class in com.sun.jersey.test.framework.spi.container.grizzly" href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/spi/container/grizzly/GrizzlyTestContainerFactory.html"><code>GrizzlyTestContainerFactory</code></a> for testing with the low-level<br />
Grizzly HTTP container.</li>
<li><a title="class in com.sun.jersey.test.framework.spi.container.http" href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/spi/container/http/HTTPContainerFactory.html"><code>HTTPContainerFactory</code></a> for testing with the Light Weight HTTP<br />
server distributed with Java SE 6.</li>
<li><a title="class in com.sun.jersey.test.framework.spi.container.inmemory" href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/spi/container/inmemory/InMemoryTestContainerFactory.html"><code>InMemoryTestContainerFactory</code></a> for testing in memory without<br />
using underlying HTTP client and server side functionality<br />
to send requests and receive responses.</li>
</ul>
<p>The following Web-based test container factories are provided:</p>
<ul>
<li><a title="class in com.sun.jersey.test.framework.spi.container.grizzly.web" href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/spi/container/grizzly/web/GrizzlyWebTestContainerFactory.html"><code>GrizzlyWebTestContainerFactory</code></a> for testing with the Grizzly<br />
Web container and Servlet support.</li>
<li><a title="class in com.sun.jersey.test.framework.spi.container.embedded.glassfish" href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/spi/container/embedded/glassfish/EmbeddedGlassFishTestContainerFactory.html"><code>EmbeddedGlassFishTestContainerFactory</code></a> for testing with<br />
embedded GlassFish.</li>
<li><a title="class in com.sun.jersey.test.framework.spi.container.external" href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/spi/container/external/ExternalTestContainerFactory.html"><code>ExternalTestContainerFactory</code></a> for testing when the Web<br />
application is independently deployed in a separate JVM to that of the<br />
tests. For example, the application may be deployed to the<br />
Glassfish v2 or v3 application server.</li>
</ul>
<p><b>Running Tests using Maven</b></p>
<p>&nbsp; &nbsp; &nbsp; As previously said, the container on which the tests have to be run is specified using the system property <font face="courier new,courier,monospace">test.containerFactory</font> which holds the fully-qualified classname of the test container factory which creates an instance of the test container, i.e.,</p>
<pre></pre>
<pre>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mvn clean test -Dtest.containerFactory=&lt;container-factory fully-qualified class name&gt;</pre>
<p>&nbsp; &nbsp; &nbsp; Note:</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1. If tests are to be run on external container like GlassFish, the application has to be explicity deployed on the container before running the tests.</p>
<p>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a. Package the application:</p>
<pre>&nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mvn clean package -Dmaven.test.skip=true</pre>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; b. Deploy the generated application war file&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; c. Run the tests:</p>
<pre>&nbsp;   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mvn test -Dtest.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory</pre>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2. If the &nbsp;tests are to be run on EmbeddedGlassFish, one additional property <font face="courier new,courier,monospace">container.type</font> has to be set along with <font face="courier new,courier,monospace">test.containerFactory</font>:</p>
</p>
<pre> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mvn clean test&nbsp;-Dtest.containerFactory=com.sun.jersey.test.framework.spi.container.embedded.glassfish.EmbeddedGlassFishTestContainerFactory -Dcontainer.type=EmbeddedGF&nbsp;
</pre>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3. If the property <font face="courier new,courier,monospace">test.containerFactory</font>&nbsp;is not set, the tests would be run on the Grizzly Web container by default.</p>
<pre></pre>
<p><b>Enable Logging </b></p>
<p><b> </b>The framework allows the logging of the HTTP requests and responses being sent over the wire during the test process. All that is needed to enable this logging is set the flag <font face="courier new,courier,monospace">enableLogging</font>.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mvn clean test -Dtest.containerFactory=&lt;test container factory class&gt; -DenableLogging</p>
</p>
<p><b>Programmatically setting the test container factory</b> </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The framework also allows setting the test container factory programmatically. This could be done by overriding the <a title="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/JerseyTest.html" href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/com/sun/jersey/test/framework/JerseyTest.html">JerseyTest</a> class&#8217;s <font face="courier new,courier,monospace">getTestContainerFactory</font> method and returning the appropriate test container factory&#8217;s instance. For example if Grizzly Web container has to be set as the default test container factory, it could be done as follows:</p>
<pre>&nbsp;&nbsp;&nbsp; @Override
&nbsp;&nbsp;&nbsp; protected TestContainerFactory getTestContainerFactory() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new GrizzlyWebTestContainerFactory();
&nbsp;&nbsp;&nbsp; }</pre>
</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; That&#8217;s a brief description of the new version of the <a title="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/index.html" href="https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey-test-framework/index.html">Jersey Test Framework</a>. Please send an email to the Jersey user&#8217;s mailing list <a href="mailto:users@jersey.dev.java.net">users@jersey.dev.java.net</a>&nbsp; in case you have any issues. Wish you a happy testing of your RESTful Web Services <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
<pre>

<b></b>
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bsnaresh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bsnaresh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bsnaresh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bsnaresh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bsnaresh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bsnaresh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bsnaresh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bsnaresh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bsnaresh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bsnaresh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bsnaresh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bsnaresh.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bsnaresh.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bsnaresh.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=10&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bsnaresh.wordpress.com/2009/08/26/jersey-test-framework-re-visited/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f020f91ab495200ee6910b93cf363688?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bsnaresh</media:title>
		</media:content>
	</item>
		<item>
		<title>Running the Jersey Webapp on Google App Engine</title>
		<link>http://bsnaresh.wordpress.com/2009/05/18/running-the-jersey-webapp-on-google-app-engine/</link>
		<comments>http://bsnaresh.wordpress.com/2009/05/18/running-the-jersey-webapp-on-google-app-engine/#comments</comments>
		<pubDate>Sun, 17 May 2009 21:07:44 +0000</pubDate>
		<dc:creator>bsnaresh</dc:creator>
				<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://bsnaresh.wordpress.com/2009/05/18/running-the-jersey-webapp-on-google-app-engine/</guid>
		<description><![CDATA[&#160; &#160; &#160;&#160; This entry describes how easy it is to get your Jersey web application running on Google App Engine. For the illustration purpose lets see how we can deploy the simple Helloworld-Webapp Jersey sample on the Google App Engine. Simple Steps: Download Google App Engine. Follow the installation instructions for installing the app [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=11&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; &nbsp;&nbsp; This entry describes how easy it is to get your <a href="http://jersey.dev.java.net/">Jersey</a> web application running on <a href="http://appengine.google.com/" title="http://appengine.google.com/">Google App Engine</a>.</p>
<p>For the illustration purpose lets see how we can deploy the simple <a href="http://download.java.net/maven/2/com/sun/jersey/samples/helloworld-webapp/1.1.0-ea/helloworld-webapp-1.1.0-ea-project.zip" title="http://download.java.net/maven/2/com/sun/jersey/samples/helloworld-webapp/1.1.0-ea/helloworld-webapp-1.1.0-ea-project.zip">Helloworld-Webapp</a> Jersey <a href="http://download.java.net/maven/2/com/sun/jersey/samples/jersey-samples/1.1.0-ea/jersey-samples-1.1.0-ea-project.zip" title="http://download.java.net/maven/2/com/sun/jersey/samples/jersey-samples/1.1.0-ea/jersey-samples-1.1.0-ea-project.zip">sample</a> on the Google App Engine. </p>
<h3>Simple Steps:</h3>
<ol>
<li><a href="http://googleappengine.googlecode.com/files/appengine-java-sdk-1.2.1.zip" title="http://googleappengine.googlecode.com/files/appengine-java-sdk-1.2.1.zip">Download</a> Google App Engine.</li>
<li>Follow the <a href="http://code.google.com/appengine/docs/java/gettingstarted/installing.html">installation</a> instructions for installing the app engine on your machine. It isn&#8217;t really too much work, just unzip the bundle, and add its <i>bin</i> directory to your path.</li>
<li>Download the Jersey helloworld-webapp sample, if you do not already have it.</li>
<li>Create an XML file named <i>appengine-web.xml</i>, under WEB-INF parallel to the deployment descriptor <i>web.xml</i>. Google App Engine requires this file in the webapp&#8217;s WEB-INF directory, for it to be able to run the application.</li>
<li>Copy the following content to the created <i>appengine-web.xml</i> file:
<pre>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;appengine-web-app xmlns="http://appengine.google.com/ns/1.0"&gt;
&lt;application&gt;&lt;/application&gt;
&lt;version&gt;1&lt;/version&gt;
&lt;/appengine-web-app&gt;
</pre>
</li>
<li>Package the application using: <i>mvn clean package -Dmaven.test.skip=true</i></li>
<li>Deploy the application on Google App Engine using the command: <i>dev_appserver.sh target/helloworld-webapp</i></li>
<li>You will see the message which says server is running at <i>http://localhost:8080/.</i></li>
<li>In a web browser enter <a href="http://localhost:8080/helloworld">http://localhost:8080/helloworld</a>. You see the application running.</li>
</ol>
<p>That&#8217;s it. You got the Jersey application running on Google App Engine <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p></p>
<p></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bsnaresh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bsnaresh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bsnaresh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bsnaresh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bsnaresh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bsnaresh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bsnaresh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bsnaresh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bsnaresh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bsnaresh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bsnaresh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bsnaresh.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bsnaresh.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bsnaresh.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=11&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bsnaresh.wordpress.com/2009/05/18/running-the-jersey-webapp-on-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f020f91ab495200ee6910b93cf363688?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bsnaresh</media:title>
		</media:content>
	</item>
		<item>
		<title>Jersey Test Framework makes it easy!</title>
		<link>http://bsnaresh.wordpress.com/2009/04/17/jersey-test-framework-makes-it-easy/</link>
		<comments>http://bsnaresh.wordpress.com/2009/04/17/jersey-test-framework-makes-it-easy/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 00:41:39 +0000</pubDate>
		<dc:creator>bsnaresh</dc:creator>
				<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://bsnaresh.wordpress.com/2009/04/17/jersey-test-framework-makes-it-easy/</guid>
		<description><![CDATA[&#160;&#160; Does your application have RESTful Web Services? Do you want to ensure that these services are working properly on a wide range of containers &#8211; both light weight and heavy weight ones? &#160; &#160;&#160; Have you ever felt the need of an infrastructure setup, which you can use to test your services against all [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=12&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&nbsp;&nbsp; Does your application have <a href="/naresh/entry/restful_web_services" title="http://blogs.sun.com/naresh/entry/restful_web_services">RESTful Web Services</a>? Do you want to ensure that these services are working properly on a wide range of containers &#8211; both light weight and heavy weight ones?</p>
<p>&nbsp; &nbsp;&nbsp; Have you ever felt the need of an infrastructure setup, which you can use to test your services against all these containers without having to worry about things like deployment descriptors, etc? If so, you have a news. <a href="http://jersey.dev.java.net/" title="http://jersey.dev.java.net/">Jersey</a> 1.0.3 got <a href="/sandoz/entry/jersey_1_0_3_is" title="http://blogs.sun.com/sandoz/entry/jersey_1_0_3_is">released</a> day before yesterday, and it comes with a testing framework called the <b>Jersey Test Framework</b>.&nbsp; </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; The Jersey Test Framework currently allows you to run your tests on any of the following three light weight containers:</p>
<ul>
<li><a href="https://embedded-glassfish.dev.java.net/" title="https://embedded-glassfish.dev.java.net/">Embedded GlassFish</a></li>
<li><a href="https://grizzly.dev.java.net/" title="https://grizzly.dev.java.net/">Grizzly Web Server</a></li>
<li>Lightweight HTTP Server</li>
</ul>
<p>The framework is built over JUnit 4.x using Maven.</p>
</p>
<h3>How do I use the Jersey Test Framework?</h3>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Using the framework is simple. All that you will need&nbsp; is do this:</p>
<ol>
<li>Add the following dependency to your pom.xml:</li>
<ul>
<li>&lt;dependency&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;com.sun.jersey.test.framework&lt;/groupId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;jersey-test-framework&lt;/artifactId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;1.0.3&lt;/version&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;scope&gt;test&lt;/scope&gt;<br />&nbsp;&lt;/dependency&gt;</li>
</ul>
<li>Create a class which extends <font face="courier new,courier,monospace">com.sun.jersey.test.framework.JerseyTest.</font></li>
<li><font face="courier new,courier,monospace"><font face="arial,helvetica,sans-serif">Some minimal number of parameters need to be passed by the test class to the <font face="courier new,courier,monospace">JerseyTest</font> class. This can be done in one of the following <font face="courier new,courier,monospace"><font face="arial,helvetica,sans-serif">ways</font>:</font></font></font></li>
<ul>
<li><font face="courier new,courier,monospace">super(String rootResourcePackage)<font face="arial,helvetica,sans-serif">: Pass the root resource package name to the <font face="courier new,courier,monospace">super</font> constructor. This constructor will then take care of initialising, starting and/or stopping the test container.</font></font></li>
<li><font face="courier new,courier,monospace">super(String contextPath, String servletPath, String resourcePackageName)<font face="arial,helvetica,sans-serif">: Pass the application context path, servlet path and root resource package name to the </font>super <font face="arial,helvetica,sans-serif">constructor if you are working on a web application. Again this constructor will take care of initializing, starting and/or stopping the test container.</font></font></li>
<li><font face="courier new,courier,monospace">super()<font face="arial,helvetica,sans-serif">: When you call the default no parameter</font> super <font face="arial,helvetica,sans-serif">constructor, you still can pass the information to the</font> JerseyTest <font face="arial,helvetica,sans-serif">class by creating an instance of the <font face="courier new,courier,monospace">com.sun.jersey.test.framework.util.ApplicationDescriptor</font> </font><font face="arial,helvetica,sans-serif">class, setting the parameters using the setter methods defined in that class. This has to be done in your test class&#8217;s constructor. Also, a call needs to be made to the</font> JerseyTest <font face="arial,helvetica,sans-serif">class&#8217;s</font> setupTestEnvironment(ApplicationDescriptor applicationDescriptor) <font face="arial,helvetica,sans-serif">method. This call would take care of the init, start and/stop of the test container.</font></font></li>
</ul>
<li><font face="courier new,courier,monospace"><font face="arial,helvetica,sans-serif">Annotate your test methods with the <font face="courier new,courier,monospace">org.junit.Test</font> annotation.</font></font></li>
<li>The handles to <font face="courier new,courier,monospace">com.sun.jersey.api.client.Client</font> and <font face="courier new,courier,monospace">com.sun.jersey.api.client.WebResource</font> instances &#8211; <font face="courier new,courier,monospace">client</font> and <font face="courier new,courier,monospace">webResource</font> get inherited from the <font face="courier new,courier,monospace">JerseyTest</font> class. You can use them in your test methods for building URIs and sending HTTP requests.</li>
<li><font face="courier new,courier,monospace"><font face="arial,helvetica,sans-serif">Run the tests using the maven command &#8211; <font face="courier new,courier,monospace">mvn clean test. <font face="arial,helvetica,sans-serif">This will by default run the tests against the Grizzly Web Server. If you want to run the tests on the container of your choice, set the system property <font face="courier new,courier,monospace">container.type</font> with one of the following values:</font></font></font></font></li>
<ul>
<li><font face="courier new,courier,monospace"><font face="arial,helvetica,sans-serif"><font face="courier new,courier,monospace">EmbeddedGF</font> : Makes the tests run against Embedded GlassFish.</font></font></li>
<li><font face="courier new,courier,monospace"><font face="arial,helvetica,sans-serif"><font face="courier new,courier,monospace">GrizzlyWeb</font> : Makes the tests run against the Grizzly Web container.</font></font></li>
<li><font face="courier new,courier,monospace"><font face="arial,helvetica,sans-serif"><font face="courier new,courier,monospace">HTTPServer</font> : Makes the tests run against the Simple HTTP Server.</font></font></li>
</ul>
<li>The framework also provides an option of seeing the HTTP requests and responses sent over the wire. It could be done by just setting the system property <font face="courier new,courier,monospace">enableLogging</font>, i.e., if you want to see the request and response sent over the wire, while running tests against Embedded GlassFish, execute the following command:</li>
<ul>
<li><font face="courier new,courier,monospace">mvn clean test -Dcontainer.type=EmbeddedGF -DenableLogging</font></li>
</ul>
<li>And that&#8217;s it. You have got the framework working.</li>
</ol>
<h3>Are there any samples which are using this framework?</h3>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Some of the <a title="http://download.java.net/maven/2/com/sun/jersey/samples/jersey-samples/1.0.3/jersey-samples-1.0.3-project.zip" href="http://download.java.net/maven/2/com/sun/jersey/samples/jersey-samples/1.0.3/jersey-samples-1.0.3-project.zip">samples</a> that come with the Jersey distribution have been modified to use this framework. These are:</p>
<ul>
<li><a title="http://download.java.net/maven/2/com/sun/jersey/samples/helloworld/1.0.3/helloworld-1.0.3-project.zip" href="http://download.java.net/maven/2/com/sun/jersey/samples/helloworld/1.0.3/helloworld-1.0.3-project.zip">helloworld</a></li>
<li><a title="http://download.java.net/maven/2/com/sun/jersey/samples/helloworld-webapp/1.0.3/helloworld-webapp-1.0.3-project.zip" href="http://download.java.net/maven/2/com/sun/jersey/samples/helloworld-webapp/1.0.3/helloworld-webapp-1.0.3-project.zip">helloworld-webapp</a></li>
<li><a title="http://download.java.net/maven/2/com/sun/jersey/samples/extended-wadl-webapp/1.0.3/extended-wadl-webapp-1.0.3-project.zip" href="http://download.java.net/maven/2/com/sun/jersey/samples/extended-wadl-webapp/1.0.3/extended-wadl-webapp-1.0.3-project.zip">extended-wadl-webapp</a></li>
<li><a title="http://download.java.net/maven/2/com/sun/jersey/samples/entity-provider/1.0.3/entity-provider-1.0.3-project.zip" href="http://download.java.net/maven/2/com/sun/jersey/samples/entity-provider/1.0.3/entity-provider-1.0.3-project.zip">entity-provider</a></li>
<li><a title="http://download.java.net/maven/2/com/sun/jersey/samples/simple-console/1.0.3/simple-console-1.0.3-project.zip" href="http://download.java.net/maven/2/com/sun/jersey/samples/simple-console/1.0.3/simple-console-1.0.3-project.zip">simple-console</a></li>
<li><a title="http://download.java.net/maven/2/com/sun/jersey/samples/jsonp/1.0.3/jsonp-1.0.3-project.zip" href="http://download.java.net/maven/2/com/sun/jersey/samples/jsonp/1.0.3/jsonp-1.0.3-project.zip">jsonp</a></li>
<li><a title="http://download.java.net/maven/2/com/sun/jersey/samples/jaxb/1.0.3/jaxb-1.0.3-project.zip" href="http://download.java.net/maven/2/com/sun/jersey/samples/jaxb/1.0.3/jaxb-1.0.3-project.zip">jaxb</a></li>
</ul>
<p>You should try running tests of these samples and see how the test framework works. I&#8217;m sure you will like it <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>If you see some of these samples do not have a deployment descriptor, but still you are able to run the tests against Embedded GlassFish. This is because the framework generates a deployment descriptor on the fly in such cases.</p>
<h3>Future Enhancements</h3>
<p>It is being planned to support the following features in the coming versions:</p>
<ol>
<li>Support for external containers &#8211; GlassFish v2 and GlassFish v3</li>
<li>Giving the user an option to specify the containers which his test doesn&#8217;t support.</li>
</ol>
<p>If you have any queries or see any issues with the current implementation or feel there should be something more, please send an email to the Jersey user mailing list &#8211; <a title="users@jersey.dev.java.net" href="mailto://users@jersey.dev.java.net">users@jersey.dev.java.net</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bsnaresh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bsnaresh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bsnaresh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bsnaresh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bsnaresh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bsnaresh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bsnaresh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bsnaresh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bsnaresh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bsnaresh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bsnaresh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bsnaresh.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bsnaresh.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bsnaresh.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=12&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bsnaresh.wordpress.com/2009/04/17/jersey-test-framework-makes-it-easy/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f020f91ab495200ee6910b93cf363688?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bsnaresh</media:title>
		</media:content>
	</item>
		<item>
		<title>Cool Firefox AddOn: Poster</title>
		<link>http://bsnaresh.wordpress.com/2009/03/14/cool-firefox-addon-poster/</link>
		<comments>http://bsnaresh.wordpress.com/2009/03/14/cool-firefox-addon-poster/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 20:01:49 +0000</pubDate>
		<dc:creator>bsnaresh</dc:creator>
				<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://bsnaresh.wordpress.com/2009/03/14/cool-firefox-addon-poster/</guid>
		<description><![CDATA[Here&#8217;s a cool utility for non-unix users, who have been looking for a curl like solution for sending HTTP requests with the various HTTP methods &#8211; GET, POST, PUT, DELETE, etc. It is the Firefox add-on Poster. Poster is a  developer tool for interacting with web services and other web resources that lets you make [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=13&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a cool utility for non-unix users, who have been looking for a <em>curl </em>like solution for sending HTTP requests with the various HTTP methods &#8211; <strong>GET</strong>, <strong>POST</strong>, <strong>PUT</strong>, <strong>DELETE</strong>, etc. It is the Firefox add-on <em><strong>Poster</strong></em>.</p>
<p>Poster is a  developer tool for interacting with web services and other web<br />
resources that lets you make HTTP requests, set the entity body, and<br />
content type. This allows you to interact with web services and inspect<br />
the results.</p>
<p>The add-on can be installed from <a href="https://addons.mozilla.org/en-US/firefox/addon/2691">https://addons.mozilla.org/en-US/firefox/addon/2691</a>.</p>
<p>Once the add-on is installed, you will be able to see an icon <strong>P</strong> in the Firefox browser status bar.</p>
<p>&nbsp;</p>
<p><img class="alignnone size-full wp-image-29" title="PosterIcon" src="http://bsnaresh.files.wordpress.com/2009/11/postericon.png?w=470" alt="PosterIcon"   /></p>
<p>Clicking this, would popup a Poster window, where  you can enter  the URL to which  you want to send the HTTP request,  set the HTTP method, set the  request headers, any query parameters, etc.</p>
<p><img class="alignnone size-full wp-image-30" title="PosterWindows" src="http://bsnaresh.files.wordpress.com/2009/11/posterwindows.png?w=470" alt="PosterWindows"   /></p>
<p>Also, you will be able to view  the response that is sent back.</p>
<p>This tool will be very useful at the time of development of <a href="/naresh/entry/restful_web_services">RESTful Web Services</a>.</p>
<p>Supported versions of Firefox: 1.5 &#8211; 3.0.*</p>
<p>In my opinion, this tool is even better that <em>curl</em>, thanks to the GUI. Moreover, it is pretty easy to learn and use, pretty much self-explanatory.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bsnaresh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bsnaresh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bsnaresh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bsnaresh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bsnaresh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bsnaresh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bsnaresh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bsnaresh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bsnaresh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bsnaresh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bsnaresh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bsnaresh.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bsnaresh.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bsnaresh.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=13&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bsnaresh.wordpress.com/2009/03/14/cool-firefox-addon-poster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f020f91ab495200ee6910b93cf363688?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bsnaresh</media:title>
		</media:content>

		<media:content url="http://bsnaresh.files.wordpress.com/2009/11/postericon.png" medium="image">
			<media:title type="html">PosterIcon</media:title>
		</media:content>

		<media:content url="http://bsnaresh.files.wordpress.com/2009/11/posterwindows.png" medium="image">
			<media:title type="html">PosterWindows</media:title>
		</media:content>
	</item>
		<item>
		<title>Jersey Client API in Action</title>
		<link>http://bsnaresh.wordpress.com/2009/03/02/jersey-client-api-in-action/</link>
		<comments>http://bsnaresh.wordpress.com/2009/03/02/jersey-client-api-in-action/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 02:24:58 +0000</pubDate>
		<dc:creator>bsnaresh</dc:creator>
				<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://bsnaresh.wordpress.com/2009/03/02/jersey-client-api-in-action/</guid>
		<description><![CDATA[In one of the previous entries we saw that Jersey provides a Client API for consuming RESTful Web Services. In this entry, we shall see how to use this API and consume the HelloWorld service. Before we go ahead and create the client, lets overwrite the HelloResource class with the following code: @Path("hello") public class [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=14&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In one of the previous <a title="Introduction to Jersey Client API" href="/naresh/entry/the_jersey_client_api">entries</a> we saw that Jersey provides a Client API for consuming <a title="Introduction to RESTful Web Services" href="/naresh/entry/restful_web_services">RESTful Web Services</a>. In this entry, we shall see how to use this API and consume the <a href="/naresh/entry/building_restful_web_services_using">HelloWorld</a> service.</p>
<p>Before we go ahead and create the client, lets overwrite the HelloResource class with the following code:</p>
<pre>@Path("hello")
public class HelloResource {
    /** Creates a new instance of HelloResource */
    public HelloResource() {
    }
    /**
     * Retrieves representation of an instance of
*  mycompany.resources.HelloResource
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    public String sayHello(@QueryParam ("name") String name) {
        if ( name != null ) {
            return "Hello " + name + "!";
        }
        return "Hello World!";
    }
    @GET
    @Path("{name}")
    @Produces("text/plain")
    public String sayHello2(@PathParam ("name") String name) {
        return "Hello " + name + "!";
    }
}</pre>
<div>
<p>Deploy the application, once this is done. As you see, what we have tried to do is to define two GET methods, one which reads the query parameter &#8220;name&#8221; and greets the user accordingly, while the other one reads &#8220;name&#8221; from the URI path segment and greets the user.</p>
<h4>Create the Client Application</h4>
<p>For the illustration purpose, let us create a simple console application, which uses the Jersey Client API to consume the service. Also, we will download the Jersey jar files and use them.</p>
<p>1. In the NetBeans IDE, create a new Java Application, by doing <em>File</em> <em>&gt; New Project &gt; Java &gt; Java Application</em>.</p>
<p>2. Name the Java Application as <strong><em>HelloWorldClient</em> </strong>and click the <em>Finish</em> button.</p>
<p>3. Download the required jar files &#8211; <em>jersey-client.jar, jersey-core.jar </em>and <em>jsr311-api.jar</em>,  from the links mentioned in the Jersey <a href="https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/jersey/dependencies.html">dependencies</a> page.</p>
<p>4. Add these jar files to the Project library, through <em>Project Properties &gt; Libraries &gt; Add JAR/Folder</em>.</p>
<blockquote></blockquote>
<p style="direction:ltr;"><img class="alignnone size-full wp-image-27" title="ClientAddJars" src="http://bsnaresh.files.wordpress.com/2009/11/clientaddjars.gif?w=470" alt="ClientAddJars"   /></p>
<blockquote></blockquote>
<p>5. Overwrite the main() method with the following code:</p>
<pre>public static void main(String[] args) {
        // Create Client and Handle to web resources
        String BASE_URI = "http://localhost:8080/HelloWorldWebapp/resources";
        Client client = Client.create();
        WebResource webResource = client.resource(BASE_URI);
        // send a GET request with Accept header set to "text/plain"
        String response = webResource.path("hello").accept(MediaType.TEXT_PLAIN).get(String.class);
        System.out.println(response);
        // send GET request with a query parameter value for 'name'
        response = webResource.path("hello").queryParam("name", "Pranabh").get(String.class);
        System.out.println(response);
        // send GET request to /hello without any query param
        response = webResource.path("hello").get(String.class);
        System.out.println(response);
        // send GET request to /hello/{name}
        response = webResource.path("hello").path("Ranjita").accept(MediaType.TEXT_PLAIN).get(String.class);
        System.out.println(response);
        // send a GET request and get the response encapsulate in ClientResponse
        ClientResponse clientResponse = webResource.path("hello").get(ClientResponse.class);
        System.out.println(clientResponse.getEntity(String.class));
 }</pre>
<p>6. The following import statements need to be added too:</p>
<pre>import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import javax.ws.rs.core.MediaType;
</pre>
<p>&nbsp;</p>
<p>7. Run the application and the following output is seen:</p>
<pre>Hello World!
Hello Pranabh!
Hello World!
Hello Ranjita!
Hello World!
</pre>
<h4>Lets Dig through the Code</h4>
<p>We created an instance of WebResource using the methods in Client class. Then GET requests were sent to the resources by appending the resource identifier to the web resource handle. Also, in some cases the HTTP Accept header was set using the <em>accept()</em> method. However, in some cases we did not use the accept header, since &#8220;text/plain&#8221; is the default type.</p>
<p>Observe the way query parameter <em>name</em> is set in the second GET request. It is set with the value <em>Pranabh</em>, and the response for this request is the string <em>Hello Pranabh!</em>. Similarly, in the fourth GET request, we have passed the value <em>Ranjita</em> for the path segment variable <em>name</em> .</p>
<p>In the last GET request, we have tried to encapsulate the response in an instance of <em>ClientResponse</em> class instead of <em>String.class</em> as in the previous requests. From this ClientResponse instance we got the response as a String entity.</p>
<p>All we saw was sending the GET requests, similarly we could send POST, PUT and DELETE methods using the methods <em>post( )</em>, <em>put( )</em> and <em>delete( )</em> respectively.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bsnaresh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bsnaresh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bsnaresh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bsnaresh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bsnaresh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bsnaresh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bsnaresh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bsnaresh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bsnaresh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bsnaresh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bsnaresh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bsnaresh.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bsnaresh.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bsnaresh.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=14&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bsnaresh.wordpress.com/2009/03/02/jersey-client-api-in-action/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f020f91ab495200ee6910b93cf363688?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bsnaresh</media:title>
		</media:content>

		<media:content url="http://bsnaresh.files.wordpress.com/2009/11/clientaddjars.gif" medium="image">
			<media:title type="html">ClientAddJars</media:title>
		</media:content>
	</item>
		<item>
		<title>Talk on REST at Sun Tech Days, Hyderabad, 2009</title>
		<link>http://bsnaresh.wordpress.com/2009/02/19/talk-on-rest-at-sun-tech-days-hyderabad-2009/</link>
		<comments>http://bsnaresh.wordpress.com/2009/02/19/talk-on-rest-at-sun-tech-days-hyderabad-2009/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 18:01:45 +0000</pubDate>
		<dc:creator>bsnaresh</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://bsnaresh.wordpress.com/2009/02/19/talk-on-rest-at-sun-tech-days-hyderabad-2009/</guid>
		<description><![CDATA[18th Feb 2009 will be one of the most memorable days in my life. It was the Day for which we have been eagerly waiting. It was the first day of Sun Tech Days@Hyderabad &#8211; 2009. &#160;&#160;&#160;&#160;&#160;&#160;&#160; We had a session on REST scheduled late in the evening. Sudhir and myself reached the venue, Hyderabad [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=15&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> <b>18th Feb 2009</b> will be one of the most memorable days in my life. It was <b>the Day</b> for which we have been eagerly waiting. It was the first day of <i><b>Sun Tech Days@Hyderabad &#8211; 2009</b></i>.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; We had a session on REST scheduled late in the evening. <a title="sudhir.prabhu@sun.com" href="mailto:sudhir.prabhu@sun.com">Sudhir</a> and myself reached the venue, Hyderabad International Convention Centre, better known as Novotel or Hitex, by 9:00 in the morning. The day began with keynote from <b>James Gosling</b> on hot technologies including <a href="/naresh/entry/restful_web_services">RESTful Web Services</a>. Then there were a couple of interesting sessions by <a href="/arungupta/entry/sun_tech_days_hyderabad_2009">Arun Gupta</a>  on <a href="http://metro.dev.java.net/">Metro</a> and <a href="http://glassfish.dev.java.net/">GlassFish</a>. And then at 6:00 in the evening, the session on REST, titled <i><b>Connecting the World with REST</b></i>, began.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Since this was the last session of the day, I was little bit worried, that not many delegates might turn around for the session, but there were a good number of them (somewhere around 600), who were there in the hall waiting for the session. This indeed showed <b>REST is getting popular</b> and that lot of people want to know about it. </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Everything was setup and we got started. The session began with an introduction to REST, <a href="/naresh/entry/restful_web_services">RESTful web services</a> and how <a href="http://jsr311.dev.java.net/">JAX-RS</a>&nbsp;/ <a href="http://jersey.dev.java.net/">Jersey</a> are related to them, followed by a small demo illustrating how to create simple RESTful web services using Jersey and <a href="http://netbeans.org/">NetBeans</a>. In the demo, we showed how to read path parameters and query paramters using the JAX-RS annotations <a href="/naresh/entry/making_the_uri_dynamic">@PathParam</a> and <a href="/naresh/entry/accessing_query_parameters_using_queryparam">@QueryParam</a>. Also, we showed how to represent data in multiple representations like XML, JSON, plain-text, etc. We wanted to show how to use the <a href="/naresh/entry/the_jersey_client_api">Jersey Client API</a> too, but could not show that because of time constraint.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Then it was the <b>Q&amp;A</b> time. There were a lot of people who have worked / are working on SOAP web services, and hence there were a lot of questions. Few of them that I can recall of are:</p>
<ol>
<li>I have a SOAP web service. I want to convert it to a REST service. Is there a tool which does that? There were many questions related to this.</li>
<li>How do I pass JSON data to my service?</li>
<li>How is a REST service different from CORBA?</li>
<li>How does Jersey produce data in XML / JSON representations from a JAXB annotated object?</li>
<li>When should I go for REST and when should I go for SOAP?</li>
<li>Is there a support for Security, Reliable-Messaging, etc?</li>
<li>About the WADL file?</li>
<li>If any tool were required for generating clients, as in SOAP?</li>
<li>Would it be possible to consume a SOAP web service using Jersey Client API?</li>
</ol>
<p>&nbsp;&nbsp; Also, there were many people who wanted to get started with Jersey, and wanted to know if there were some good references. I have pointed them to blogs, the Jersey project page and the main <a href="http://wikis.sun.com/display/Jersey/Main">wiki</a> page.</p></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bsnaresh.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bsnaresh.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bsnaresh.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bsnaresh.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bsnaresh.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bsnaresh.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bsnaresh.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bsnaresh.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bsnaresh.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bsnaresh.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bsnaresh.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bsnaresh.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bsnaresh.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bsnaresh.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=15&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bsnaresh.wordpress.com/2009/02/19/talk-on-rest-at-sun-tech-days-hyderabad-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f020f91ab495200ee6910b93cf363688?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bsnaresh</media:title>
		</media:content>
	</item>
		<item>
		<title>The Jersey Client API</title>
		<link>http://bsnaresh.wordpress.com/2009/02/16/the-jersey-client-api/</link>
		<comments>http://bsnaresh.wordpress.com/2009/02/16/the-jersey-client-api/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 20:38:48 +0000</pubDate>
		<dc:creator>bsnaresh</dc:creator>
				<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://bsnaresh.wordpress.com/2009/02/16/the-jersey-client-api/</guid>
		<description><![CDATA[&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; One of the distinguishing features of Jersey is its client API. The Jersey client API makes it really easy to consume the RESTful Web Services &#8211; send requests and get back response along with all the required entities. There are two variants of the API &#8211; one [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=16&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; One of the distinguishing features of <a href="http://jersey.dev.java.net/">Jersey</a> is its client API. The Jersey client API makes it really easy to consume the RESTful Web Services &#8211; send requests and get back response along with all the required entities. There are two variants of the API &#8211; one based on <a href="http://java.sun.com/javase/6/docs/api/java/net/HttpURLConnection.html" title="HttpURLConnection">HttpUrlConnection</a> and the other based on the <a href="http://hc.apache.org/httpclient-3.x/" title="Apache HTTP Client project page">Apache HTTP Client</a>. The API docs (for Jersey version 1.0.2, latest as of the day) are available at:</p>
<ul>
<li><a href="https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/jersey/com/sun/jersey/api/client/Client.html">https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/jersey/com/sun/jersey/api/client/Client.html</a></li>
<li><a href="https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/contribs/jersey-apache-client/index.html">https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/contribs/jersey-apache-client/index.html</a></li>
<p> The API provides methods for creating client, handles to resources, setting the header values, parameters and also methods corresponding to the four HTTP methods of GET, POST, PUT and DELETE.</p>
</ul>
<h4>Steps for consuming a service using the client API:</h4>
<ul>
<li>Get an instance of <b><i>Client</i></b> by either:
<ol>
<li><i><b>Client client = Client.create();</b></i> for the HttpURLConnection based client, or</li>
<li><b><i>ApacheHttpClient client = ApacheHttpClient.create();</i></b> for the ApacheHttpClient.</li>
</ol>
</li>
<li>Get a handle to the resources using the <i><b>resource(..)</b></i> method as &#8211; <b><i>WebResource webResource = client.resource(base_url_of_the_service);</i></b> The base_url could be given either as a String or as java.net.URI.</li>
<li>Set the relative path to the required resource using the <i>path()</i> method of the <i>WebResource</i> class</li>
<ul>
<li>Something like <i><b>webResource.path(path1).path(path2) </b></i>- &quot;path1&quot; and &quot;path2&quot; are the path elements. Say, I have my web service running at the base URI <i>http://myserver/base</i>, and the resource is identified by <i>http://myserver/base/resources/resource1</i>, then we could set the path to resource using the above as &#8211; <i>webResource.path(&quot;resources&quot;).path(&quot;resource1&quot;)</i></li>
<li><i><b>WebResource </b></i>follows the builder design pattern for appending path elements to the request URI.</li>
</ul>
<li>Methods mapping each of the four HTTP methods GET, POST, PUT and DELETE are provided. These are:</li>
<ul>
<li>GET ==&gt; <i><b>get()</b></i></li>
<li>POST ==&gt; <i><b>post()</b></i></li>
<li>PUT ==&gt; <i><b>put()</b></i></li>
<li>DELETE ==&gt; <i><b>delete()</b></i></li>
</ul>
<li>If you want to send a GET request to a resource<i><b>, </b></i>that can be done using this statement:</li>
<ul>
<li><i><b>webResource.path(path1).path(path2).get(Class)</b></i>, where Class is the type of the variable in which the response is to be set to. For example, if the response is to be set to a String variable, it could be done by using&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String reponse = webResource.path(path1).path(path2).get(String.class);</li>
<li>In general, the class is set to <i><b>Response.class</b></i> and the response is returned as an object of type <i><b>com.sun.jersey.api.client.ClientResponse</b></i>.</li>
</ul>
<li>If you want to send a request with the Accept Header set to some mime-type, that can be done using the <i><b>accept()</b></i> method of the <i><b>WebResource</b></i> class as shown in the following statement:</li>
<ul>
<li><i><b>webResource.path(path1).path(path2).accept(mime-type).get(Class)</b></i></li>
</ul>
<li>On the other hand if you want to send some data of some mime-type, it could be achieved using the <i><b>type() </b></i>method of the <i><b>WebResource </b></i>class as shown in the following statement:</li>
<ul>
<li><i><b>webResource.path(path1).path(path2).type(mime-type).post(Object);</b></i></li>
</ul>
<p>&nbsp;This gives a brief introduction to the Client API. In the next entry, we will use this API to send requests to the service(s) created in the previous entries which used <a href="/naresh/entry/making_the_uri_dynamic">PathParam</a> and <a href="/naresh/entry/accessing_query_parameters_using_queryparam">QueryParam</a>. </p>
</p>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bsnaresh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bsnaresh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bsnaresh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bsnaresh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bsnaresh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bsnaresh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bsnaresh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bsnaresh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bsnaresh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bsnaresh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bsnaresh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bsnaresh.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bsnaresh.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bsnaresh.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bsnaresh.wordpress.com&amp;blog=10433317&amp;post=16&amp;subd=bsnaresh&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bsnaresh.wordpress.com/2009/02/16/the-jersey-client-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f020f91ab495200ee6910b93cf363688?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bsnaresh</media:title>
		</media:content>
	</item>
	</channel>
</rss>
