<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Free practice test , mock test, driving test, interview questions &#187; REST</title>
	<atom:link href="http://www.skill-guru.com/blog/tag/rest/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.skill-guru.com/blog</link>
	<description>Find free mock and practice test, create and sell tests</description>
	<lastBuildDate>Mon, 16 Jan 2012 16:53:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>IE caching Ajax calls</title>
		<link>http://www.skill-guru.com/blog/2011/03/02/ie-caching-ajax-calls/</link>
		<comments>http://www.skill-guru.com/blog/2011/03/02/ie-caching-ajax-calls/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 02:02:21 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=3890</guid>
		<description><![CDATA[If you have been trying to make a REST call from your javascript or jsp page, you might have found that in firefox(FF) and Safari there is a call made to server every time . But this does not happen in IE.
This is the scenario I had
I had script file client.js which was making a [...]]]></description>
			<content:encoded><![CDATA[<p>If you have been trying to make a REST call from your javascript or jsp page, you might have found that in firefox(FF) and Safari there is a call made to server every time . But this does not happen in IE.</p>
<p>This is the scenario I had</p>
<p>I had script file client.js which was making a rest call to get some data.</p>
<p>First time I could see the results but then with every other subsequent call, there was no change in state, although the data should have changed.</p>
<p>Now this can be fixed by multiple ways</p>
<p><strong>Option 1: </strong></p>
<p>Change the browser settings. To  do this you have to go to</p>
<p>General&#8211;Settings&gt;</p>
<p>and change the settings from <strong>Automatically</strong> to <strong>Every Visit to page</strong></p>
<p>This will resolve the issue.</p>
<p><strong>Option 2:<br />
</strong></p>
<p>Change from GET to POST</p>
<p><strong>Option 3 :</strong></p>
<p>Add a timestamp at end of url which will looking at which server will think it is a new URL.</p>
<p><span id="more-3890"></span>I am planning to find some better solution but did not had any luck so far. Once I find anything, will update the post.</p>
<p>Update : Here is the solution using Servlet Filter  <a href="http://www.skill-guru.com/blog/2011/03/27/servlet-filter-to-prevent-no-cache/">Servlet Filter to prevent No Cache</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2011/03/02/ie-caching-ajax-calls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Invocation of REST service from Java Script</title>
		<link>http://www.skill-guru.com/blog/2011/01/29/invocation-rest-service-from-java-script/</link>
		<comments>http://www.skill-guru.com/blog/2011/01/29/invocation-rest-service-from-java-script/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 03:37:01 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=3694</guid>
		<description><![CDATA[We had shown an example to create your REST service in Java using JERSEY Creating your first REST service using Jersey. In this post we will explain how to invoke REST service through Java Script
&#60;html&#62;
&#60;head&#62;
&#60;script type=&#8221;text/javascript&#8221; charset=&#8221;utf-8&#8243; src=&#8221;json2.js&#8221;&#62;&#60;/script&#62;
&#60;script type=&#8221;text/javascript&#8221; charset=&#8221;utf-8&#8243; src=&#8221;jquery-1.4.4.min.js&#8221;&#62;&#60;/script&#62;
&#60;script&#62;
var restDataResults;
function callMyFirstRestService()
{
var myRestService = null;
if (window.XMLHttpRequest) //for mozilla
{
myRestService = new XMLHttpRequest();
if ( typeof myRestService.overrideMimeType [...]]]></description>
			<content:encoded><![CDATA[<p>We had shown an example to create your REST service in Java using JERSEY <a href="http://www.skill-guru.com/blog/2010/12/29/creating-your-firs-rest-service-with-jersey/">Creating your first REST service using Jersey</a>. In this post we will explain how to invoke REST service through Java Script</p>
<blockquote><p>&lt;html&gt;</p>
<p>&lt;head&gt;</p>
<p>&lt;script type=&#8221;text/javascript&#8221; charset=&#8221;utf-8&#8243; src=&#8221;json2.js&#8221;&gt;&lt;/script&gt;</p>
<p>&lt;script type=&#8221;text/javascript&#8221; charset=&#8221;utf-8&#8243; src=&#8221;jquery-1.4.4.min.js&#8221;&gt;&lt;/script&gt;</p>
<p>&lt;script&gt;</p>
<p>var restDataResults;</p>
<p>function callMyFirstRestService()</p>
<p>{</p>
<p>var myRestService = null;</p>
<p>if (window.XMLHttpRequest) //for mozilla</p>
<p>{</p>
<p>myRestService = new XMLHttpRequest();</p>
<p>if ( typeof myRestService.overrideMimeType != &#8216;undefined&#8217;)</p>
<p>myRestService.overrideMimeType(&#8216;application/json&#8217;);</p>
<p>}<span id="more-3694"></span></p>
<p>else if (window.ActiveXObject) //for IE</p>
<p>{</p>
<p>myRestService = new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);</p>
<p>}</p>
<p>//This is the url/ restApp is the web app deployed on tomcat.</p>
<p>var serviceUrl = &#8220;http://127.0.0.1:8080/restApp/webresources/paramater1/9991&#8243;;</p>
<p>myRestService.open(&#8220;GET&#8221;, serviceUrl, false);</p>
<p>//Create a callback    for myRestService</p>
<p>myRestService.onreadystatechange = function()</p>
<p>{</p>
<p>if (myRestService.readyState == 4)</p>
<p>{</p>
<p>if(myRestService.status == 200)</p>
<p>{</p>
<p>// Retrieve the json object and work on it</p>
<p>var obj = JSON.parse(myRestService.responseText);</p>
<p>for(var i=0;i&lt;obj.length;i++)</p>
<p>{</p>
<p>var item = obj[i];</p>
<p>$(&#8220;#restDataResults&#8221;).append(</p>
<p>&#8216;&lt;tr&gt;&lt;td&gt;&#8217;+ item.value1 + &#8216;&lt;/td&gt;&#8217; +</p>
<p>&#8216;&lt;td&gt;&#8217; + item.value2 + &#8216;&lt;/td&gt;&#8217; +</p>
<p>&#8216;&lt;/tr&gt;&#8217;);</p>
<p>}</p>
<p>}</p>
<p>else if(myRestService.status == 404)</p>
<p>{</p>
<p>alert(&#8216;Error occurred:&#8217; + myRestService.responseText);</p>
<p>}else{</p>
<p>alert(&#8220;No resposne&#8211;Error&#8221;);</p>
<p>}</p>
<p>}</p>
<p>};</p>
<p>tempresults = myRestService.send(null);</p>
<p>}</p>
<p>&lt;/script&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p>&lt;h2&gt;My First Rest Service&lt;/h2&gt;</p>
<p>&lt;p&gt;My rest Service:</p>
<p>&lt;input type=&#8221;button&#8221; id=&#8221;submitlookup&#8221; name=&#8221;submitlookup&#8221; value=&#8221;My First rest Service&#8221; onClick=&#8221;javascript:callMyFirstRestService();&#8221;/&gt;</p>
<p>&lt;/p&gt;</p>
<p>&lt;div id=&#8221;divRestData&#8221; title=&#8221;My rest data&#8221;&gt;</p>
<p>&lt;table border=&#8221;1&#8243;&gt;</p>
<p>&lt;thead&gt;&lt;tr&gt;</p>
<p>&lt;td width=&#8217;70&#8242;&gt;Column A Heading&lt;/td&gt;</p>
<p>&lt;td width=&#8217;100&#8242;&gt;Column B Heading&lt;/td&gt;</p>
<p>&lt;/tr&gt;&lt;/thead&gt;</p>
<p>&lt;tbody id=&#8217;restDataResults&#8217;&gt;</p>
<p>&lt;/tbody&gt;</p>
<p>&lt;/table&gt;</p>
<p>&lt;/div&gt;</p>
<p>&lt;/body&gt;</p>
<p>&lt;/html&gt;</p></blockquote>
<p>In this code , you can see different behavior for fire fox and IE.</p>
<blockquote><p><strong>var serviceUrl = &#8220;http://127.0.0.1:8080/restApp/webresources/paramater1/9991&#8243;;</strong></p></blockquote>
<p>This is the url of the web app deployed on tomcat. It expects a parameter1 string with some value . In this case we are hard coding it be 9991. Based on this value 9991,  some data would be returned</p>
<blockquote><p>myRestService.open(&#8220;GET&#8221;, serviceUrl, <strong>false</strong>);</p></blockquote>
<p>Here false means the call will be executed <strong>asynchronously. </strong>Now this is very important. It means your method would complete execution even before response is received.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2011/01/29/invocation-rest-service-from-java-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Synchronous calls with REST Service</title>
		<link>http://www.skill-guru.com/blog/2011/01/26/synchronous-calls-with-rest-service/</link>
		<comments>http://www.skill-guru.com/blog/2011/01/26/synchronous-calls-with-rest-service/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 19:02:54 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=3692</guid>
		<description><![CDATA[In last posts , we had shown the example Creating your first REST service using Jersey. Then we introduced to making the Rest call from JavaScript.
The example which we had shown was for asynchronous request. Now let us assume that you want to make an asynchronous call . How will it work out ?
Option A [...]]]></description>
			<content:encoded><![CDATA[<p>In last posts , we had shown the example <a href="http://www.skill-guru.com/blog/2010/12/29/creating-your-firs-rest-service-with-jersey/">Creating your first REST service using Jersey</a>. Then we introduced to making the Rest call from JavaScript.</p>
<p>The example which we had shown was for asynchronous request. Now let us assume that you want to make an asynchronous call . How will it work out ?</p>
<p><strong>Option A</strong> : Let the call be asynchronous and put a while loop at the end</p>
<blockquote><p>//Create a callback    for myRestService<br />
myRestService.onreadystatechange = function()<br />
{<br />
if (myRestService.readyState == 4)<br />
{<br />
if(myRestService.status == 200)<br />
{<br />
// Retrieve the json object and work on it</p>
<p>var obj = JSON.parse(myRestService.responseText);</p>
<p>for(var i=0;i&lt;obj.length;i++)<br />
{<br />
var item = obj[i];<br />
$(&#8220;#restDataResults&#8221;).append(<br />
&#8216;&lt;tr&gt;&lt;td&gt;&#8217;+ item.value1 + &#8216;&lt;/td&gt;&#8217; +<br />
&#8216;&lt;td&gt;&#8217; + item.value2 + &#8216;&lt;/td&gt;&#8217; +</p>
<p>&#8216;&lt;/tr&gt;&#8217;);<br />
}</p>
<p>done = true;<br />
}<br />
else if(myRestService.status == 404)<br />
{<br />
alert(&#8216;Error occurred:&#8217; + myRestService.responseText);<br />
}else{<br />
alert(&#8220;No resposne&#8211;Error&#8221;);<br />
}<br />
}<br />
};</p>
<p>tempresults = myRestService.send(null);<br />
while(done == false){</p>
<p>//wait here</p>
<p>}</p>
</blockquote>
<p>In this case you will see a warning pop up in Firefox</p>
<p><em>A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.<br />
</em></p>
<p><strong>Option B</strong> :  <strong>false </strong>changes to <strong>true </strong>and we make synchronous calls</p>
<p>myRestService.open(&#8220;GET&#8221;, serviceUrl, true);</p>
<p>Now this works out well in IE but FF does not accept it.</p>
<p>Why it does not work ? <strong>Because we are still using the callback mechanism to get back the results</strong></p>
<p>If we change it to regular method call , it will return results</p>
<p>Here is the code</p>
<blockquote><p>&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; charset=&#8221;utf-8&#8243; src=&#8221;json2.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; charset=&#8221;utf-8&#8243; src=&#8221;jquery-1.4.4.min.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script&gt;</p>
<p>var restDataResults;<br />
var done = false;</p>
<p>function callMyFirstRestService()<br />
{<br />
var myRestService = null;<br />
if (window.XMLHttpRequest) //for mozilla<br />
{<br />
myRestService = new XMLHttpRequest();</p>
<p>if ( typeof myRestService.overrideMimeType != &#8216;undefined&#8217;)<br />
myRestService.overrideMimeType(&#8216;application/json&#8217;);<br />
}<br />
else if (window.ActiveXObject) //for IE<br />
{<br />
myRestService = new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);<br />
}</p>
<p>//This is the url/ restApp is the web app deployed on tomcat.<br />
var serviceUrl = &#8220;http://127.0.0.1:8080/restApp/webresources/paramater/1440&#8243;;</p>
<p>myRestService.open(&#8220;GET&#8221;, serviceUrl, false);<br />
<span style="color: #800000;"><strong>//synchronous calls<br />
tempresults = myRestService.send();<br />
var obj = JSON.parse(myRestService.responseText);</strong></span></p>
<p>}</p>
<p>&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h2&gt;My First Rest Service&lt;/h2&gt;</p>
<p>&lt;p&gt;My rest Service:<br />
&lt;input type=&#8221;button&#8221; id=&#8221;submitlookup&#8221; name=&#8221;submitlookup&#8221; value=&#8221;My First rest Service&#8221; onClick=&#8221;javascript:callMyFirstRestService();&#8221;/&gt;<br />
&lt;/p&gt;</p>
<p>&lt;div id=&#8221;divRestData&#8221; title=&#8221;My rest data&#8221;&gt;<br />
&lt;table border=&#8221;1&#8243;&gt;<br />
&lt;thead&gt;&lt;tr&gt;<br />
&lt;td width=&#8217;70&#8242;&gt;Column A Heading&lt;/td&gt;<br />
&lt;td width=&#8217;100&#8242;&gt;Column B Heading&lt;/td&gt;<br />
&lt;/tr&gt;&lt;/thead&gt;<br />
&lt;tbody id=&#8217;restDataResults&#8217;&gt;<br />
&lt;/tbody&gt;<br />
&lt;/table&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
</blockquote>
<p>Hope you would have find this helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2011/01/26/synchronous-calls-with-rest-service/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XMLHttpRequest cross domain request issues on Firefox and Safari</title>
		<link>http://www.skill-guru.com/blog/2011/01/02/xmlhttprequest-cross-domain-request-issues-on-firefox-and-safari/</link>
		<comments>http://www.skill-guru.com/blog/2011/01/02/xmlhttprequest-cross-domain-request-issues-on-firefox-and-safari/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 14:29:02 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=3063</guid>
		<description><![CDATA[If you are running you web application on a domain http://mydomain.com and you want to invoke XMLHttpRequest on another domain for eg http://mydomain2.com , you would find different issues in IE, Firefox and Safari.
Code

if (window.XMLHttpRequest) //for mozilla
{
myService = new XMLHttpRequest();
if ( typeof cmdService.overrideMimeType != &#8216;undefined&#8217;)
myService.overrideMimeType(&#8216;application/json&#8217;);
}
else if (window.ActiveXObject) //for IE
{
myService= new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);
}
function callCmdService()
{
//Call the REST service&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>If you are running you web application on a domain http://mydomain.com and you want to invoke XMLHttpRequest on another domain for eg http://mydomain2.com , you would find different issues in IE, Firefox and Safari.</p>
<p><strong>Code<br />
</strong></p>
<p>if (window.XMLHttpRequest) //for mozilla<br />
{<br />
myService = new XMLHttpRequest();</p>
<p>if ( typeof cmdService.overrideMimeType != &#8216;undefined&#8217;)<br />
myService.overrideMimeType(&#8216;application/json&#8217;);<br />
}<br />
else if (window.ActiveXObject) //for IE<br />
{<br />
myService= new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);</p>
<p>}</p>
<p>function callCmdService()<br />
{<br />
//Call the REST service&#8217;s GET method asynchronously<br />
myService.open(&#8220;GET&#8221;, &#8220;http://mydomain2/restdata/1, true);</p>
<p>}</p>
<p><strong>What happens in IE ?</strong></p>
<p>In IE you might see an error message pop up , kind of a security warning. When you say yes, only then the connection is established with mydomain2.</p>
<p><strong>What happens in Firefox ?</strong></p>
<p>A security restriction within Firefox, the <a href="http://www.mozilla.org/projects/security/components/same-origin.html">&#8220;same origin policy&#8221;</a>, causes this error. Essentially, javascript within a page should only interact with the same host that served that page.</p>
<p>I could not find any reliable solution yet, but below are some helpful resources.</p>
<p><strong>Some helpful resources</strong></p>
<p>http://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html#Requesting_JSONC_Feeds</p>
<p>http://blog.monstuff.com/archives/000262.html</p>
<p>http://ejohn.org/blog/cross-site-xmlhttprequest/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2011/01/02/xmlhttprequest-cross-domain-request-issues-on-firefox-and-safari/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating your first REST service using Jersey</title>
		<link>http://www.skill-guru.com/blog/2010/12/29/creating-your-firs-rest-service-with-jersey/</link>
		<comments>http://www.skill-guru.com/blog/2010/12/29/creating-your-firs-rest-service-with-jersey/#comments</comments>
		<pubDate>Wed, 29 Dec 2010 12:50:38 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jersey]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2976</guid>
		<description><![CDATA[In the last post , we had talked about SOAP being retired in favor of REST based service. in which we discussed advantages of REST over SOAP.
This post will be a short tutorial on creating your first REST based service.
What is REST  and how are they accesses ?
From Sun(oracle) docs
RESTful web services are built to [...]]]></description>
			<content:encoded><![CDATA[<p>In the last post , we had talked about <a href="http://www.skill-guru.com/blog/2010/11/02/goodbye-soap-welcome-json-rest/">SOAP being retired in favor of REST based service</a>. in which we discussed advantages of REST over SOAP.</p>
<p>This post will be a short tutorial on creating your first REST based service.</p>
<h3>What is REST  and how are they accesses ?</h3>
<p>From Sun(oracle) docs</p>
<blockquote><p><strong>RESTful web services</strong> are built to work best on the Web.  Representational State Transfer (REST) is an architectural style that specifies constraints, such as the uniform interface, that if applied to a web service induce desirable properties, such as performance, scalability, and modifiability, that enable services to work best on the Web. In the REST architectural style, data and functionality are considered resources and are accessed using <strong>Uniform Resource Identifiers (URIs)</strong>, typically links on the Web. The resources are acted upon by using a set of simple, well-defined operations. The REST architectural style constrains an architecture to a client/server architecture and is designed to use a stateless communication protocol, typically HTTP. In the REST architecture style, clients and servers exchange representations of resources by using a standardized interface and protocol.</p></blockquote>
<p>Why use  JERSEY ?</p>
<p>Java defines standard REST support via JAX-RS (The Java API for 			RESTful Web Services) in 			<a href="http://jcp.org/aboutJava/communityprocess/final/jsr311/index.html" target="_top">JSR 311</a>. Jersey is the open source,                     production quality, <a href="http://jsr311.dev.java.net/nonav/releases/1.1/index.html">JAX-RS</a> (JSR 311) Reference Implementation for building RESTful Web services</p>
<p>Here is the objective of our tutorial</p>
<ul>
<li> Set up development environment and infrastructure to build first REST full app using JERSEY</li>
<li>Create the sample application</li>
<li>Deploy and run in tomcat<span id="more-2976"></span></li>
</ul>
<p>All right. Now let us get going.</p>
<h3>1. Set up development environment</h3>
<p>I have used maven to download files required to run the application. My IDE is Eclipse, server is tomcat 6.0.29</p>
<p>Add these dependencies to your pom.xml</p>
<blockquote><p>&lt;dependency&gt;<br />
&lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;<br />
&lt;artifactId&gt;jersey-json&lt;/artifactId&gt;<br />
&lt;version&gt;1.4&lt;/version&gt;<br />
&lt;/dependency&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;<br />
&lt;artifactId&gt;jersey-atom&lt;/artifactId&gt;<br />
&lt;version&gt;1.4&lt;/version&gt;<br />
&lt;/dependency&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;com.sun.jersey.contribs&lt;/groupId&gt;<br />
&lt;artifactId&gt;jersey-spring&lt;/artifactId&gt;<br />
&lt;version&gt;1.4&lt;/version&gt;<br />
&lt;/dependency&gt;<br />
&lt;dependency&gt;<br />
&lt;groupId&gt;com.sun.jersey.contribs&lt;/groupId&gt;<br />
&lt;artifactId&gt;jersey-apache-client&lt;/artifactId&gt;<br />
&lt;version&gt;1.4&lt;/version&gt;<br />
&lt;/dependency&gt;</p></blockquote>
<p>2. Here is the code</p>
<p>package com.skillguru.jersey;</p>
<p>import javax.ws.rs.GET;<br />
import javax.ws.rs.Path;<br />
import javax.ws.rs.Produces;<br />
import javax.ws.rs.core.MediaType;</p>
<p>@Path(&#8220;/hellojersey&#8221;)<br />
public class HelloJersey {</p>
<p>// for TEXT_PLAIN request<br />
@GET<br />
@Produces(MediaType.TEXT_PLAIN)<br />
public String sayPlainTextHello() {<br />
return &#8220;Hello Jersey text plain&#8221;;<br />
}</p>
<p>// for HTML request<br />
@GET<br />
@Produces(MediaType.TEXT_HTML)<br />
public String sayHtmlHello() {<br />
return &#8220;&lt;html&gt; &#8221; + &#8220;&lt;title&gt;&#8221; + &#8220;Hello Jersey html&#8221; + &#8220;&lt;/title&gt;&#8221;<br />
+ &#8220;&lt;body&gt;&lt;h1&gt;&#8221; + &#8220;Hello Jersey html&#8221; + &#8220;&lt;/body&gt;&lt;/h1&gt;&#8221; + &#8220;&lt;/html&gt; &#8220;;<br />
}</p>
<p>}</p>
<p>4.Chnage settings in your web .xml as</p>
<p>This is the code for web.xml</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;web-app xmlns=&#8221;http://java.sun.com/xml/ns/j2ee&#8221; xmlns:xsi=&#8221;http://www.w3.org/2001/XMLSchema-instance&#8221; version=&#8221;2.5&#8243; xsi:schemaLocation=&#8221;http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd&#8221;&gt;<br />
&lt;servlet&gt;<br />
&lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;<br />
&lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;<br />
&lt;init-param&gt;<br />
&lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;<br />
&lt;param-value&gt;<strong>com.skillguru.jersey</strong>&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;<br />
&lt;/servlet&gt;<br />
&lt;servlet-mapping&gt;<br />
&lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;<br />
&lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;<br />
&lt;/servlet-mapping&gt;<br />
&lt;/web-app&gt;</p>
<p>5.  Package and deploy in tomcat . Start the server .</p>
<p>Type in this in browser</p>
<p>http://localhost:8080/cmd/rest/hellojersey</p>
<p>You should see</p>
<h1>Hello Jersey in Html</h1>
<p>Tips :</p>
<p>Once you run your application , you might get this error<br />
<pre>com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.</pre><br />
Go to tomcat , into WEB-INF/classes and look out for the classes</p>
<p>The package inside which your HelloJersey class resides should be in the same durectory as specified in web.xml</p>
<p>i.e HelloJersey.class should reside in your com.skillguru.jersey package inside WEB-INF/classes</p>
<p>It should solve the problem.</p>
<p><em>Some other references </em></p>
<p>https://jersey.dev.java.net/nonav/documentation/latest/chapter_deps.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/12/29/creating-your-firs-rest-service-with-jersey/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Goodbye SOAP &#8211; Welcome JSON REST</title>
		<link>http://www.skill-guru.com/blog/2010/11/02/goodbye-soap-welcome-json-rest/</link>
		<comments>http://www.skill-guru.com/blog/2010/11/02/goodbye-soap-welcome-json-rest/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 01:51:55 +0000</pubDate>
		<dc:creator>Vinay</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[soap]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=2881</guid>
		<description><![CDATA[We look at the leader to give us the guidance.

Not sure if that is quote or not but when Google , Apple , facebook or some of the best companies take some step, it is time to take notice.

Google has killed their SOAP API. XML+SOAP was a good milestone in the history of integration but [...]]]></description>
			<content:encoded><![CDATA[<p><strong>We look at the leader to give us the guidance.</strong><em><br />
</em></p>
<p>Not sure if that is quote or not but when Google , Apple , facebook or some of the best companies take some step, it is time to take notice<em>.<br />
</em></p>
<p>Google has <a href="http://blogoscoped.com/archive/2009-03-03-n84.html">killed their SOAP API</a>. XML+SOAP was a good milestone in the history of integration but it is now time to look at the next milestone and that next milestone is JSON+REST</p>
<h3>What is REST ?</h3>
<p>Representational State Transfer (REST) is a software architectural style for distributed hypermedia systems like the world wide web.</p>
<p>The term originated in a 2000 doctoral dissertation Architectural Styles and the Design of Network- based Software Architectures about the web written by Roy Fielding, one of the principal authors of the HTTP protocol specification, and has quickly passed into widespread use in the networking community.</p>
<h3>What is SOAP ?</h3>
<p><strong>S</strong>imple <strong>O</strong>bject <strong>A</strong>ccess <strong>P</strong>rotocol . SOAP is an XML-based messaging protocol. It defines a set of rules for structuring messages that can be used for simple one-way messaging but is particularly useful for performing RPC-style (Remote Procedure Call) request-response dialogues. It is not tied to any particular transport protocol though HTTP is popular</p>
<p><strong>Why REST + JSON is a good choice over SOAP?<span id="more-2881"></span></strong></p>
<p>The deeper problem with SOAP is strong typing. WSDL accomplishes its magic via XML Schema and strongly typed messages. But strong typing is a bad choice for loosely coupled distributed systems. The moment you need to change anything, the type signature changes and all the clients that were built to your earlier protocol spec break.</p>
<p>The REST / HTTP+POX services typically assume that the clients will be flexible and can make sense of messages, even if they change a bit. And in practice this seems to work pretty well.  Twitter , yahoo web services , Flickr ,del.icio.us, technorati, all use use REST.</p>
<p>Some more differences<br />
1. JSON is a lot simpler than XML+XML Schema and is more isomorphic with the relational data stores most services use for persistence.</p>
<p>2. Browsers can consume large amount of JSON much more efficiently than they can consume large amount of XML and the gap is widening because the latest versions of the browsers are now providing native, safe support for encoding and decoding JSON.</p>
<p>3. REST provides improved response times and server loading characteristics due to support for <strong>caching.<br />
</strong></p>
<p>4. REST interfaces are much easier to design and implement than SOAP interfaces: verbs are already defined, exception semantics are already defined, caching semantics are already defined, versioning semantics are already defined, authentication and access control are already defined. All you really need to focus on are modeling resources using JSON, modeling URL hierarchies, modeling search patterns and modeling batching for performance improvements.</p>
<p>5. Does not require a separate resource discovery mechanism, due to the use of hyperlinks in content. An example of REST service would be http://www.skill-guru.com/getmyscore?userid=007</p>
<p>In a REST based architecture everything is a resource. A 			resource is 			accessed via a common interface based on the HTTP standard 			methods. 			Every resource should support the HTTP common 			operations. 			Resources are 			identified by global 			ID&#8217;s (which are typically 			URIs).</p>
<p>If you want to know about the history of REST, go through <a href="http://www.restlet.org/about/introduction">this</a></p>
<p>Other posts worth reading on REST</p>
<p>http://rest.blueoxen.net/cgi-bin/wiki.pl?WhatIsREST</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2010/11/02/goodbye-soap-welcome-json-rest/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Power of WCF</title>
		<link>http://www.skill-guru.com/blog/2009/08/19/power-of-wcf/</link>
		<comments>http://www.skill-guru.com/blog/2009/08/19/power-of-wcf/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 10:27:56 +0000</pubDate>
		<dc:creator>wali</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=424</guid>
		<description><![CDATA[WCF (Windows Communication Foundation) is Microsoft&#8217;s unified programming model for building service-oriented applications that communicate across the web and the enterprise. WCF clearly demarcates development and implementation. There are various Hosting options available and is independent of the run-time environment in which the service is deployed, they are:-

Self-Hosting in a Managed Application
Managed Windows Services
Internet Information Services (IIS)
Windows [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: justify;">WCF (Windows Communication Foundation) is Microsoft&#8217;s unified programming model for building service-oriented applications that communicate across the web and the enterprise. WCF clearly demarcates development and implementation. There are various Hosting options available and is independent of the run-time environment in which the service is deployed, they are:-</p>
<ul>
<li>Self-Hosting in a Managed Application</li>
<li>Managed Windows Services</li>
<li>Internet Information Services (IIS)</li>
<li>Windows Process Activation Service (WAS)</li>
</ul>
<p>All the development part lies in the code while the implementation like the binding can be handled in the config file as Microsoft has abstracted a lot of plumbing work reducing the implementation time. By this way developer can concentrate on core logic and WCF takes care of data delivery in the most reliable, secure and high performance fashion depending on situation.</p>
<p>WCF has an integrated Logging mechanism that helps you log traces. In other technologies developer has to write custom solution but in WCF, all that you need to do is to enable trace by changing the config file.</p>
<p>To achieve security mechanism in WCF you have 3 implementation choices:</p>
<ol>
<li><em>Transport</em>: Transport security depends on the mechanism that the binding you&#8217;ve selected uses.</li>
<li><em>Message</em>: Message security means that every message includes the necessary headers and data to keep the message secure.</li>
<li><em>TransportWithMessageCredential</em> : This choice uses the transport layer to secure the message transfer, while every message includes the rich credentials other services need.</li>
</ol>
<p>After the launch of modeling edition I feel it gets easy to delegate work in a team. An architect can create a Data Contracts/Relationships, Message Contracts and Service Contracts. After that only the facade layer has to be made with some tweaks here &#8216;n&#8217; there. In this way lot of architecture intricacies can be hidden from developer.</p>
<p>WCF does not replace MSMQ, COM+ or Web Services, it provides a declarative infrastructure for all forms of communication to and from the Windows platform. Using WCF, communications happen at designated service endpoints, and an endpoint can implement different protocols (such as Web Service, WS-* SOAP style services), encodings (such as Text, Binary &amp; MTOM), and transports (such as MSMQ, Http, etc.).</p>
<p>With .net 3.5, it becomes even easier to provide RESTful endpoints (JSON, POX, RSS and ATOM). So the real powerful leverage shall be building services that can be consumed by a ASP.net web client as JSON while simultaneously being accessed by a business partner through a php web client using the SOAP protocol (with its full complement of WS-* implementations such as WS-Security, WS-ReliableMessaging, etc.)</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2009/08/19/power-of-wcf/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

