<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CEMHQXc-eCp7ImA9WhRbEU8.&quot;"><id>tag:blogger.com,1999:blog-6059900666911337555</id><updated>2012-02-01T18:53:50.950Z</updated><category term="linux" /><category term="SBJSon" /><category term="postgresql" /><category term="java" /><category term="vmware" /><category term="development" /><category term="NSRunLoop" /><category term="glassfish" /><category term="fedora" /><category term="MacOS X" /><category term="Google" /><category term="pgworksheet" /><category term="oracle" /><category term="HTTP" /><category term="iPhone" /><category term="timer" /><category term="NSTimer" /><category term="python" /><category term="software" /><category term="web service" /><category term="sun java system application server" /><category term="Objective-C" /><category term="javaee" /><category term="jboss" /><category term="run loop" /><category term="Google books" /><category term="eclipse" /><category term="iOS" /><category term="j2ee" /><category term="JSON" /><category term="NSURLConnection" /><title>Software development, Operating Systems, ...</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://x-techteam.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://x-techteam.blogspot.com/" /><author><name>HM</name><uri>http://www.blogger.com/profile/15314161484458836048</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="31" src="http://4.bp.blogspot.com/-RCZ2mlbmVd0/TpgZlCf1LyI/AAAAAAAAAbo/CXeSJw4Tp64/s220/icon-software-development.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/SoftwareDevelopmentOperatingSystems" /><feedburner:info uri="softwaredevelopmentoperatingsystems" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CUIBRn45fip7ImA9WhdaEEw.&quot;"><id>tag:blogger.com,1999:blog-6059900666911337555.post-7712031522382021774</id><published>2011-10-19T09:38:00.001+01:00</published><updated>2011-10-19T09:39:17.026+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-19T09:39:17.026+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="NSURLConnection" /><category scheme="http://www.blogger.com/atom/ns#" term="SBJSon" /><category scheme="http://www.blogger.com/atom/ns#" term="JSON" /><category scheme="http://www.blogger.com/atom/ns#" term="HTTP" /><category scheme="http://www.blogger.com/atom/ns#" term="iPhone" /><category scheme="http://www.blogger.com/atom/ns#" term="development" /><category scheme="http://www.blogger.com/atom/ns#" term="Objective-C" /><category scheme="http://www.blogger.com/atom/ns#" term="MacOS X" /><category scheme="http://www.blogger.com/atom/ns#" term="web service" /><category scheme="http://www.blogger.com/atom/ns#" term="iOS" /><category scheme="http://www.blogger.com/atom/ns#" term="Google" /><category scheme="http://www.blogger.com/atom/ns#" term="Google books" /><title>Asynchronous web service client using NSURLConnection and SBJSON</title><content type="html">&lt;span class="Apple-style-span" style="color: #3d85c6; font-size: large;"&gt;The &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSURLConnection&lt;/span&gt; class&lt;/span&gt;&lt;br /&gt;
A &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSURLConnection&lt;/span&gt; object is used to perform the execution of a web service using HTTP.&lt;br /&gt;
When using&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSURLConnection&lt;/span&gt;, requests are made in asynchronous form. This mean that you don't wait the end of the request to continue, but you do something else until the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSURLConnection&lt;/span&gt; object tell you that some data arrived or the connection started, failed on ended.&lt;br /&gt;
When initializing the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSURLConnection&lt;/span&gt; object you have to pass the reference of a delegate. This is the object called by &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSURLConnection&lt;/span&gt; to inform your program about the status on the connection.&lt;br /&gt;
This delegate must have to implement the following methods &amp;nbsp;:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;connection:didReceiveResponse&lt;/span&gt; : called after the connection is made successfully and before receiving any data. Can be called more than one time in case of redirection.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt; connection:didReceiveData &lt;/span&gt;: called for each bloc of data.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;connectionDidFinishLoading&lt;/span&gt; : called only one time upon the completion of the request, if no error.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;connection:didFailWithError&lt;/span&gt; : called on error.&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #3d85c6; font-size: large;"&gt;The Google Books service&lt;/span&gt;&lt;br /&gt;
In this example, we will use the&lt;a href="http://code.google.com/intl/us-US/apis/books/"&gt; Google Book web service&lt;/a&gt;. We selected this service mainly for the easy of use and the&amp;nbsp;concise&amp;nbsp;results. We also selected this service because it use JSON to return the datas, and JSON is the best data interchange format for mobile devices like iPhone because it's lightweight and easy to parse.&lt;br /&gt;
A typical request to the search function of the Google Book web service is :&lt;br /&gt;
&lt;a href="https://www.googleapis.com/books/v1/volumes?q=biologie"&gt;https://www.googleapis.com/books/v1/volumes?q=biologie&lt;/a&gt;&lt;br /&gt;
where &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;searchterms&lt;/span&gt; are replaced by the searched keywords. You can see by clicking on the preceding link that the service return an array of &lt;i&gt;items&lt;/i&gt; consisting of books description.&lt;br /&gt;
We will extract the &lt;i&gt;volumeInfo/title&lt;/i&gt;, &lt;i&gt;volumeInfo/description,&lt;/i&gt;&amp;nbsp;&lt;i&gt;volumeInfo/imageLinks/smallThumbnail&lt;/i&gt; and &lt;i&gt;volumeInfo/previewLink&lt;/i&gt; in this example.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #3d85c6; font-size: large;"&gt;Integrating SBJSon&lt;/span&gt;&lt;br /&gt;
Unfortunately, neither the MacOS X nor the iOS SDK have some JSON parsing API, despite the fact that Apple use JSON intensively in their own applications.&lt;br /&gt;
There is several third party API that can easily be found on the Internet, and we selected &lt;a href="http://stig.github.com/json-framework/"&gt;SBJSon&lt;/a&gt; for this example.&lt;br /&gt;
You need to &lt;a href="https://github.com/stig/json-framework/downloads"&gt;download&lt;/a&gt; the latest &lt;a href="http://stig.github.com/json-framework/"&gt;SBJSon&lt;/a&gt; distribution, extract it somewhere and import it in your XCode project under a new group :&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-htZHPbL5iFI/Tp1ijodOPyI/AAAAAAAAAc0/g5_BRksB43o/s1600/Capture%2Bd%25E2%2580%2599%25C3%25A9cran%2B2011-10-18%2B%25C3%25A0%2B13.25.44.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="247" src="http://4.bp.blogspot.com/-htZHPbL5iFI/Tp1ijodOPyI/AAAAAAAAAc0/g5_BRksB43o/s320/Capture%2Bd%25E2%2580%2599%25C3%25A9cran%2B2011-10-18%2B%25C3%25A0%2B13.25.44.png" width="287" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #3d85c6; font-size: large;"&gt;Writing the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Book&lt;/span&gt; business class&lt;/span&gt;&lt;br /&gt;
The &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Book&lt;/span&gt; class represent a book with only the attributes we need in the example: a title, a description, a thumbnail image and a URL to the book page. A &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Book&lt;/span&gt; object will be initialized using a JSON string corresponding to a single &lt;i&gt;item&lt;/i&gt; from the Google Book web service.&lt;br /&gt;
This is the interface :&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="co1" style="color: #6e371a; font-style: normal;"&gt;#import &amp;lt;Foundation/Foundation.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@interface&lt;/span&gt;&amp;nbsp;Book&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSObject&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;title;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;desc;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; UIImage&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;smallThumbnail;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURL&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;url;&lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@property&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;nonatomic, copy&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;title;&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@property&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;nonatomic, copy&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;desc;&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@property&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;nonatomic, retain&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;UIImage&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;smallThumbnail;&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@property&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;nonatomic, retain&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURL&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;url;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="sy0" style="color: #002200;"&gt;-&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="kw4" style="color: #a61390;"&gt;id&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;initWithJSONDictionnary&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSDictionary&lt;/span&gt;&lt;/a&gt;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;json;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
and the implementation :&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="co1" style="color: #6e371a; font-style: normal;"&gt;#import "Book.h"&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@implementation&lt;/span&gt;&amp;nbsp;Book&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@synthesize&lt;/span&gt;&amp;nbsp;title, desc, smallThumbnail, url;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="sy0" style="color: #002200;"&gt;-&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="kw4" style="color: #a61390;"&gt;id&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;initWithJSONDictionnary&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSDictionary&lt;/span&gt;&lt;/a&gt;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;json&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; self&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;super init&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="kw1" style="color: #a61390;"&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;self&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSDictionary&lt;/span&gt;&lt;/a&gt;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&amp;nbsp;volumeInfo&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;json objectForKey&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="co3" style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span class="st0" style="color: #bf1d1a;"&gt;"volumeInfo"&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.title&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;volumeInfo objectForKey&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="co3" style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span class="st0" style="color: #bf1d1a;"&gt;"title"&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.desc&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;volumeInfo objectForKey&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="co3" style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span class="st0" style="color: #bf1d1a;"&gt;"description"&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;/a&gt;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&amp;nbsp;path&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;volumeInfo objectForKey&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="co3" style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span class="st0" style="color: #bf1d1a;"&gt;"imageLinks"&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&amp;nbsp;objectForKey&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="co3" style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span class="st0" style="color: #bf1d1a;"&gt;"smallThumbnail"&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; UIImage&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&amp;nbsp;image&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;UIImage alloc&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&amp;nbsp;initWithData&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSData&lt;/span&gt;&lt;/a&gt;&amp;nbsp;dataWithContentsOfURL&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURL&lt;/span&gt;&lt;/a&gt;&amp;nbsp;URLWithString&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;path&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.smallThumbnail&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;image;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;image release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.url&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURL&lt;/span&gt;&lt;/a&gt;&amp;nbsp;URLWithString&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;volumeInfo objectForKey&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="co3" style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span class="st0" style="color: #bf1d1a;"&gt;"previewLink"&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="kw1" style="color: #a61390;"&gt;return&lt;/span&gt;&amp;nbsp;self;&lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="sy0" style="color: #002200;"&gt;-&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="kw4" style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;dealloc&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;url release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;desc release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;title release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;smallThumbnail release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;super dealloc&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/product/1449388434/ref=as_li_tf_il?ie=UTF8&amp;amp;tag=vxp-20&amp;amp;linkCode=as2&amp;amp;camp=217145&amp;amp;creative=399369&amp;amp;creativeASIN=1449388434"&gt;&lt;img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&amp;amp;Format=_SL160_&amp;amp;ASIN=1449388434&amp;amp;MarketPlace=US&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;tag=vxp-20&amp;amp;ServiceVersion=20070822" /&gt;&lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=vxp-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1449388434&amp;amp;camp=217145&amp;amp;creative=399369" style="border: none !important; margin: 0px !important;" width="1" /&gt;&lt;br /&gt;
&lt;/center&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #3d85c6; font-size: large;"&gt;The &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;GoogleBookService&lt;/span&gt; class&lt;/span&gt;&lt;br /&gt;
This class implements the code to query the Google Books web service using HTTPS and translate the JSON resulting datas into &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Books&lt;/span&gt; business objects.&lt;br /&gt;
The resulting objects are stored in a &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSMutableArray&lt;/span&gt; collection of &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Books&lt;/span&gt;, and the search is started by the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;-performSearch&lt;/span&gt; function :&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="co1" style="color: #6e371a; font-style: normal;"&gt;#import &amp;lt;Foundation/Foundation.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@interface&lt;/span&gt;&amp;nbsp;GoogleBooksService&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSObject&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSMutableArray&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;books;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableData_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSMutableData&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;data;&lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@property&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;nonatomic, retain&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSMutableArray&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;books;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="sy0" style="color: #002200;"&gt;-&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="kw4" style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;performSearch&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;/a&gt;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;keyword;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw1" style="color: #a61390;"&gt;@end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;data&lt;/span&gt; instance variable will be used by the same callbacks to store the raw datas received from by the&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSURLConnection&lt;/span&gt; object.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #3d85c6; font-size: large;"&gt;Implementing the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;GoogleBookService&lt;/span&gt; class&lt;/span&gt;&lt;br /&gt;
The first thing is of course to write the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;-dealloc&lt;/span&gt; destructor :&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="sy0" style="color: #002200;"&gt;-&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="kw4" style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;dealloc&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;data release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;books release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;super dealloc&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;-performSearch&lt;/span&gt;&amp;nbsp;allocate the temporary data storage, build the URL using the keyword (note that you can build a better URL by encoding/escaping the keyword, not done here for clarity), build a &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSURLRequest&lt;/span&gt; object using the URL then execute the request using NSURLConnection :&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="sy0" style="color: #002200;"&gt;-&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="kw4" style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;performSearch&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;/a&gt;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;keyword&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; data&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableData_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSMutableData&lt;/span&gt;&lt;/a&gt;&amp;nbsp;alloc&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&amp;nbsp;init&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURL&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;url&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURL&lt;/span&gt;&lt;/a&gt;&amp;nbsp;URLWithString&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="br0" style="color: #002200;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;/a&gt;&amp;nbsp;stringWithFormat&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="co3" style="color: #bf1d1a;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;@&lt;/span&gt;&lt;span class="st0" style="color: #bf1d1a;"&gt;"https://www.googleapis.com/books/v1/volumes?q=%@"&lt;/span&gt;,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;keyword&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURLRequest&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;request&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURLRequest&lt;/span&gt;&lt;/a&gt;&amp;nbsp;requestWithURL&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;url&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURLConnection&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;connection&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURLConnection&lt;/span&gt;&lt;/a&gt;&amp;nbsp;alloc&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&amp;nbsp;initWithRequest&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;request&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; delegate&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;self&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="kw1" style="color: #a61390;"&gt;if&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="sy0" style="color: #002200;"&gt;!&lt;/span&gt;connection&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="co2" style="color: #11740a; font-style: italic;"&gt;// this is better if you @throw an exception&amp;nbsp;here&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NSLog&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="co3" style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span class="st0" style="color: #bf1d1a;"&gt;"error while starting the connection"&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;data release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The request to the web service will be executed in a background thread by the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;connection&lt;/span&gt; object. This thread will call the callback functions, in order :&lt;br /&gt;
-&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;connection:didReceiveResponse&lt;/span&gt;, after the connection object have received the response and HTTP headers from the remote web server :&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="sy0" style="color: #002200;"&gt;-&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="kw4" style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;connection&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURLConnection&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;connection didReceiveResponse&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLResponse_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURLResponse&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;response&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;data setLength&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="nu0" style="color: #2400d9;"&gt;0&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
-&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;connection:didReceiveData&lt;/span&gt;, for each block of raw data received :&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="sy0" style="color: #002200;"&gt;-&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="kw4" style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;connection&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURLConnection&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;connection didReceiveData&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSData&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;someData&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;data appendData&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;someData&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
-&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;connection:didFailWithError&lt;/span&gt;, in case of error :&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="sy0" style="color: #002200;"&gt;-&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="kw4" style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;connection&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURLConnection&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;connection didFailWithError&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSError&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;error&lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;connection release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;data release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
-&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;connectionDidFinishLoading&lt;/span&gt;, at the end of the request, if no error have happened. In this function we use SBJSon to translate the raw datas in &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Books&lt;/span&gt; objects :&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="sy0" style="color: #002200;"&gt;-&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;span class="kw4" style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;connectionDidFinishLoading&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSURLConnection&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;connection&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;connection release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;jsonString&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;/a&gt;&amp;nbsp;alloc&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&amp;nbsp;initWithData&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;data&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;encoding&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;NSUTF8StringEncoding&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;data release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #0000bb; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSArray&lt;/span&gt;&lt;/a&gt;&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&amp;nbsp;jsonItems&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;jsonString JSONValue&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&amp;nbsp;objectForKey&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;&lt;span class="co3" style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span class="st0" style="color: #bf1d1a;"&gt;"items"&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="kw4" style="color: #a61390;"&gt;id&lt;/span&gt;&amp;nbsp;item;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; books&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/" style="color: #000066;"&gt;&lt;span class="kw5" style="color: #400080;"&gt;NSMutableArray&lt;/span&gt;&lt;/a&gt;&amp;nbsp;alloc&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&amp;nbsp;init&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="kw1" style="color: #a61390;"&gt;for&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;(&lt;/span&gt;item&amp;nbsp;&lt;span class="kw1" style="color: #a61390;"&gt;in&lt;/span&gt;&amp;nbsp;jsonItems&lt;span class="br0" style="color: #002200;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Book&lt;span class="sy0" style="color: #002200;"&gt;*&lt;/span&gt;&amp;nbsp;book&amp;nbsp;&lt;span class="sy0" style="color: #002200;"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;Book alloc&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;&amp;nbsp;initWithJSONDictionnary&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;item&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;books addObject&lt;span class="sy0" style="color: #002200;"&gt;:&lt;/span&gt;book&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="br0" style="color: #002200;"&gt;[&lt;/span&gt;jsonString release&lt;span class="br0" style="color: #002200;"&gt;]&lt;/span&gt;;&lt;br /&gt;
&lt;span class="br0" style="color: #002200;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6059900666911337555-7712031522382021774?l=x-techteam.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8fZov021yUdxaq08FCOtDmTeCz4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8fZov021yUdxaq08FCOtDmTeCz4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8fZov021yUdxaq08FCOtDmTeCz4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8fZov021yUdxaq08FCOtDmTeCz4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareDevelopmentOperatingSystems/~4/xf0NlInLk3E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://x-techteam.blogspot.com/feeds/7712031522382021774/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6059900666911337555&amp;postID=7712031522382021774" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/7712031522382021774?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/7712031522382021774?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareDevelopmentOperatingSystems/~3/xf0NlInLk3E/asynchronous-web-service-client-using.html" title="Asynchronous web service client using NSURLConnection and SBJSON" /><author><name>HM</name><uri>http://www.blogger.com/profile/15314161484458836048</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="31" src="http://4.bp.blogspot.com/-RCZ2mlbmVd0/TpgZlCf1LyI/AAAAAAAAAbo/CXeSJw4Tp64/s220/icon-software-development.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-htZHPbL5iFI/Tp1ijodOPyI/AAAAAAAAAc0/g5_BRksB43o/s72-c/Capture%2Bd%25E2%2580%2599%25C3%25A9cran%2B2011-10-18%2B%25C3%25A0%2B13.25.44.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://x-techteam.blogspot.com/2011/10/asynchronous-web-service-client-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck4DRXY7fyp7ImA9WhdaEEw.&quot;"><id>tag:blogger.com,1999:blog-6059900666911337555.post-4838383633776419539</id><published>2011-10-14T11:46:00.007+01:00</published><updated>2011-10-19T08:56:14.807+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-19T08:56:14.807+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="run loop" /><category scheme="http://www.blogger.com/atom/ns#" term="NSRunLoop" /><category scheme="http://www.blogger.com/atom/ns#" term="NSTimer" /><category scheme="http://www.blogger.com/atom/ns#" term="iPhone" /><category scheme="http://www.blogger.com/atom/ns#" term="development" /><category scheme="http://www.blogger.com/atom/ns#" term="timer" /><category scheme="http://www.blogger.com/atom/ns#" term="Objective-C" /><category scheme="http://www.blogger.com/atom/ns#" term="MacOS X" /><category scheme="http://www.blogger.com/atom/ns#" term="iOS" /><title>How to schedule the execution of a function using NSTimer</title><content type="html">&lt;span class="Apple-style-span" style="color: #3d85c6; font-size: large;"&gt;The &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSTimer&lt;/span&gt; class&lt;/span&gt;&lt;br /&gt;
The &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSTimer&lt;/span&gt; class can be used to schedule the execution of a function in a program for MacOS X, iPhone / &amp;nbsp;iOs.&lt;br /&gt;
You can execute a function for any object, pass some user defined datas, and optionally you can repeat the scheduled execution automagically.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #3d85c6; font-size: large;"&gt;The target function&lt;/span&gt;&lt;br /&gt;
First, you have to write the target function.&lt;br /&gt;
This function must have a &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSTimer*&lt;/span&gt; parameter because you can use it with multiple timers.&lt;br /&gt;
In this exemple, the target function called &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;timerEnd&lt;/span&gt; stops the animation of a &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;UIActivityIndicatorView&lt;/span&gt;&amp;nbsp;called &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;indicator&lt;/span&gt; then posts a notification if the user have entered some text in a &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;UITextField&lt;/span&gt; named &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;textNom&lt;/span&gt; :&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;-(&lt;span style="color: blue;"&gt;void&lt;/span&gt;) timerEnd: (NSTimer *) theTimer { 
    [indicator stopAnimating]; 
    &lt;span style="color: blue;"&gt;if&lt;/span&gt; ([textNom.text length] &amp;gt; &lt;span style="color: maroon;"&gt;0&lt;/span&gt;) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@&lt;span style="color: maroon;"&gt;"My Notification"&lt;/span&gt;  
                                                            object:textNom.text]; 
    } 
    textNom.text = @&lt;span style="color: maroon;"&gt;""&lt;/span&gt;; 
} &lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #3d85c6; font-size: large;"&gt;Scheduling the timer&lt;/span&gt;&lt;br /&gt;
Once you have your target function ready, you can schedule the execution using the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;+NSTimer:scheduledTimerWithTimeInterval&lt;/span&gt; class function.&lt;br /&gt;
In the following example, the timer execute the&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt; [self timerEnd]&lt;/span&gt; message after 5 seconds :&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;[NSTimer scheduledTimerWithTimeInterval: &lt;span style="color: maroon;"&gt;5&lt;/span&gt;&lt;span style="color: maroon;"&gt;.0&lt;/span&gt;  
                                 target: self  
                               selector: @selector(timerEnd:)  
                               userInfo: nil  
                                repeats: NO];&lt;/pre&gt;&lt;br /&gt;
&lt;center&gt;&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/product/0321706242/ref=as_li_tf_il?ie=UTF8&amp;tag=vxp-20&amp;linkCode=as2&amp;camp=217145&amp;creative=399369&amp;creativeASIN=0321706242"&gt;&lt;img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&amp;Format=_SL160_&amp;ASIN=0321706242&amp;MarketPlace=US&amp;ID=AsinImage&amp;WS=1&amp;tag=vxp-20&amp;ServiceVersion=20070822" &gt;&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=vxp-20&amp;l=as2&amp;o=1&amp;a=0321706242&amp;camp=217145&amp;creative=399369" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;&lt;br /&gt;
&lt;/center&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #3d85c6; font-size: large;"&gt;Notes on &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSTimer&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Never forget that &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;NSTimer&lt;/span&gt; relies on the run loop. It means :&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;You must have a run loop. If you write a MacOS X console application, you must write it yourself. If you write a library or a Framework, you must document the fact that a run loop is mandatory.&lt;/li&gt;
&lt;li&gt;Run loops &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;retain&lt;/span&gt; timers. So you can &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;release&lt;/span&gt; your timers once scheduled.&lt;/li&gt;
&lt;li&gt;It's not real time. The run loop execute the timers once it have checked that the timer time have been passed. Hence in the preceding example the "after 5 seconds" and not "in 5 seconds".&lt;/li&gt;
&lt;li&gt;the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;+NSTimer:scheduleTimer*&lt;/span&gt; functions creates the timer and pushes it in the run loop. If you only want to create the timer use &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;+NSTimer:timerWithTimeInterval&lt;/span&gt; functions then use &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;-NSRunLoop:addTimer&lt;/span&gt; to push the timer (you can use &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;+NSRunLoop:currentRunLoop&lt;/span&gt; to get the current run loop).&lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6059900666911337555-4838383633776419539?l=x-techteam.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/dpFP5nEu2iF0gpFFLCjrlTBrcno/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dpFP5nEu2iF0gpFFLCjrlTBrcno/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/dpFP5nEu2iF0gpFFLCjrlTBrcno/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dpFP5nEu2iF0gpFFLCjrlTBrcno/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareDevelopmentOperatingSystems/~4/gODCUO9wNXY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://x-techteam.blogspot.com/feeds/4838383633776419539/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6059900666911337555&amp;postID=4838383633776419539" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/4838383633776419539?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/4838383633776419539?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareDevelopmentOperatingSystems/~3/gODCUO9wNXY/how-to-schedule-execution-of-function.html" title="How to schedule the execution of a function using NSTimer" /><author><name>HM</name><uri>http://www.blogger.com/profile/15314161484458836048</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="31" src="http://4.bp.blogspot.com/-RCZ2mlbmVd0/TpgZlCf1LyI/AAAAAAAAAbo/CXeSJw4Tp64/s220/icon-software-development.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://x-techteam.blogspot.com/2011/10/how-to-schedule-execution-of-function.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQARH0zcCp7ImA9WhdaEEw.&quot;"><id>tag:blogger.com,1999:blog-6059900666911337555.post-9017549572081001387</id><published>2008-03-05T09:36:00.018Z</published><updated>2011-10-19T08:45:45.388+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-19T08:45:45.388+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="development" /><category scheme="http://www.blogger.com/atom/ns#" term="javaee" /><category scheme="http://www.blogger.com/atom/ns#" term="j2ee" /><category scheme="http://www.blogger.com/atom/ns#" term="glassfish" /><category scheme="http://www.blogger.com/atom/ns#" term="sun java system application server" /><title>Glassfish login module : a simple example</title><content type="html">In this tutorial we will see how to write a very simple custom login module for the &lt;a href="https://glassfish.dev.java.net/"&gt;Glassfish&lt;/a&gt; application server.&lt;br /&gt;
Even if Glassfish ships with some useful login modules, there are not adapted to every situations, most notably with custom LDAP directories or strange authentication methods.&lt;br /&gt;
&lt;a href="http://docs.sun.com/app/docs/doc/819-3672/beabo?a=view"&gt;Chapter 5&lt;/a&gt; of the Glassfish developer documentation is a must read on this subject, and reading it is recommended before trying to write your own custom login module.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #663366;"&gt;&lt;span style="font-size: 130%;"&gt; Our custom authentication scheme &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
In this example we want to implement a very simple authentication method : a user is authenticated if is username start with a specific string. For example, if the string is "z", then the users &lt;span style="font-style: italic;"&gt;zed&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;zorro &lt;/span&gt;can login.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;A configurable login module&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
The login module must be fully configurable. The application server administrator can configure the string used in our authentication scheme.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;The custom realm&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;A custom login module in glassfish is composed by two classes :&lt;br /&gt;
- a &lt;span style="font-style: italic;"&gt;custom realm&lt;/span&gt;, which handle realm configuration&lt;br /&gt;
- a &lt;span style="font-style: italic;"&gt;custom login module&lt;/span&gt;, which handle authentication based on the informations given by the custom realm&lt;br /&gt;
A custom realm must extends &lt;span style="font-family: 'courier new';"&gt;AppservRealm&lt;/span&gt; :&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #000066; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;class&lt;/span&gt;&amp;nbsp;MyRealm&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;extends&lt;/span&gt;&amp;nbsp;AppservRealm&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;&amp;nbsp; private&lt;/span&gt;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html" style="color: #000066;"&gt;&lt;span class="kw21" style="color: #003399; font-weight: bold;"&gt;String&lt;/span&gt;&lt;/a&gt;&amp;nbsp;jaasCtxName&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;&amp;nbsp; private&lt;/span&gt;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html" style="color: #000066;"&gt;&lt;span class="kw21" style="color: #003399; font-weight: bold;"&gt;String&lt;/span&gt;&lt;/a&gt;&amp;nbsp;startWith&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
@&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Override.html" style="color: #000066;"&gt;&lt;span class="kw21" style="color: #003399; font-weight: bold;"&gt;Override&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;protected&lt;/span&gt;&amp;nbsp;&lt;span class="kw3" style="color: #006600; font-weight: bold;"&gt;void&lt;/span&gt;&amp;nbsp;init&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html" style="color: #000066;"&gt;&lt;span class="kw46" style="color: #003399; font-weight: bold;"&gt;Properties&lt;/span&gt;&lt;/a&gt;&amp;nbsp;props&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;throws&lt;/span&gt;&amp;nbsp;BadRealmException, NoSuchRealmException&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;{&lt;/span&gt;&amp;nbsp;_&lt;br /&gt;
&amp;nbsp; logger.&lt;span class="me1" style="color: #006633;"&gt;info&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="st0" style="color: blue;"&gt;"X-TECH MyRealm: init()"&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; jaasCtxName = props.&lt;span class="me1" style="color: #006633;"&gt;getProperty&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="st0" style="color: blue;"&gt;"jaas-context"&lt;/span&gt;,&amp;nbsp;&lt;span class="st0" style="color: blue;"&gt;"xtechMyRealm"&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; startWith = props.&lt;span class="me1" style="color: #006633;"&gt;getProperty&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="st0" style="color: blue;"&gt;"startWith"&lt;/span&gt;,&amp;nbsp;&lt;span class="st0" style="color: blue;"&gt;"z"&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0" style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
@&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Override.html" style="color: #000066;"&gt;&lt;span class="kw21" style="color: #003399; font-weight: bold;"&gt;Override&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html" style="color: #000066;"&gt;&lt;span class="kw21" style="color: #003399; font-weight: bold;"&gt;String&lt;/span&gt;&lt;/a&gt;&amp;nbsp;getJAASContext&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;{&lt;/span&gt;&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;return&lt;/span&gt;&amp;nbsp;jaasCtxName&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Enumeration.html" style="color: #000066;"&gt;&lt;span class="kw46" style="color: #003399; font-weight: bold;"&gt;Enumeration&lt;/span&gt;&lt;/a&gt;&amp;nbsp;getGroupNames&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html" style="color: #000066;"&gt;&lt;span class="kw21" style="color: #003399; font-weight: bold;"&gt;String&lt;/span&gt;&lt;/a&gt;&amp;nbsp;string&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;throws&lt;/span&gt;&amp;nbsp;InvalidOperationException, NoSuchUserException&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class="kw166" style="color: #003399; font-weight: bold;"&gt;&amp;nbsp;&amp;nbsp;&lt;a href="http://www.google.com/search?sitesearch=java.sun.com&amp;amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+List" style="color: #000066;"&gt;List&lt;/a&gt;&lt;/span&gt;&amp;nbsp;groupNames =&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedList.html" style="color: #000066;"&gt;&lt;span class="kw46" style="color: #003399; font-weight: bold;"&gt;LinkedList&lt;/span&gt;&lt;/a&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #000066; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;&amp;nbsp; return&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Enumeration.html" style="color: #000066;"&gt;&lt;span class="kw46" style="color: #003399; font-weight: bold;"&gt;Enumeration&lt;/span&gt;&lt;/a&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&amp;nbsp;groupNames&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0" style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html" style="color: #000066;"&gt;&lt;span class="kw21" style="color: #003399; font-weight: bold;"&gt;String&lt;/span&gt;&lt;/a&gt;&amp;nbsp;getAuthType&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;{&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #000066; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;&amp;nbsp; return&lt;/span&gt;&amp;nbsp;&lt;span class="st0" style="color: blue;"&gt;"X-TECH MyRealm"&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #000066; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="br0" style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #000066; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html" style="color: #000066;"&gt;&lt;span class="kw21" style="color: #003399; font-weight: bold;"&gt;String&lt;/span&gt;&lt;/a&gt;&amp;nbsp;getStartWith&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;{&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #000066; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;&amp;nbsp; return&lt;/span&gt;&amp;nbsp;startWith&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #000066; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="br0" style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="br0" style="color: #009900;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;The custom login module&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;A custom login must extends &lt;span style="font-family: 'courier new';"&gt;AppservPasswordLoginModule&lt;/span&gt; and override &lt;span style="font-family: 'courier new';"&gt;authenticateUser()&lt;/span&gt;:&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="background-color: #f0f0f0; color: #000066; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 14px; white-space: nowrap;"&gt;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;class&lt;/span&gt;&amp;nbsp;MyLoginModule&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;extends&lt;/span&gt;&amp;nbsp;AppservPasswordLoginModule&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;protected&lt;/span&gt;&amp;nbsp;&lt;span class="kw3" style="color: #006600; font-weight: bold;"&gt;void&lt;/span&gt;&amp;nbsp;authenticateUser&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;throws&lt;/span&gt;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/login/LoginException.html" style="color: #000066;"&gt;&lt;span class="kw93" style="color: #003399; font-weight: bold;"&gt;LoginException&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; _logger.&lt;span class="me1" style="color: #006633;"&gt;info&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="st0" style="color: blue;"&gt;"X-TECH MyLoginModule : authenticateUser for "&lt;/span&gt;&amp;nbsp;+ &lt;br /&gt;
&amp;nbsp; &amp;nbsp; _username&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; MyRealm realm =&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;MyRealm&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&amp;nbsp;_currentRealm&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw1" style="color: black; font-weight: bold;"&gt;&amp;nbsp; if&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;!&lt;/span&gt;_username.&lt;span class="me1" style="color: #006633;"&gt;startsWith&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;realm.&lt;span class="me1" style="color: #006633;"&gt;getStartWith&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; _logger.&lt;span class="me1" style="color: #006633;"&gt;info&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="st0" style="color: blue;"&gt;"Invalid credentials."&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;&amp;nbsp; &amp;nbsp; throw&lt;/span&gt;&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/login/LoginException.html" style="color: #000066;"&gt;&lt;span class="kw93" style="color: #003399; font-weight: bold;"&gt;LoginException&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="st0" style="color: blue;"&gt;"Invalid credentials."&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0" style="color: #009900;"&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; _logger.&lt;span class="me1" style="color: #006633;"&gt;info&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="st0" style="color: blue;"&gt;"User authenticated"&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="kw46" style="color: #003399; font-weight: bold;"&gt;&amp;nbsp;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Set.html" style="color: #000066;"&gt;Set&lt;/a&gt;&lt;/span&gt;&amp;nbsp;principals = _subject.&lt;span class="me1" style="color: #006633;"&gt;getPrincipals&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; principals.&lt;span class="me1" style="color: #006633;"&gt;add&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;new&lt;/span&gt;&amp;nbsp;PrincipalImpl&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;_username&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="kw21" style="color: #003399; font-weight: bold;"&gt;&amp;nbsp;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html" style="color: #000066;"&gt;String&lt;/a&gt;&lt;/span&gt;&amp;nbsp;grpList&lt;span class="br0" style="color: #009900;"&gt;[&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;]&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html" style="color: #000066;"&gt;&lt;span class="kw21" style="color: #003399; font-weight: bold;"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span class="br0" style="color: #009900;"&gt;[&lt;/span&gt;&lt;span class="nu0" style="color: #cc66cc;"&gt;1&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;]&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; grpList&lt;span class="br0" style="color: #009900;"&gt;[&lt;/span&gt;&lt;span class="nu0" style="color: #cc66cc;"&gt;0&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;]&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class="st0" style="color: blue;"&gt;"User"&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="kw2" style="color: black; font-weight: bold;"&gt;&amp;nbsp; this&lt;/span&gt;.&lt;span class="me1" style="color: #006633;"&gt;commitUserAuthentication&lt;/span&gt;&lt;span class="br0" style="color: #009900;"&gt;(&lt;/span&gt;grpList&lt;span class="br0" style="color: #009900;"&gt;)&lt;/span&gt;&lt;span class="sy0" style="color: #339933;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span class="br0" style="color: #009900;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="br0" style="color: #009900;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;center&gt; &lt;a href="http://www.amazon.com/gp/product/1849510369/ref=as_li_tf_il?ie=UTF8&amp;amp;tag=vxp-20&amp;amp;linkCode=as2&amp;amp;camp=217145&amp;amp;creative=399369&amp;amp;creativeASIN=1849510369"&gt;&lt;img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&amp;amp;Format=_SL160_&amp;amp;ASIN=1849510369&amp;amp;MarketPlace=US&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;tag=vxp-20&amp;amp;ServiceVersion=20070822" /&gt;&lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=vxp-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1849510369&amp;amp;camp=217145&amp;amp;creative=399369" style="border: none !important; margin: 0px !important;" width="1" /&gt;&lt;br /&gt;
&lt;/center&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt; Installing the custom login module&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;Installing and activating the customs realm and login module involve three steps :&lt;br /&gt;
- Configuring a realm using the glassfish administration console&lt;br /&gt;
- Linking the custom realm with the custom login module&lt;br /&gt;
- Make the classes avaible to glassfish&lt;br /&gt;
The first step is illustrated in the screenshot below :&lt;br /&gt;
&lt;a href="http://3.bp.blogspot.com/_WSFHFTDJ5iw/R85t3GlOc2I/AAAAAAAAACU/q2g1z18s0hQ/s1600-h/Capture-Sun+Java+System+Application+Server+9.1+Admin+Console+-+Mozilla+Firefox-1.png"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5174193815322260322" src="http://3.bp.blogspot.com/_WSFHFTDJ5iw/R85t3GlOc2I/AAAAAAAAACU/q2g1z18s0hQ/s320/Capture-Sun+Java+System+Application+Server+9.1+Admin+Console+-+Mozilla+Firefox-1.png" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /&gt;&lt;/a&gt;The second step is done by editing the &lt;span style="font-family: 'courier new';"&gt;login.conf&lt;/span&gt; file located in the &lt;span style="font-family: 'courier new';"&gt;config&lt;/span&gt; directory of the domain. Add a line like this one to the end of the &lt;span style="font-family: 'courier new';"&gt;login.conf &lt;/span&gt;file:&lt;br /&gt;
&lt;span style="font-family: 'courier new';"&gt;xtechMyRealm {&lt;/span&gt; &lt;span style="font-family: 'courier new';"&gt;    org.xtech.examples.gfloginmodule.MyLoginModule required;&lt;/span&gt; &lt;span style="font-family: 'courier new';"&gt;};&lt;/span&gt;&lt;br /&gt;
For the last step just copy the&lt;span style="font-family: 'courier new';"&gt; .jar&lt;/span&gt; file containing the customs realm and login module classes in the &lt;span style="font-family: 'courier new';"&gt;lib&lt;/span&gt; directory of glassfish (you must restart glassfish).&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;&lt;br /&gt;
Writing an example application&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;To try the new login module create a web application with only a index.jsp page. Put this line to display the authenticated user name :&lt;br /&gt;
&lt;span style="font-family: 'courier new';"&gt;Welcome ${pageContext.request.userPrincipal.name}&lt;/span&gt;&lt;br /&gt;
Add security to the web.xml file:&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/_WSFHFTDJ5iw/R85wjWlOc3I/AAAAAAAAACc/4qA3AotmHG8/s1600-h/Capture-GlassfishCustomLoginModuleTest+-+NetBeans+IDE+6.0.1.png"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5174196774554727282" src="http://4.bp.blogspot.com/_WSFHFTDJ5iw/R85wjWlOc3I/AAAAAAAAACc/4qA3AotmHG8/s320/Capture-GlassfishCustomLoginModuleTest+-+NetBeans+IDE+6.0.1.png" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;security-constraint&gt;&lt;security-role&gt;&lt;description&gt; &lt;/description&gt;&lt;br /&gt;
and link the web application security roles with the group name used in the custom login module by adding the folowing lines to the sun-web.xml file:&lt;br /&gt;
&lt;security-role-mapping&gt;&lt;/security-role-mapping&gt;&lt;/security-role&gt;&lt;/security-constraint&gt;&lt;a href="http://3.bp.blogspot.com/_WSFHFTDJ5iw/R85woGlOc4I/AAAAAAAAACk/lzzSmDLZccE/s1600-h/Capture-GlassfishCustomLoginModuleTest+-+NetBeans+IDE+6.0.1-1.png"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5174196856159105922" src="http://3.bp.blogspot.com/_WSFHFTDJ5iw/R85woGlOc4I/AAAAAAAAACk/lzzSmDLZccE/s320/Capture-GlassfishCustomLoginModuleTest+-+NetBeans+IDE+6.0.1-1.png" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /&gt;&lt;/a&gt;&lt;br /&gt;
Deploy your application and give it a try !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6059900666911337555-9017549572081001387?l=x-techteam.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_cxeEC4LAuQO_x0hjYPczxEs6dw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_cxeEC4LAuQO_x0hjYPczxEs6dw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_cxeEC4LAuQO_x0hjYPczxEs6dw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_cxeEC4LAuQO_x0hjYPczxEs6dw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareDevelopmentOperatingSystems/~4/G_h03hTEjCE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://x-techteam.blogspot.com/feeds/9017549572081001387/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6059900666911337555&amp;postID=9017549572081001387" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/9017549572081001387?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/9017549572081001387?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareDevelopmentOperatingSystems/~3/G_h03hTEjCE/glassfish-login-module-simple-example.html" title="Glassfish login module : a simple example" /><author><name>HM</name><uri>http://www.blogger.com/profile/15314161484458836048</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="31" src="http://4.bp.blogspot.com/-RCZ2mlbmVd0/TpgZlCf1LyI/AAAAAAAAAbo/CXeSJw4Tp64/s220/icon-software-development.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_WSFHFTDJ5iw/R85t3GlOc2I/AAAAAAAAACU/q2g1z18s0hQ/s72-c/Capture-Sun+Java+System+Application+Server+9.1+Admin+Console+-+Mozilla+Firefox-1.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://x-techteam.blogspot.com/2008/03/glassfish-login-module-simple-example.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0YFRns7eCp7ImA9WhdaEEw.&quot;"><id>tag:blogger.com,1999:blog-6059900666911337555.post-4109290906788307096</id><published>2007-04-03T14:23:00.003+01:00</published><updated>2011-10-19T08:58:37.500+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-19T08:58:37.500+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="development" /><category scheme="http://www.blogger.com/atom/ns#" term="javaee" /><category scheme="http://www.blogger.com/atom/ns#" term="j2ee" /><category scheme="http://www.blogger.com/atom/ns#" term="jboss" /><title>JBoss custom login module : a simple example</title><content type="html">In this tutorial we will see how to write a very simple custom login module for the JBoss application server.&lt;br /&gt;
Even if JBoss ships with some useful login modules, there are not adapted to every situations, most notably with custom LDAP directories or strange authentication methods.&lt;br /&gt;
&lt;a href="http://docs.jboss.org/jbossas/jboss4guide/r5/html/ch8.chapter.html"&gt;Chapter 8&lt;/a&gt; of the JBoss documentation is a must read on this subject, and reading it is recommended before trying to write your own custom login module.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #663366;"&gt;&lt;span style="font-size: 130%;"&gt; Our custom authentication scheme &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
In this example we want to implement a very stange authentication method :&lt;br /&gt;
- dynamic user login names in the form &lt;span style="font-style: italic;"&gt;userX&lt;/span&gt; where X is a decimal number&lt;br /&gt;
- dynamic administrators login names in the form &lt;span style="font-style: italic;"&gt;adminY&lt;/span&gt; where Y is what you want and is not very important&lt;br /&gt;
- a guest user name for anonymous connections&lt;br /&gt;
- dynamic user passphrase in the form &lt;span style="font-style: italic;"&gt;userX loves you&lt;/span&gt;&lt;br /&gt;
- dynamic administrator passphrase in the form &lt;span style="font-style: italic;"&gt;adminY is the boss&lt;/span&gt;&lt;br /&gt;
- empty password for the guest user&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;A configurable login module&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
The login module must be fully configurable.&lt;br /&gt;
We want :&lt;br /&gt;
- a regular expression to indentify guest users (optional, "anonymous" if not configured)&lt;br /&gt;
- a regular expression to indentify normal users&lt;br /&gt;
- a regular expression to indentify administrators&lt;br /&gt;
- a model for the users passphrases&lt;br /&gt;
- a model for the administrator passphrases&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;JBoss configuration&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Default JBoss login modules configuration file is &lt;tt&gt;${JBOSS_HOME}/server/default/conf/login-config.xml&lt;/tt&gt;.&lt;br /&gt;
Every JBoss login module must be given a JAAS security domain name. We will call our security domain "MyLoginModule".&lt;br /&gt;
Add the following to the configuration file just before the "other" security domain :&lt;br /&gt;
&lt;a href="http://3.bp.blogspot.com/_WSFHFTDJ5iw/RhJiM6yroEI/AAAAAAAAAAU/2XyFdhiJvy8/s1600-h/Capture-NetBeans+IDE+5.5.png"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5049206106315530306" src="http://3.bp.blogspot.com/_WSFHFTDJ5iw/RhJiM6yroEI/AAAAAAAAAAU/2XyFdhiJvy8/s400/Capture-NetBeans+IDE+5.5.png" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;tt&gt;com.blogger.xtechteam.examples.jboss.loginmodule.CustomJBossLoginModule&lt;/tt&gt;&lt;br /&gt;
is the name of our custom login module class.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;The custom login module&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Our custom login module is a class derived from &lt;tt&gt;org.jboss.security.auth.spi.UsernamePasswordLoginModule&lt;/tt&gt;.&lt;br /&gt;
By derivating UsernamePasswordLoginModule we only need to implements the following methods :&lt;br /&gt;
- &lt;tt&gt;initialize()&lt;/tt&gt; : called by JBoss after creating a new instance of our login module&lt;br /&gt;
- &lt;tt&gt;validatePassword()&lt;/tt&gt; : called by JBoss each time a user try to login&lt;br /&gt;
- &lt;tt&gt;getRoleSets()&lt;/tt&gt; : called by JBoss after a user have been successfully authenticated to get the list of roles for this user&lt;br /&gt;
This is the code of our login module :&lt;br /&gt;
&lt;tt style="font-size: small;"&gt;&lt;br /&gt;
public class CustomJBossLoginModule extends UsernamePasswordLoginModule {&lt;br /&gt;
&lt;br /&gt;
/* Regular expressions used for user login name */&lt;br /&gt;
private Pattern guestRegEx;&lt;br /&gt;
private Pattern userRegEx;&lt;br /&gt;
private Pattern adminRegEx;&lt;br /&gt;
/* Magic phrases used in place of user password */&lt;br /&gt;
private String userMagic;&lt;br /&gt;
private String adminMagic;&lt;br /&gt;
&lt;br /&gt;
/* Currently authenticated user roles */&lt;br /&gt;
private boolean isGuest;&lt;br /&gt;
private boolean hasUserRole;&lt;br /&gt;
private boolean hasAdminRole;&lt;br /&gt;
&lt;br /&gt;
/* called by JBoss when loading the login module */&lt;br /&gt;
@Override&lt;br /&gt;
public void initialize (&lt;br /&gt;
Subject subject,&lt;br /&gt;
CallbackHandler callbackHandler,&lt;br /&gt;
Map sharedState,&lt;br /&gt;
Map options) {&lt;br /&gt;
super.initialize (subject, callbackHandler, sharedState, options);&lt;br /&gt;
log.info ("CustomJBossLoginModule : initialize");&lt;br /&gt;
&lt;br /&gt;
/* load the optional login module option */&lt;br /&gt;
String guestParam = (String)options.get ("guestRegEx");&lt;br /&gt;
if (guestParam == null) {&lt;br /&gt;
guestParam = "anonymous";&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* load the mandatory login module options */&lt;br /&gt;
guestRegEx = Pattern.compile (guestParam);&lt;br /&gt;
userRegEx = Pattern.compile ((String)options.get ("userRegEx"));&lt;br /&gt;
adminRegEx = Pattern.compile ((String)options.get ("adminRegEx"));&lt;br /&gt;
userMagic = (String)options.get ("userMagic");&lt;br /&gt;
adminMagic = (String)options.get ("adminMagic");&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public CustomJBossLoginModule () {&lt;br /&gt;
super ();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/* called by JBoss to validate a user password */&lt;br /&gt;
@SuppressWarnings ("unchecked")&lt;br /&gt;
@Override&lt;br /&gt;
protected boolean validatePassword (String inputPassword, String expectedPassword) {&lt;br /&gt;
log.info ("CustomJBossLoginModule : validatePassword for " + getUsername ());&lt;br /&gt;
&lt;br /&gt;
/* validate the user name */&lt;br /&gt;
isGuest = guestRegEx.matcher (getUsername ()).matches ();&lt;br /&gt;
if (!isGuest) {&lt;br /&gt;
hasUserRole = userRegEx.matcher (getUsername ()).matches ();&lt;br /&gt;
if (!hasUserRole) {&lt;br /&gt;
hasAdminRole = adminRegEx.matcher (getUsername ()).matches ();&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* validate the password */&lt;br /&gt;
boolean validPassword = isGuest;&lt;br /&gt;
if (hasUserRole) {&lt;br /&gt;
validPassword = inputPassword.equals (&lt;br /&gt;
String.format (userMagic, getUsername ()));&lt;br /&gt;
} else if (hasAdminRole) {&lt;br /&gt;
validPassword = inputPassword.equals (&lt;br /&gt;
String.format (adminMagic, getUsername ()));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* save some informations for the application */&lt;br /&gt;
if (validPassword) {&lt;br /&gt;
Set&lt;principal&gt; principals = subject.getPrincipals ();&lt;br /&gt;
principals.add (new SimplePrincipal (getUsername ()));&lt;br /&gt;
principals.add (new SimplePrincipal (inputPassword));&lt;br /&gt;
principals.add (new SimplePrincipal ("Hello from CustomJBossLoginModule"));&lt;br /&gt;
principals.add (new SimplePrincipal (Boolean.toString (isGuest)));&lt;br /&gt;
principals.add (new SimplePrincipal (Boolean.toString (hasUserRole)));&lt;br /&gt;
principals.add (new SimplePrincipal (Boolean.toString (hasAdminRole)));&lt;br /&gt;
log.info (String.format ("CustomJBossLoginModule : user %s authenticated (guest : %b, user : %b, admin : %b)",&lt;br /&gt;
getUsername (), isGuest, hasUserRole, hasAdminRole));&lt;br /&gt;
} else {&lt;br /&gt;
log.info ("CustomJBossLoginModule : Invalid credentials");&lt;br /&gt;
}&lt;br /&gt;
return validPassword;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
@Override&lt;br /&gt;
protected String getUsersPassword () throws LoginException {&lt;br /&gt;
return "";&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* fill the role collection */&lt;br /&gt;
@Override&lt;br /&gt;
protected Group[] getRoleSets () throws LoginException {&lt;br /&gt;
SimpleGroup userRoles = new SimpleGroup ("Roles");&lt;br /&gt;
if (isGuest)  {&lt;br /&gt;
userRoles.addMember (new SimplePrincipal ("Guest"));&lt;br /&gt;
}&lt;br /&gt;
if (hasUserRole) {&lt;br /&gt;
userRoles.addMember (new SimplePrincipal ("User"));&lt;br /&gt;
}&lt;br /&gt;
if (hasAdminRole) {&lt;br /&gt;
userRoles.addMember (new SimplePrincipal ("Admin"));&lt;br /&gt;
}&lt;br /&gt;
Group[] roleSets = { userRoles };&lt;br /&gt;
return roleSets;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;/principal&gt;&lt;/tt&gt;&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;Compilation&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
To compile this login module you need two .jar files from JBoss : &lt;tt&gt;jboss-common.jar&lt;/tt&gt; and &lt;tt&gt;jbosssx.jar.&lt;/tt&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;Deployment&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Put the login module class in a .jar file and copy this archive to &lt;tt&gt;${JBOSS_HOME}/server/default/lib&lt;/tt&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;Getting informations about the user from the application&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
You (normally) have noticed that our login module save some informations in the collection of principals for the subject (the authenticated user).&lt;br /&gt;
This is needed to have this informations from our web applications or from our EJBs in a application-server independant way.&lt;br /&gt;
This is an example of a class that can be used to get this informations :&lt;br /&gt;
&lt;tt style="font-size: small;"&gt;&lt;br /&gt;
public class AuthenticatedUserInformations  {&lt;br /&gt;
&lt;br /&gt;
public class InvalidUserException extends Exception {};&lt;br /&gt;
&lt;br /&gt;
/** The JACC PolicyContext key for the current Subject */&lt;br /&gt;
private static final String SUBJECT_CONTEXT_KEY =&lt;br /&gt;
"javax.security.auth.Subject.container";&lt;br /&gt;
&lt;br /&gt;
private String username;&lt;br /&gt;
private String password;&lt;br /&gt;
private String hello;&lt;br /&gt;
private boolean isGuest;&lt;br /&gt;
private boolean isAdmin;&lt;br /&gt;
private boolean isUser;&lt;br /&gt;
&lt;br /&gt;
public AuthenticatedUserInformations () throws InvalidUserException {&lt;br /&gt;
Subject caller;&lt;br /&gt;
try {&lt;br /&gt;
caller = (Subject) PolicyContext.getContext (SUBJECT_CONTEXT_KEY);&lt;br /&gt;
if (caller == null) {&lt;br /&gt;
throw new InvalidUserException ();&lt;br /&gt;
}&lt;br /&gt;
Iterator&lt;principal&gt; it = caller.getPrincipals ().iterator ();&lt;br /&gt;
username = it.next ().getName ();&lt;br /&gt;
password = it.next ().getName ();&lt;br /&gt;
hello = it.next ().getName ();&lt;br /&gt;
isGuest = Boolean.valueOf (it.next ().getName ());&lt;br /&gt;
isUser = Boolean.valueOf (it.next ().getName ());&lt;br /&gt;
isAdmin = Boolean.valueOf (it.next ().getName ());&lt;br /&gt;
} catch (PolicyContextException e) {&lt;br /&gt;
throw new InvalidUserException ();&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public String getUsername () {&lt;br /&gt;
return username;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public String getPassword () {&lt;br /&gt;
return password;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public boolean isGuest () {&lt;br /&gt;
return isGuest;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public boolean isAdmin () {&lt;br /&gt;
return isAdmin;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public boolean isUser () {&lt;br /&gt;
return isUser;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;/principal&gt;&lt;/tt&gt;&lt;br /&gt;
&lt;center&gt;&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/product/0596007345/ref=as_li_tf_il?ie=UTF8&amp;tag=vxp-20&amp;linkCode=as2&amp;camp=217145&amp;creative=399369&amp;creativeASIN=0596007345"&gt;&lt;img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&amp;Format=_SL160_&amp;ASIN=0596007345&amp;MarketPlace=US&amp;ID=AsinImage&amp;WS=1&amp;tag=vxp-20&amp;ServiceVersion=20070822" &gt;&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=vxp-20&amp;l=as2&amp;o=1&amp;a=0596007345&amp;camp=217145&amp;creative=399369" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;&lt;br /&gt;
&lt;/center&gt;&lt;br /&gt;
&lt;span style="font-size: 130%;"&gt;&lt;span style="color: #663366;"&gt;Web application example&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Finally, write a web application example to test our login module.&lt;br /&gt;
First, the &lt;tt&gt;web.xml&lt;/tt&gt; file must contain the classic security configuration elements :&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_WSFHFTDJ5iw/RhJnKqyroFI/AAAAAAAAAAc/KwQqy69hORI/s1600-h/Capture-NetBeans+IDE+5.5+-+JBossCustomLoginModule.png"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5049211565218963538" src="http://2.bp.blogspot.com/_WSFHFTDJ5iw/RhJnKqyroFI/AAAAAAAAAAc/KwQqy69hORI/s400/Capture-NetBeans+IDE+5.5+-+JBossCustomLoginModule.png" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /&gt;&lt;/a&gt;Second, the &lt;tt&gt;jboss-web.xml&lt;/tt&gt; must declare the security domain :&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://1.bp.blogspot.com/_WSFHFTDJ5iw/RhJnaayroGI/AAAAAAAAAAk/SkkREqqfJrY/s1600-h/Capture-NetBeans+IDE+5.5+-+JBossCustomLoginModuleTest.png"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5049211835801903202" src="http://1.bp.blogspot.com/_WSFHFTDJ5iw/RhJnaayroGI/AAAAAAAAAAk/SkkREqqfJrY/s400/Capture-NetBeans+IDE+5.5+-+JBossCustomLoginModuleTest.png" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /&gt;&lt;/a&gt;&lt;br /&gt;
Third, a simple JSP page to demonstrate the use of the AuthenticatedUserInformations class.&lt;br /&gt;
In an empty JSP page add the following lines before the HTML body :&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/_WSFHFTDJ5iw/RhJoLKyroHI/AAAAAAAAAAs/0a7N7ZdW7Kk/s1600-h/Capture-NetBeans+IDE+5.5+-+JBossCustomLoginModuleTest-1.png"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5049212673320525938" src="http://4.bp.blogspot.com/_WSFHFTDJ5iw/RhJoLKyroHI/AAAAAAAAAAs/0a7N7ZdW7Kk/s400/Capture-NetBeans+IDE+5.5+-+JBossCustomLoginModuleTest-1.png" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /&gt;&lt;/a&gt;and some JSP and HTML code in the body :&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/_WSFHFTDJ5iw/RhJoXKyroII/AAAAAAAAAA0/vsgeKNrBqog/s1600-h/Capture-NetBeans+IDE+5.5+-+JBossCustomLoginModuleTest-2.png"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5049212879478956162" src="http://4.bp.blogspot.com/_WSFHFTDJ5iw/RhJoXKyroII/AAAAAAAAAA0/vsgeKNrBqog/s400/Capture-NetBeans+IDE+5.5+-+JBossCustomLoginModuleTest-2.png" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /&gt;&lt;/a&gt;Deploy your application and give it a try !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6059900666911337555-4109290906788307096?l=x-techteam.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4t-LWKrrhIkyqFwMhJJkjI1KuYs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4t-LWKrrhIkyqFwMhJJkjI1KuYs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4t-LWKrrhIkyqFwMhJJkjI1KuYs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4t-LWKrrhIkyqFwMhJJkjI1KuYs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareDevelopmentOperatingSystems/~4/u__1NEeY3kk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://x-techteam.blogspot.com/feeds/4109290906788307096/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6059900666911337555&amp;postID=4109290906788307096" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/4109290906788307096?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/4109290906788307096?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareDevelopmentOperatingSystems/~3/u__1NEeY3kk/jboss-custom-login-module-simple.html" title="JBoss custom login module : a simple example" /><author><name>HM</name><uri>http://www.blogger.com/profile/15314161484458836048</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="31" src="http://4.bp.blogspot.com/-RCZ2mlbmVd0/TpgZlCf1LyI/AAAAAAAAAbo/CXeSJw4Tp64/s220/icon-software-development.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_WSFHFTDJ5iw/RhJiM6yroEI/AAAAAAAAAAU/2XyFdhiJvy8/s72-c/Capture-NetBeans+IDE+5.5.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://x-techteam.blogspot.com/2007/04/jboss-custom-login-module-simple.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0EMQnk6fip7ImA9WxZXF0w.&quot;"><id>tag:blogger.com,1999:blog-6059900666911337555.post-4099611840467810269</id><published>2006-12-01T22:16:00.001Z</published><updated>2008-03-05T10:08:03.716Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-03-05T10:08:03.716Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="development" /><category scheme="http://www.blogger.com/atom/ns#" term="eclipse" /><category scheme="http://www.blogger.com/atom/ns#" term="software" /><category scheme="http://www.blogger.com/atom/ns#" term="javaee" /><category scheme="http://www.blogger.com/atom/ns#" term="j2ee" /><category scheme="http://www.blogger.com/atom/ns#" term="jboss" /><title>Eclipse+JBoss Error : "transport error 202"</title><content type="html">I get the following error when starting JBoss 4.0.5 from Eclipse/JBossIDE :&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;&lt;br /&gt;ERROR: transport error 202: gethostbyname: unknown host ["transport.c",L41]&lt;br /&gt;ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) ["debugInit.c",L500]&lt;br /&gt;JDWP exit error JVMTI_ERROR_INTERNAL(113): No transports initializedFATAL ERROR in native method: JDWP No transports initialized, jvmtiError=JVMTI_ERROR_INTERNAL(113)&lt;br /&gt;&lt;/code&gt;&lt;/blockquote&gt;&lt;br /&gt;Since this error only appears when starting JBoss when connected to my home network and not at work, I suspected a DNS/Resolver problem.&lt;br /&gt;To correct the problem, just add the following line to &lt;code&gt;/etc/hosts&lt;/code&gt; :&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;&lt;br /&gt;127.0.0.1        localhost&lt;br /&gt;&lt;/code&gt;&lt;/blockquote&gt;&lt;br /&gt;Apparently the problem appears only when launching the Eclipse debugger and is not linked with JBoss.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6059900666911337555-4099611840467810269?l=x-techteam.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MVY2vQftxvXvBL-vB9zVJW3_xJk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MVY2vQftxvXvBL-vB9zVJW3_xJk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MVY2vQftxvXvBL-vB9zVJW3_xJk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MVY2vQftxvXvBL-vB9zVJW3_xJk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareDevelopmentOperatingSystems/~4/UmZtqIMh93s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://x-techteam.blogspot.com/feeds/4099611840467810269/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6059900666911337555&amp;postID=4099611840467810269" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/4099611840467810269?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/4099611840467810269?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareDevelopmentOperatingSystems/~3/UmZtqIMh93s/eclipsejboss-error-transport-error-202.html" title="Eclipse+JBoss Error : &quot;transport error 202&quot;" /><author><name>HM</name><uri>http://www.blogger.com/profile/15314161484458836048</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="31" src="http://4.bp.blogspot.com/-RCZ2mlbmVd0/TpgZlCf1LyI/AAAAAAAAAbo/CXeSJw4Tp64/s220/icon-software-development.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://x-techteam.blogspot.com/2006/12/eclipsejboss-error-transport-error-202.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0MARXo5eCp7ImA9WBBXGEU.&quot;"><id>tag:blogger.com,1999:blog-6059900666911337555.post-602727619628438765</id><published>2006-11-30T12:00:00.000Z</published><updated>2006-11-30T12:24:04.420Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-30T12:24:04.420Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="linux" /><category scheme="http://www.blogger.com/atom/ns#" term="fedora" /><category scheme="http://www.blogger.com/atom/ns#" term="software" /><category scheme="http://www.blogger.com/atom/ns#" term="vmware" /><title>WMWare : "End of error message"</title><content type="html">A great error message from VMWare server :&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/x/blogger2/3155/739733968128825/1600/207357/Capture-Error.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/x/blogger2/3155/739733968128825/320/401688/Capture-Error.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;"End of error message".... very usefull !&lt;br /&gt;To view the real error message, just check the &lt;code&gt; /var/log/vmware/vmware-serverd.log&lt;/code&gt; file :&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;&lt;br /&gt;Msg_Post: Could not open /dev/vmmon: No such file or directory.&lt;br /&gt;Nov 30 12:59:53: app| Please make sure that the kernel module `vmmon' is loaded.&lt;br /&gt;Nov 30 12:59:53: app|&lt;br /&gt;Nov 30 12:59:53: app| Msg_Post: Error&lt;br /&gt;Nov 30 12:59:53: app| [msg.vmmonPosix.initFailed] Failed to initialize monitor device.&lt;br /&gt;Nov 30 12:59:53: app| [localized] Failed to initialize monitor device.&lt;br /&gt;&lt;/code&gt;&lt;/blockquote&gt;&lt;br /&gt;Ooops, the VMWare service (which create &lt;code&gt;/dev/vmmon&lt;/code&gt; and other devices) was not started :&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;&lt;br /&gt;# sudo service vmware start&lt;br /&gt;&lt;/code&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6059900666911337555-602727619628438765?l=x-techteam.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/p0OWJjLvErfjpe0qD37gPUJC0g4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/p0OWJjLvErfjpe0qD37gPUJC0g4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/p0OWJjLvErfjpe0qD37gPUJC0g4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/p0OWJjLvErfjpe0qD37gPUJC0g4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareDevelopmentOperatingSystems/~4/LT02Ra6PAbg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://x-techteam.blogspot.com/feeds/602727619628438765/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6059900666911337555&amp;postID=602727619628438765" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/602727619628438765?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/602727619628438765?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareDevelopmentOperatingSystems/~3/LT02Ra6PAbg/wmware-end-of-error-message.html" title="WMWare : &quot;End of error message&quot;" /><author><name>HM</name><uri>http://www.blogger.com/profile/15314161484458836048</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="31" src="http://4.bp.blogspot.com/-RCZ2mlbmVd0/TpgZlCf1LyI/AAAAAAAAAbo/CXeSJw4Tp64/s220/icon-software-development.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://x-techteam.blogspot.com/2006/11/wmware-end-of-error-message.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUDRX49fyp7ImA9WBBXFk4.&quot;"><id>tag:blogger.com,1999:blog-6059900666911337555.post-8761869990448907631</id><published>2006-11-27T13:08:00.000Z</published><updated>2006-11-27T14:37:54.067Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2006-11-27T14:37:54.067Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="pgworksheet" /><category scheme="http://www.blogger.com/atom/ns#" term="development" /><category scheme="http://www.blogger.com/atom/ns#" term="software" /><category scheme="http://www.blogger.com/atom/ns#" term="python" /><category scheme="http://www.blogger.com/atom/ns#" term="postgresql" /><category scheme="http://www.blogger.com/atom/ns#" term="oracle" /><title>Introducing PgWorksheet</title><content type="html">&lt;a href="http://pgworksheet.projects.postgresql.org/"&gt;PgWorksheet&lt;/a&gt; is a simple GUI frontend to PostgreSQL for executing SQL queries and psql commands without using the psql command line tool.&lt;br /&gt;&lt;br /&gt;Development of this tool have started at the &lt;a href="http://www.e-cml.org/"&gt;E-CML&lt;/a&gt; Computer Science school for SQL and PL/SQL courses when Oracle was replaced by &lt;a href="http://www.postgresql.org/"&gt;PostgreSQL&lt;/a&gt; for this courses.&lt;br /&gt;PostgreSQL was choosen in place of Oracle for several reasons :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Minimal server administration compared to the mammoth-style administration tasks requiered by Oracle&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Minimal CPU &amp;amp; memory footprint : Oracle needed a single server only for the courses. With PostgreSQL, the database was installed on the school main NFS/Samba/DNS/DHCP/VPN/... server.&lt;/li&gt;&lt;li&gt;No need to install a mammoth-sized client to have a simple GUI client to execute simples SQL queries.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;This last point is also an important problem with PostgreSQL at the time of the switch : the total lack of a simple, light, easy to install, open source, free GUI client.&lt;br /&gt;While PostgreSQL offers some great administration tools (&lt;a href="http://www.pgadmin.org/"&gt;PgAdmin&lt;/a&gt;, &lt;a href="http://phppgadmin.sourceforge.net/"&gt;phpPgAdmin&lt;/a&gt;) there are administration tools, not just SQL scratch pads.&lt;br /&gt;&lt;br /&gt;Since the main GUI tool used during SQL courses with Oracle was SQLWorksheet, we started to explore the web to find an identical tool for PostgreSQL. We found only one application fullfiling our requirements, &lt;a href="http://sourceforge.net/projects/pgst/"&gt;pgst.&lt;/a&gt; But pgst have an important problem : despite the fact that is was written in Python, pgst was not portable and needed some important modifications to run under Microsoft Windows.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://pgworksheet.projects.postgresql.org/"&gt;PgWorksheet&lt;/a&gt; started as a re-implementation of some ideas of pgst, written from scratch, but with portability in mind since we have 3 different operating system used during the courses : FreeBSD, Linux Fedora and Microsoft Windows.&lt;br /&gt;&lt;br /&gt;Now &lt;a href="http://pgworksheet.projects.postgresql.org/"&gt;PgWorksheet&lt;/a&gt; version 1.8 offers several, but limited to provide easy of use, fonctionnalities :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;portability (runs on *BSD, all Linux distribs and Microsoft Windows XP)&lt;/li&gt;&lt;li&gt;syntax coloring&lt;/li&gt;&lt;li&gt;load/save SQL queries&lt;/li&gt;&lt;li&gt;SQL queries history&lt;/li&gt;&lt;li&gt;unlimited undo/redo&lt;/li&gt;&lt;li&gt;display of SQL queries results separated (one tab for one query)&lt;/li&gt;&lt;li&gt;server connection history&lt;/li&gt;&lt;/ul&gt;The PgWorksheet project is hosted by &lt;a href="http://pgfoundry.org/projects/pgworksheet/"&gt;PgFoundry&lt;/a&gt; and the &lt;a href="http://pgworksheet.projects.postgresql.org/"&gt;PgWorksheet&lt;/a&gt; sources are hosted by &lt;a href="http://sourceforge.net/projects/pgworksheet"&gt;SourceForge&lt;/a&gt; (you can &lt;a href="http://pgworksheet.cvs.sourceforge.net/pgworksheet/"&gt;browse source code&lt;/a&gt;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6059900666911337555-8761869990448907631?l=x-techteam.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pMxH8v0M9LkiKXOc-7f1MnB490A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pMxH8v0M9LkiKXOc-7f1MnB490A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pMxH8v0M9LkiKXOc-7f1MnB490A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pMxH8v0M9LkiKXOc-7f1MnB490A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SoftwareDevelopmentOperatingSystems/~4/0Lxqvel0kh8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://x-techteam.blogspot.com/feeds/8761869990448907631/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6059900666911337555&amp;postID=8761869990448907631" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/8761869990448907631?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6059900666911337555/posts/default/8761869990448907631?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SoftwareDevelopmentOperatingSystems/~3/0Lxqvel0kh8/introducing-pgworksheet.html" title="Introducing PgWorksheet" /><author><name>HM</name><uri>http://www.blogger.com/profile/15314161484458836048</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="31" src="http://4.bp.blogspot.com/-RCZ2mlbmVd0/TpgZlCf1LyI/AAAAAAAAAbo/CXeSJw4Tp64/s220/icon-software-development.jpg" /></author><thr:total>2</thr:total><feedburner:origLink>http://x-techteam.blogspot.com/2006/11/introducing-pgworksheet.html</feedburner:origLink></entry></feed>

