<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Swarm of XeBees</title>
	
	<link>http://xebee.xebia.in</link>
	<description>powered by Xebia India</description>
	<lastBuildDate>Fri, 02 Mar 2012 06:35:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Xebia/Xebee" /><feedburner:info uri="xebia/xebee" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>Xebia/Xebee</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Five best practices for effective mobile QA</title>
		<link>http://feedproxy.google.com/~r/Xebia/Xebee/~3/8qe4ZL75yzs/</link>
		<comments>http://xebee.xebia.in/2012/03/02/five-best-practices-for-effective-mobile-qa/#comments</comments>
		<pubDate>Fri, 02 Mar 2012 06:35:02 +0000</pubDate>
		<dc:creator>Priyanka</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile Testing]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://xebee.xebia.in/?p=12454</guid>
		<description><![CDATA[In today’s world, ever increasing inclination towards mobile devices and applications has provided great prospects for enterprises to move their business in mobile world. As mobile technology lets the customers stay connected for almost all the time, enterprises are moving beyond the desktop world to keep attuned to their customer needs. But development of mobile applications [...]]]></description>
			<content:encoded><![CDATA[<p>In today’s world, ever increasing inclination towards mobile devices and applications has provided great prospects for enterprises to move their business in mobile world. As mobile technology lets the customers stay connected for almost all the time, enterprises are moving beyond the desktop world to keep attuned to their customer needs. But development of mobile applications with an impeccable user interface and  functionality for highly fragmented mobile market is in itself an ordeal. Thus quite evidently mobile application development has become a booming field in the IT industry. Few days back, I met with a guy who is mobile QA from long time. I discussed with him few of the best practices which shall be followed for functional testing of mobile applications. So through this blog I want to share few of those practices which should be followed by mobile QA while doing testing for any mobile application.<span id="more-12454"></span></p>
<p><b>1. Emulators can be used for limited functionality testing only</b></p>
<p>Emulators are just mimic to actual devices in terms of functionality. They can never be treated as substitutes for actual devices. For a start, device emulators and simulators can act as an stepping stone in testing mobile applications but totally relying on them can lead to catastrophe. One of the prime examples where emulators can be used is testing design level implementations, for instance if the desired icons are on a specific screen or not. The biggest limitation of emulators is that they do not work on real network and are not prone to real world interrupts and for this reason, we need real devices to test applications. For instance emulators can be used in location based apps by simulating a route, but actual interrupts occurring on these routes can only be tested using real devices.</p>
<p><b>2. Field testing is uber important</b></p>
<p>Mobile field testing provides testing assurance of the mobile device’s workability in the actual field. This will ensure that the device works not only in the Static field environment but also in the dynamic field environment. Few years back, there was one research conducted in Helsinki where users were given 10 different tasks to perform on application at different locations. Although that application was already tested before in their laboratories but during field testing users found many different functional bugs due to signal discrepancies and other interrupts.</p>
<p><b>3. Never assume one application works for all</b></p>
<p>Market is full of devices having different configurations, operating systems, features and assuming if things are working fine on one device  then they will be fine on every device is not a good practice at all. Every device has its own characteristics due to which some features of application may fit well in one device and may not in other device. For example:- Samsung and Nokia might come up with any native application solution. Though the basic functionality is the same for both the apps but the look and feel, form factor of the applications might be largely different from each other.</p>
<p><b>4. Keep interrupts in mind while mobile app testing</b></p>
<p>Wireless networks are prone to functional and network interrupts. Lets take an example where user is disbursing using his debit card and in between that transaction there is a signal loss for fraction of seconds. In that case application should be able to intimate user about signal loss or should  be able to resume from where signal was lost then his transaction should be completed  after this interrupt is over. This was just one example of interrupt. There can be other types of interrupts like receiving message, receiving calls which are uncontrollable. The concept of interrupts is important in every type of applications and they should be tested with extra care specially in case of financial applications like mobile banking.</p>
<p><b>5. Give special focus on usability</b></p>
<p>Good user interface can play crucial role in software industry.Any software product can be made with provided set of functionality but an intelligent user interface can make a product hit. Intelligent user  interface means it should be easily used by end-users. There are unique features in usability of a mobile application when compared to normal desktop application. Some of the examples are mentioned below:-</p>
<p>1. Mobile devices are designed for both left handed and right handed people. In that case, QA should focus on convenience perspective so that mobile applications can be used by both set of people.</p>
<p>2. Mobile applications should be tested according to phone orientation as mobile applications can be viewed either in landscape or portrait format.  Here, QA should focus on testing on different screen resolution as well as different orientation format.</p>
<p>3. In addition to usability testing in different orientation,  usability should also be tested for touchscreen screens, qwerty keypads,etc. Example : sufficient usability testing should be performed to ensure that the keyboard is visible only when it is required while inputting text, numbers, etc.</p>
<img src="http://feeds.feedburner.com/~r/Xebia/Xebee/~4/8qe4ZL75yzs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://xebee.xebia.in/2012/03/02/five-best-practices-for-effective-mobile-qa/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://xebee.xebia.in/2012/03/02/five-best-practices-for-effective-mobile-qa/</feedburner:origLink></item>
		<item>
		<title>Executing Selenium/WebDriver tests remotely using Maven and Jenkins</title>
		<link>http://feedproxy.google.com/~r/Xebia/Xebee/~3/ZlJoyYhuNbU/</link>
		<comments>http://xebee.xebia.in/2012/03/01/executing-seleniumwebdriver-tests-remotely-using-maven-and-jenkins/#comments</comments>
		<pubDate>Thu, 01 Mar 2012 18:36:38 +0000</pubDate>
		<dc:creator>Rajneesh</dc:creator>
				<category><![CDATA[Agile Testing]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[Test Auotmation]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[WebDriver]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[Jenkins]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[RemoteWebDriver]]></category>
		<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[testing tools]]></category>

		<guid isPermaLink="false">http://xebee.xebia.in/?p=12487</guid>
		<description><![CDATA[Recently our team created a nifty selenium test suite for testing a salesforce.com app we developed. We used TestNG framework for writing tests along with the latest and greatest selenium available out there which is WebDriver. In case you want to know why we chose web driver over RC,read this. Since we planned to execute [...]]]></description>
			<content:encoded><![CDATA[<p>Recently our team created a nifty selenium test suite for testing a salesforce.com app we developed. We used <a href="http://testng.org/doc/index.html">TestNG </a> framework for writing tests along with the latest and greatest selenium available out there which is <a href="http://code.google.com/p/selenium/wiki/GettingStarted">WebDriver</a>. In case you want to know why we chose web driver over RC,read <a href="http://xebee.xebia.in/2012/02/07/selenium-web-driver-or-rc-decide-yourself/">this</a>. Since we planned to execute the tests on a remote windows machine triggered from our Jenkins machine (linux), we leveraged the capabilities of <a href="http://code.google.com/p/selenium/wiki/RemoteWebDriver">RemoteWebdriver</a>. Eventually we wanted to be able to run the tests with our Continuous Integration environment which meant that the tests are build on Jenkins (linux) with maven and executed on dedicated windows machine remotely.<br />
<span id="more-12487"></span><br />
Following are the key objectives that we identified to make it happen:</p>
<p>1. Configure/trigger the tests in way so that we can put them into the Jenkins machines as build jobs.</p>
<p>2. Use maven targets to be able to force a browser type at build time (for example: mvn integration-test -DBrowserType=chrome). Using this we can create multiple Jenkins jobs for execution of selenium tests against each browser.</p>
<p>3. Make remote execution capability configurable along with the location (IP and port) of the selenium server (if Remote Execution is true) so that we can easily switch server (if required) or use multiple servers simultaneously executing test against different browsers.</p>
<p>4. Run the tests on multiple browsers like FF,IE and chrome.</p>
<p>With the help of this blog I intend to share the way we set about to achieve our objectives. Here I am assuming that the reader is aware of basic concepts of selenium and maven.</p>
<p>As a first step we created a maven project for the test suite and added the required dependencies to the POM file. We prepared a remote windows virtual machine with all the required browsers and downloaded the selenium-server-standalone-{VERSION}.jar on it.</p>
<p>In our framework, we added a few system properties in our BaseTest.java (A helper class used by all tests to instantiate a WebDriver/RemoteWebDriver instance).</p>
<p><code><span style="color: #993300;">String BrowserType = System.getProperty("BrowserType");</span><br />
<span style="color: #993300;"> String RemoteExecution = System.getProperty("RemoteExecution");</span><br />
<span style="color: #993300;"> String RemoteUrl = System.getProperty("RemoteUrl");</span><br />
</code></p>
<p>Next, we made the invocation of a browser type and remote execution capability dependent on these property values in our BaseTest.java.</p>
<p><span style="color: #000080;"><code>if(!<strong>RemoteExecution</strong>.equals("true")) <span style="color: #333333;">// remote execution is false</span></code></span><br />
<span style="color: #333333;"> <code>{</code></span><br />
<span style="color: #000080;"> <code>if(<strong>BrowserType</strong>.equals("firefox"))</code></span><br />
<span style="color: #000080;"> <code>{</code></span><br />
<span style="color: #000080;"> <code>WebDriver driver = new FirefoxDriver(); <span style="color: #333333;">// Create a new instance of firefox driver</span></code></span><br />
<code><span style="color: #000080;">}</span><br />
<span style="color: #000080;"> else if</span><br />
<span style="color: #000080;"> {</span><br />
<span style="color: #000080;"> code for ie and chrome goes here</span><br />
<span style="color: #000080;"> }</span><br />
<span style="color: #000080;"> else                              <span style="color: #333333;"> //remote execution is true</span></span><br />
<span style="color: #000080;"> <code> if(<strong>BrowserType</strong>.equals("firefox"))</code></span><br />
<span style="color: #000080;"> {</span><br />
<span style="color: #000080;"> WebDriver driver = new RemoteWebDriver(newURL(<strong>RemoteUrl</strong>+"/wd/hub"),DesiredCapabilities.firefox());</span><br />
<span style="color: #333333;"> //Create a new instance of RemoteWebDriver with the  remote server url</span><br />
<span style="color: #000080;"> }</span><br />
<span style="color: #000080;"> else if</span><br />
<span style="color: #000080;"> {</span><br />
<span style="color: #000080;"> code for ie and chrome goes here</span><br />
<span style="color: #000080;"> }</span><br />
</code></p>
<p>Finally, we configured the maven-surefire-plugin to run the tests in integration-test phase. In the plugin execution we added the parameter 'systemPropertyVariables' to pass values for the system properties defined above at build time.</p>
<p><span style="color: #000080;">&lt;plugin&gt;</span><br />
<span style="color: #000080;"> &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;</span><br />
<span style="color: #000080;"> &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;</span><br />
<span style="color: #000080;"> &lt;configuration&gt;</span><br />
<span style="color: #000080;"> &lt;skip&gt;true&lt;/skip&gt;</span><br />
<span style="color: #000080;"> &lt;/configuration&gt;</span><br />
<span style="color: #000080;"> &lt;executions&gt;</span><br />
<span style="color: #000080;"> &lt;execution&gt;</span><br />
<span style="color: #000080;"> &lt;phase&gt;integration-test&lt;/phase&gt;</span><br />
<span style="color: #000080;"> &lt;goals&gt;</span><br />
<span style="color: #000080;"> &lt;goal&gt;test&lt;/goal&gt;</span><br />
<span style="color: #000080;"> &lt;/goals&gt;</span><br />
<span style="color: #000080;"> &lt;configuration&gt;</span><br />
<span style="color: #000080;"> &lt;skip&gt;false&lt;/skip&gt;</span><br />
<span style="color: #000080;"> <strong> &lt;systemPropertyVariables&gt;</strong></span><br />
<span style="color: #000080;"> <strong> &lt;BrowserType&gt;firefox&lt;/BrowserType&gt;</strong></span><br />
<span style="color: #000080;"> <strong> &lt;RemoteExecution&gt;false&lt;/RemoteExecution&gt;</strong></span><br />
<span style="color: #000080;"> <strong> &lt;RemoteUrl&gt;http://127.0.0.1:4444&lt;/RemoteUrl&gt;</strong></span><br />
<span style="color: #000080;"> <strong> &lt;/systemPropertyVariables&gt;</strong></span><br />
<span style="color: #000080;"> &lt;suiteXmlFiles&gt;</span><br />
<span style="color: #000080;"> &lt;suiteXmlFile&gt;${project.build.directory}/test-classes/testng.xml&lt;/suiteXmlFile&gt;</span><br />
<span style="color: #000080;"> &lt;/suiteXmlFiles&gt;</span><br />
<span style="color: #000080;"> &lt;/configuration&gt;</span><br />
<span style="color: #000080;"> &lt;/execution&gt;</span><br />
<span style="color: #000080;"> &lt;/executions&gt;</span><br />
<span style="color: #000080;"> &lt;/plugin&gt;</span></p>
<p>Now once we had the server running on the remote VM (using java -jar selenium-server-standalone-{VERSION}.jar) we were able to build and execute our tests using the following maven command.<br />
<code><br />
<span style="color: #993300;">mvn integration-test -DBrowserType=firefox -DRemoteExecution=true -DRemoteUrl=http://xyz.com:4444</span><br />
</code><br />
Now we already achieved our objective 1,2 and 3 but not 4. We ran into issues while running the tests on chrome remotely. We encountered an exception with the message 'The path to the chrome driver executable must be set by the webdriver.chrome.driver system property'. The solution to this is already discussed on <a href="http://stackoverflow.com/questions/6921170/how-to-build-remote-webdriver-for-chrome">stackoverflow</a>. In nutshell, you need to have the chromedriver.exe on the remote machine (where the selenium server is hosted) and run the selenium server on the remote machine with the following argument<br />
<code><br />
<span style="color: #993300;"> java -Dwebdriver.chrome.driver="path-to-chromedriver.exe" -jar selenium-server-standalone.jar</span><br />
</code><br />
That's it. This enabled us to run our tests on any remote machine against a specific browser with ease in continuous integration environment. It would be great to hear what alternative approaches you have used to solve something similar.</p>
<img src="http://feeds.feedburner.com/~r/Xebia/Xebee/~4/ZlJoyYhuNbU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://xebee.xebia.in/2012/03/01/executing-seleniumwebdriver-tests-remotely-using-maven-and-jenkins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://xebee.xebia.in/2012/03/01/executing-seleniumwebdriver-tests-remotely-using-maven-and-jenkins/</feedburner:origLink></item>
		<item>
		<title>NFC in Android</title>
		<link>http://feedproxy.google.com/~r/Xebia/Xebee/~3/SXZ5IgiXWko/</link>
		<comments>http://xebee.xebia.in/2012/03/01/nfc-in-android/#comments</comments>
		<pubDate>Thu, 01 Mar 2012 12:51:22 +0000</pubDate>
		<dc:creator>Paramvir Singh</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[mCommerce]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile Apps]]></category>
		<category><![CDATA[NFC]]></category>
		<category><![CDATA[android development]]></category>
		<category><![CDATA[android wallet]]></category>
		<category><![CDATA[Android4.0]]></category>
		<category><![CDATA[mobile apps]]></category>
		<category><![CDATA[Near Field Communication]]></category>

		<guid isPermaLink="false">http://xebee.xebia.in/?p=12262</guid>
		<description><![CDATA[Near Field Communication or NFC is one of the hottest and most talked about feature in present day smartphones. The reason it is being so popular with smartphone users is that it is intuitive and easy to use. Also, NFC is being considered as one of the most appealing future technology in Mobile domain. Invented [...]]]></description>
			<content:encoded><![CDATA[<p>Near Field Communication or NFC is one of the hottest and most talked about feature in present day smartphones. The reason it is being so popular with smartphone users is that it is intuitive and easy to use. Also, NFC is being considered as one of the most appealing future technology in Mobile domain. Invented by NXP and Sony jointly in 2002, NFC was first adopted by Nokia for their smartphones to make mobile payments easy for their users. Now it is being supported and encouraged by <a target="_blank" title="NFC forum" href="http://www.nfc-forum.org/home/">NFC -Forum</a>, which has nearly 160 members including mobile manufaturers and developers. The member list of this forum boasts of major players like Samsung, Motorola, Google, Sony Ericsson and Microsoft among others.</p>
<p><span id="more-12262"></span>Google is particularly ambitious about this feature in its latest range of Android devices. Here is a summary of recent efforts by Google to make NFC popular among users and developers:</p>
<ul>
<li><strong>NFC API's for developers: </strong>In OS version 2.3 (Gingerbread) of Android, Google introduced NFC support and also exposed API's for developers to create applications for NFC enabled Android devices. Using this API's, "Developers can create new applications that offer proximity-based information and services to users, organizations, merchants, and advertisers".</li>
<li><strong>Google Wallet: </strong>Google's ambitious project in the area of mCommerce. This application for smart-phones empowers the devices to act as a virtual wallet which store user's credit card and other payment information safely. Users can use their mobile devices at stores to pay and benefit from offers provided by Google directly. The transaction will happen by tapping the mobile device at NFC readers installed at point of sales.</li>
<li><strong>Android Beam: </strong>In Android 4.0(Ice-cream Sandwich), a new application called "Beam" is introduced. This application makes it more easy and intuitive for users to share contacts, apps, songs and videos between two Android devices using NFC. Beam uses NFC Android API's which are fully exposed to developers.</li>
</ul>
<p>Let's dig into the important API’s and technical details we can use to make our application NFC enabled. Two terms frequently used for NFC are:</p>
<ul>
<li><strong>NFC Tag: </strong>The important characteristic of NFC is that an NFC powered mobile device can read and write passive targets. These passive targets are usually NFC tags which may be very small and simple and can be in the form of small stickers, movie poster or visting cards.</li>
<li><strong>NFC device:</strong> NFC device is the powered device which can read or write another NFC device or tag. In our case, it is NFC enabled Android phone.</li>
</ul>
<p><b>Detecting an NFC tag:</b></p>
<p>NFC device detects a NFC tag or other device when they come in close proximity(distance &lt; 4cm). On detecting the target, the device opens up the desired Activity to handle the required job. For instance, when a video is to be shared, Youtube application opens up and when user wants to share an app, Android market gets opened. If the device detects a tag with a link, it redirects to that link on browser.</p>
<p>This astute process of detecting a target, extracting information from that target and then pinpointing the Activity to accomplish the intended task without user intervention is called "<strong>Tag dispatching</strong>". Tags contain small amount of data in a special format called NDEF (NFC Data Exchange Format) standardized by NFC forum. This data and its MIME type is exchanged from the target to the device. On device, this data is further attached to an Intent which is sent to the interested applications. The applications which intend to handle this type of data will have to register appropriate Intent-filter.</p>
<p>We deal with following classes:</p>
<ol>
<li><strong>NdefMessage: </strong>Container class for storing the NDEF data. It contains a group of records which  contain the actual payload data, the type of data and other information about it.</li>
<li><strong>NdefRecord: </strong>Represents the records in NdefMessage. These records contain different fields to identify the required information about the data like format, type, ID and the actual payload. One of the field is <strong>Type Name Format (TNF)</strong> which is used to detect the MIME type or URI of the NdefMessage. When the data is transferred from target to receiver,the first NdefRecord is looked up for getting information about the whole NdefMessage. After that an Intent is created with action <strong>ACTION_NDEF_DISCOVERED </strong>and the MIME type and URI is attached to it.</li>
</ol>
<p>The appropriate application is chosen to do the job on the bases of intent and the data attached to it. The applications willing to handle the NFC tag detection declare intent filter in their manifest file:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;intent-filter&gt;

&lt;action android:name=&quot;android.nfc.action.NDEF_DISCOVERED&quot;/&gt;

&lt;category android:name=&quot;android.intent.category.DEFAULT&quot;/&gt;

&lt;data android:scheme=&quot;http&quot;

android:host=&quot;xebia.in&quot;

android:pathPrefix=&quot;/company.html&quot; /&gt;

&lt;/intent-filter&gt;
</pre>
<p>This Intent filter will filter intent generated on detecting a tag having a URI as data and will result in opening www.xebia.in/company.html in browser.</p>
<p style="text-align: center;"><img height="500" width="620" src="http://xebee.xebia.in/wp-content/uploads/2012/02/Tag_dispatching.png" title="Tag_dispatching" class="aligncenter size-full wp-image-12284" /></p>
<p><strong>Extracting required data from the NFC intent:</strong></p>
<p>When the selected activity opens up after tag dispatch, required data is extracted from the incoming intent to proceed further. This data is contained in "extras" of the intent:</p>
<p>1<strong>.  EXTRA_TAG: </strong>The extra for containing payload data and tag technology information bound into a  Tag object.</p>
<pre class="brush: java; title: ; notranslate">
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
</pre>
<p>2. <strong>EXTRA_NDEF_MESSAGES: </strong>The extra for containing all the NDEF messages in Tag object. These messages are obtained in an Array of Parcelable objects.</p>
<pre class="brush: java; title: ; notranslate">

public void onResume() {
	super.onResume();
	Intent parentIntent = getIntent();
	if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(parentIntent.getAction())){
		Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
		if (rawMsgs != null) {
			msgs = new NdefMessage[rawMsgs.length];
			for (int i = 0; i &lt; rawMsgs.length; i++){
				msgs[i] = (NdefMessage) rawMsgs[i];
			}
		}
	}
}
</pre>
<p><strong>Using Beam to push data:</strong></p>
<p>Beam can be used to push data from an application while it is running in foreground. Beam gets activated when the "beaming" device is put in physical contact with another device for a moment. At this instance, user is prompted for confirmation in special Beam UI and style. Any third party application can integrate Beam by using <strong>setNdefPushMessage() </strong>on <strong>NfcAdapter</strong>. This method will handle the beaming of data when devices come in required distance.</p>
<p><strong>CreateNdefMessageCallback </strong>interface is implemented to add Ndef push functionality in the Activity. This implementation requires following method to be defined:</p>
<pre class="brush: java; title: ; notranslate">
public NdefMessage createNdefMessage(NfcEvent event) {
String message = &quot;This is NFC message&quot;;
NdefRecord mimeRecord = createMimeRecord(&quot;application/param.android.sample.beam&quot;,
message.getBytes());
NdefRecord appRecord = NdefRecord.createApplicationRecord(&quot;param.android.sample.beam&quot;);
NdefRecord[] ndefRecords = new NdefRecord[] {
mimeRecord,
appRecord
};
NdefMessage ndefMessage = new NdefMessage(ndefRecords);
return ndefMessage;
}

public NdefRecord createMimeRecord(String mimeType, byte[] payload) {
byte[] mimeBytes = mimeType.getBytes(Charset.forName(&quot;US-ASCII&quot;));
NdefRecord mimeRecord = new NdefRecord(
NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload);
return mimeRecord;
}
</pre>
<p>Here two NdefRecords are being transferred. One record represents a text message and other is <strong>Android Application Record. </strong>This may be included to get guarantee that only this application will be opened up on detecting NFC device with this intent.</p>
<p>In onCreate method a reference to to an NFC adapter is created and a callback is set to it:</p>
<pre class="brush: java; title: ; notranslate">
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Check for available NFC Adapter
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter == null) {
Toast.makeText(this, &quot;NFC is not available&quot;, Toast.LENGTH_LONG).show();
finish();
return;
}
// Register callback
nfcAdapter.setNdefPushMessageCallback(this, this);
}
</pre>
<p>The developers can use basic NFC API's to support any kind of tags and NFC data or they can simply leverage the benefits of in built Beam application to use NFC power. Interesting thing is that these API's are really simple to use and working with NFC is nothing less than fun.</p>
<img src="http://feeds.feedburner.com/~r/Xebia/Xebee/~4/SXZ5IgiXWko" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://xebee.xebia.in/2012/03/01/nfc-in-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://xebee.xebia.in/2012/03/01/nfc-in-android/</feedburner:origLink></item>
		<item>
		<title>Distributed Pomodoro</title>
		<link>http://feedproxy.google.com/~r/Xebia/Xebee/~3/PHKMEm5RwCM/</link>
		<comments>http://xebee.xebia.in/2012/02/29/distributed-pomodoro/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 18:20:08 +0000</pubDate>
		<dc:creator>Sohil</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Human Behaviour]]></category>
		<category><![CDATA[thought]]></category>

		<guid isPermaLink="false">http://xebee.xebia.in/?p=12418</guid>
		<description><![CDATA[Pomodoro is a simple technique for time management. Here is a link if you would like to know more about Pomodoro.http://www.pomodorotechnique.com/ . Here at Xebia we have a Open work area.This blog talk about one of the problems that we faced while working in Open work area and how we solved it.Our team was following Scrum [...]]]></description>
			<content:encoded><![CDATA[<p>Pomodoro is a simple technique for time management. Here is a link if you would like to know more about Pomodoro.<a target="_blank" href="http://www.pomodorotechnique.com/">http://www.<wbr></wbr>pomodorotechnique.com/</a> . Here at Xebia we have a Open work area.This blog talk about one of the problems that we faced while working in Open work area and how we solved it.Our team was following Scrum with a two weeks sprints.This was an ongoing project for last 6 months which had a team of 2.Project was recently just scaled up to 8 team members. Which means there were 6 team members who had joined new.<br />
<span id="more-12418"></span></p>
<div>
<div>
<div>Following are the challenges that we (new guys on team) faced</div>
<div>
<ul>
<li>No domain knowledge</li>
<li>Less idea about the latest frameworks used in project.</li>
<li>No idea about the architecture of the current project.</li>
</ul>
</div>
</div>
<div></div>
<div>
<div>With the above challenges one of the common point of Retrospective was we were disturbing</div>
</div>
<div>the 2 guys who have been in the project for the longest time. This is one of the disadvantages of this open work enviornment. You can be disturbed every easily. "Get the image for open work area". If someone has a questions he can just interrupt you when you are actually in the zone. This further affected the productivity of the 2 guys.</div>
<p>&nbsp;</p>
<div>To solve this problem Distributed Pomodoro was the solution that we came up with. Like pomodoro is a time management technique for one to be more productive and focused on work.The idea was simple We all have our clocks synched. We formed a protocol that we all work for 40 minutes and take a break for 10 minutes.Use this 10 minutes to discuss questions if we have , take a break , etc. Basically you can make all the noise you want to in a room in this 10 min.</div>
<div></div>
<div>This all looked good but there were a lot of challenges in executing this</div>
<div>
<ul>
<li>Someone has to keep time.</li>
<li>Not everyone starts the day together.</li>
</ul>
</div>
<p>&nbsp;</p>
<div>To solve the above challenge I have made a simple application based on P2P Solution. The application creates a virtual group</div>
<div>on LAN. Everyone can join the group in the start of the day.Anyone can start the clock. Once the clock is started it will start a clock on everyone's laptop. Once 40 mins is over there will be a loud alarm.If someone joins in the middle he will have the current clock timings synchronized on his laptop.</div>
<p>&nbsp;</p>
<div>This is a simple application that works on P2P based network.Having P2P message for communicating and synchronizing everyone connected.Also because of this application not only one person but the whole team follows Pomodoro.With some practicing this will help increase the teams productivity to good extend.Here is the <a href="http://code.google.com/p/team-pomodoro/source/checkout">Source Code</a></div>
<p>of the application. Enjoy!!</p>
</div>
<img src="http://feeds.feedburner.com/~r/Xebia/Xebee/~4/PHKMEm5RwCM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://xebee.xebia.in/2012/02/29/distributed-pomodoro/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://xebee.xebia.in/2012/02/29/distributed-pomodoro/</feedburner:origLink></item>
		<item>
		<title>To Err is a Developer</title>
		<link>http://feedproxy.google.com/~r/Xebia/Xebee/~3/ef1HIvcm6h4/</link>
		<comments>http://xebee.xebia.in/2012/02/28/to-err-is-a-developer/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 08:05:13 +0000</pubDate>
		<dc:creator>Shruti Khattar</dc:creator>
				<category><![CDATA[Designing]]></category>
		<category><![CDATA[Project Development Methodologies]]></category>
		<category><![CDATA[Quality]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Development practices]]></category>

		<guid isPermaLink="false">http://xebee.xebia.in/?p=12140</guid>
		<description><![CDATA[There is nothing like “flawless” in this world. Even the renowned or self proclaimed “Perfectionists” are not immaculate. Errors, mistakes, bugs are part of life of a developer. They can be equated to the quadrants of the 'Johari Window'.  In terms of design, code, testing, security measures, providing access and information, there can be both [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;" align="CENTER"><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: small;" color="#000000"><span face="Arial, sans-serif"><span size="2">There is nothing like “flawless” in this world. Even the renowned or self proclaimed “Perfectionists” are not immaculate. Errors, mistakes, bugs are part of life of a developer. They can be equated to the quadrants of the 'Johari Window'.  In terms of design, code, testing, security measures, providing access and information, there can be both technical as well as non technical mistakes. I would like to discuss some of the common mistakes and loopholes that the developers are prone to commit even if they score very high on the proficiency level.</span></span></span></p>
<p align="CENTER"><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: small;" color="#000000"><span face="Arial, sans-serif"><span size="2"><span id="more-12140"></span></span></span></span></p>
<ul>
<li><strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">In a design, individual elements do not matter, big picture does: </span></strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">It can be difficult to separate an eye for design with the ability to design. A captivating design is simple and attractive and not. Because of prejudice and bias, designers are not able to distinguish what should be included in the existing design and what should not be. They should not be tempted to use anything that does not integrate well with the existing design. It is absolutely not worth over committing the details and wasting time on it</span></li>
</ul>
<ul>
<li><strong><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: small;" color="#000000"><span face="Arial, sans-serif"><span size="2">Demanding Perfection in first attempt: </span></span></span></strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Too many people want everything perfect before they go live. While the coder makes all the efforts to get everything perfect, the Internet changes, someone presents  the same idea. “Getting there first” is often more important than “Getting there perfect” Apply the 80-20 rule to projects instead. It is better to wait to spend 80% of your resources polishing that last 20% once you've proven the stability of your site.</span></li>
</ul>
<ul>
<li><strong><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: small;" color="#000000"><span face="Arial, sans-serif"><span size="2">Not enough Unit Testing : </span></span></span></strong><span style="font-family: arial, helvetica, sans-serif; font-size: small;">It is the confidence biased towards the self written code that refrains the developer. It becomes hard to think of the scenarios and inputs that can break their code. Thus, the developer is not able to enhance his code to make it more rich and robust. Also, they get complacent when their code has to be reviewed by someone else and then is functionally checked by the QA.  A developer has to get into a different mindset keeping in consideration that all checks cannot be and ideally should not be incorporated into the code.  The method(s) has to be as generic as possible to allow extensibility  and it should be tested with respect to all the specifications. Ideally, even for a minor bug fix, a unit test case should be written.</span></li>
</ul>
<ul>
<li>
<p align="LEFT"><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: small;" color="#000000"><span face="Arial, sans-serif"><span size="2"><b>Exceptions</b></span></span></span></p>
<p align="LEFT"><em style="font-family: arial, helvetica, sans-serif; font-size: small;"><span color="#000000"><span face="Arial, sans-serif"><span size="2">Surpassing 	and suppressing exceptional conditions</span></span></span></em></p>
<p align="LEFT"><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Sometimes, the programmer is not specific enough in the type of exception they catch. Catching too general an exception type means that they may be inadvertently dealing with particular exceptions that would be best left to other code, higher up the call chain. Tune your exception catch blocks to be as specific as possible. The second mistake is more detrimental-the programmer doesn't want any exceptions leaving their code and so catches them all and ignores them. This is known as the empty catch block. Also,don't absorb exceptions with no logging and operation. Ignoring exceptions will save that moment but will create a chaos for maintainability later</span></p>
<p align="LEFT"><em style="font-family: arial, helvetica, sans-serif; font-size: small;"><span color="#000000"><span face="Arial, sans-serif"><span size="2"><span face="'times new roman', times" size="3">Inter wining Exception Handling and Business Logic</span></span></span></span></em></p>
<p align="LEFT"><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Don't manage business logic with exceptions. Use conditional statements instead. If a control can be done with if-else statement clearly, don't use exceptions because it reduces readability and performance  (e.g. null control, divide by zero control).eg. Null control with conditionals is not an alternative to catching NullPointerException. If a method may return null, control it with if-else statement. If a return may throw NullPointerException, it should be caught.</span></p>
</li>
</ul>
<ul>
<li><span style="font-family: arial, helvetica, sans-serif; font-size: small;"><strong><span style="color: #000000;" color="#000000"><span face="Arial, sans-serif"><span size="2"><b>Closing 	the source: </b></span></span></span></strong></span><span style="font-family: arial, helvetica, sans-serif; font-size: small;">One of the trickiest challenges for any company is determining how much to share with the people who use the software. Often the code itself grows more modular and better structured as others recompile the program and move it to other platforms. Just opening up the code forces you to make the info more accessible, understandable, and thus better. As they make the small tweaks to share the code, they feed the results back into the code base. Due to the trade off, developers are mostly indecisive of it.</span></li>
</ul>
<ul>
<li><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: small;" color="#000000"><span face="Arial, sans-serif"><span size="2"><b>Playing 	it fast and loose: </b></span></span></span><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Even though the developers are well aware of the possible security breaches, still not much is done to prevent them. Some of them are:</span></li>
</ul>
<p><span color="#000000" style="font-family: arial, helvetica, sans-serif; font-size: small;"><span face="Arial, sans-serif"><span size="2">1. <i>SQL 	injection or OS injection</i></span></span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;"><span color="#000000"><span face="Arial, sans-serif"><span size="2">2. <i style="font-family: 'times new roman', times; font-size: medium;">Cross-site 	scripting</i></span></span></span><span color="#000000" style="color: #000000;"><span face="Arial, sans-serif"><span size="2"> : By not validating the input that is given dynamically, the 	developer might invite these problems like compromising on data 	integrity, cookies can be set and read, user input can be 	intercepted. Malicious scripts can be executed by the client in 	the context of the trusted source.</span></span></span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;"><span style="color: #a2427c;" color="#a2427c"><span face="Arial, sans-serif"><span size="2"><i>3. I</i></span></span></span><span color="#000000"><span face="Arial, sans-serif"><span size="2"><i>mproper 	release of resources</i></span></span></span><span color="#000000"><span face="Arial, sans-serif"><span size="2">:</span></span></span><span style="color: #a2427c;" color="#a2427c"><span face="Arial, sans-serif"><span size="2"> </span></span></span><span style="color: #333333;" color="#333333"><span face="Arial, sans-serif"><span size="2">When</span></span></span><span style="color: #333333;" color="#333333"><span face="Arial, sans-serif"><span size="2"> the system resources such as memory, files, cookies, data 	structures, sessions, communication pipes, and so on have reached 	their end-of-life, they are disposed off. Attackers can exploit 	improper shutdown to maintain control over those resources well 	after you thought you got rid of them. They  may sift through the disposed off  items, looking for sensitive data. They can potentially be 	useful to them.</span></span></span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;"><span color="#000000" style="color: #000000;"><span face="Arial, sans-serif"><span size="2"><i>4. Use 	of insufficiently random values:</i></span></span></span><span color="#333333" style="color: #333333;"><span face="Arial, sans-serif"><span size="2">The developer  may depend on randomness without even knowing it, such as when 	generating session IDs or temporary file names. Pseudo-Random Number 	Generators (PRNG) are commonly used, but a variety of things can go 	wrong. Once an attacker can determine which algorithm is being used,  they can guess the next random number often enough to launch a 	successful attack after a relatively small number of tries.</span></span></span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;"><span color="#000000" style="color: #000000;"><span face="Arial, sans-serif"><span size="2"><i>5. Client 	side security: </i></span></span></span><span color="#000000" style="color: #000000;"><span face="Arial, sans-serif"><span size="2">The 	developer should not</span></span></span><span color="#000000" style="color: #000000;"><span face="Arial, sans-serif"><span size="2"><i> </i></span></span></span><span color="#333333" style="color: #333333;"><span face="Arial, sans-serif"><span size="2">trust 	the client to perform security checks on behalf of your server. 	Attackers can reverse engineer your client and write their own 	custom clients. The consequences will vary depending on what the security checks are protecting, but some of the more common targets 	are authentication, authorization, and input validation.</span></span></span></span></p>
<p><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: small;" color="#000000"><span face="Arial, sans-serif"><span size="2">Developers make such errors for two main reasons. First, they may be operating under the mistaken assumption that a given function is too obscure to be vulnerable, they fail to grasp the extent to which attackers may be willing to analyze their application flows to find weaknesses. More often, however, they simply haven't considered how important a given function might be to the overall security of their application. As applications grow more complicated and their functions are distributed across multiple systems and resources, it's particularly easy to lose track of the big security picture.</span></span></span></p>
<ul>
<li><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: small;" color="#000000"><span face="Arial, sans-serif"><span size="2"><b>Delegating 	too much to frameworks : </b></span></span></span><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Sometimes the magic tools lead only to confusion. By abstracting functionality and assuming what we want, frameworks can all too often leave developers at a loss for what's gone wrong in their code. This is where the developer gets bounded within the limitations of framework. Framework should be chosen only if it has a utility, and is inevitable in the project, keeping in mind that it should not tie you down and restrict you to extend or customize your code.</span></li>
</ul>
<ul>
<li><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: small;" color="#000000"><span face="Arial, sans-serif"><span size="2"><b>Reinventing 	the wheel : </b></span></span></span><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Writing your own libraries just because you think you know a better way to code can come back to haunt you. So being obsessed with writing your own logic without the help of an inbuilt function is like wasting time and efforts. Accepting and using libraries that are ready made, freely available and easy to use which solve your purpose is a stitch in time saves nine.</span></li>
</ul>
<p><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: small;" color="#000000"><span face="Arial, sans-serif"><span size="2">This is not an exhaustive list of the mistakes. But the ones which are the major ones. The other side of mistakes is that they are developer friendly. They act as a driver to push them get better and better and also lead to useful findings and discoveries. There would be no errors or exceptions if nobody ever had an encounter with them <img src='http://xebee.xebia.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  The important thing is to accept them with an open mindset, deal and resolve if it is not possible to eliminate it.</span></span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;" face="Arial, sans-serif"><span size="2"><br />
</span></span></p>
<p align="CENTER">&nbsp;</p>
<div dir="ltr" id=":xh"></div>
<img src="http://feeds.feedburner.com/~r/Xebia/Xebee/~4/ef1HIvcm6h4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://xebee.xebia.in/2012/02/28/to-err-is-a-developer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://xebee.xebia.in/2012/02/28/to-err-is-a-developer/</feedburner:origLink></item>
		<item>
		<title>Using Spring 3.1 Profiles To Achieve PaaS Portability</title>
		<link>http://feedproxy.google.com/~r/Xebia/Xebee/~3/DdThwT16xk0/</link>
		<comments>http://xebee.xebia.in/2012/02/27/using-spring-3-1-profiles-to-achieve-paas-portability/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 17:21:04 +0000</pubDate>
		<dc:creator>Shekhar Gulati</dc:creator>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Cloud Foundry]]></category>
		<category><![CDATA[openshift]]></category>
		<category><![CDATA[cloudfoundry]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring Roo]]></category>

		<guid isPermaLink="false">http://xebee.xebia.in/?p=12349</guid>
		<description><![CDATA[Spring 3.1 release introduced a much awaited feature called Profiles which allows you to register different beans in different environments. In this blog we will take a look at how we can use profiles feature to run the same application without any code change in both OpenShift Express and Cloud Foundry. Creating a sample Spring [...]]]></description>
			<content:encoded><![CDATA[<p>Spring 3.1 release introduced a much awaited feature called Profiles which allows you to register different beans in different environments. In this blog we will take a look at how we can use profiles feature to run the same application without any code change in both OpenShift Express and Cloud Foundry.<span id="more-12349"></span></p>
<p><strong>Creating a sample Spring MongoDB Application</strong></p>
<p>I will use Spring Roo to create a simple bookshop application. Fire up the Roo shell and execute the following commands.</p>
<pre class="brush: plain; title: ; notranslate">
project --topLevelPackage com.xebia.bookshop --projectName bookshop
mongo setup --databaseName bookshop --host localhost --port 27017
entity mongo --class ~.domain.Book --testAutomatically --identifierType org.bson.types.ObjectId
field string --fieldName title --notNull
field string --fieldName author --notNull
field number --type double --fieldName price --notNull
repository mongo --interface ~.repository.BookRepository --entity ~.domain.Book
service --interface ~.service.BookService
web mvc setup
web mvc all --package ~.web
</pre>
<p>This will create a simple bookshop application. You can deploy this application on local tomcat using mvn tomcat:run. Please make sure you have MongoDB running on your local system.</p>
<p><strong>Deploying on OpenShift Express</strong></p>
<p>OpenShift Express supports two forms of deployment one is source code deployment which I showed in my last two blogs and other is war/binary deployment. In this blog I will show you how to deploy war to the Express cloud. Before we can deploy the application to OpenShift Express we first need to create bookshop application. To create the application execute the following command. You need rhc ruby gem to execute the command.</p>
<pre class="brush: plain; title: ; notranslate">
rhc-create-app -l &lt;rhlogin&gt; -a bookshop -t jbossas-7.0
</pre>
<p>It will prompt for the password. Now that you have created the application you should embed MongoDB cartridge in your application.</p>
<pre class="brush: plain; title: ; notranslate">
rhc-ctl-app -l &lt;rhlogin&gt; -a bookshop -e add-mongodb-2.0
</pre>
<p>Now that we have created the application and added the MongoDB cartridge we need to make change in our Spring application. We need to change applicationContext-mongo.xml file to have correct values for MongoDB factory. The values which exist are for application running on your local system. To change these values to OpenShift ones add a profile as shown below.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;beans profile=&quot;openshift&quot;&gt;
 &lt;mongo:db-factory dbname=&quot;${mongo.name}&quot; host=&quot;${OPENSHIFT_NOSQL_DB_HOST}&quot;
 port=&quot;${OPENSHIFT_NOSQL_DB_PORT}&quot; username=&quot;${OPENSHIFT_NOSQL_DB_USERNAME}&quot;
 password=&quot;${OPENSHIFT_NOSQL_DB_PASSWORD}&quot; /&gt;
 &lt;/beans&gt;
</pre>
<p>You also need to mention one context-param in web.xml to tell which profile is active. To do it add the following context-param.</p>
<pre class="brush: xml; title: ; notranslate">
   &lt;context-param&gt;
		&lt;param-name&gt;spring.profiles.active&lt;/param-name&gt;
		&lt;param-value&gt;openshift&lt;/param-value&gt;
	&lt;/context-param&gt;
</pre>
<p>Now build the project using mvn clean install -Dtest=maven.test.skip=true and copy to war file to deployments folder in OpenShift bookshop application. Also change the name of war to ROOT.war otherwise you application will be available at url_of_application/bookshop.<br />
Now to deploy do the following in deployments folder.</p>
<pre class="brush: plain; title: ; notranslate">
git add .
git commit -a -m &quot;adding bookshop application&quot;
git push
</pre>
<p>Wait for application to get deployed and see your application running at <a href="http://bookshop-random.rhcloud.com/">http://bookshop-random.rhcloud.com/</a></p>
<p><strong>Deploying to Cloud Foundry</strong></p>
<p>To deploy the bookshop application to Cloud Foundry we just need to add one more profile as shown below.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;beans profile=&quot;cloud&quot;&gt;
	&lt;cloud:mongo-db-factory id=&quot;mongoDbFactory&quot;/&gt;
&lt;/beans&gt;
</pre>
<p>In web.xml change the value of spring.profiles.active to cloud and create a war. To deploy to Cloud Foundry follow the following steps</p>
<ol>
<li>Download the Cloud Foundry <a href="http://rubygems.org/gems/vmc">VMC Ruby gem</a></li>
<li>Build the project using Maven. Do mvn clean install -Dmaven.test.skip=true</li>
<li>Once you have installed the vmc gem go to target folder and do vmc push.  This command will prompt you for creating a MongoDB service say yes to  that and you application will be deployed to Cloud Foundry cloud.</li>
<li>You can check the running application at <a href="http://bookshop.cloudfoundry.com/">http://bookshop.cloudfoundry.com/</a></li>
</ol>
<p>That's it for this blog. I think you will agree that Spring Profiles feature is very useful and powerful.</p>
<img src="http://feeds.feedburner.com/~r/Xebia/Xebee/~4/DdThwT16xk0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://xebee.xebia.in/2012/02/27/using-spring-3-1-profiles-to-achieve-paas-portability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://xebee.xebia.in/2012/02/27/using-spring-3-1-profiles-to-achieve-paas-portability/</feedburner:origLink></item>
		<item>
		<title>JavaScript client for web service using CXF</title>
		<link>http://feedproxy.google.com/~r/Xebia/Xebee/~3/uyrldHSDw_A/</link>
		<comments>http://xebee.xebia.in/2012/02/24/javascript-client-for-web-service-using-cxf/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 08:35:07 +0000</pubDate>
		<dc:creator>Mukesh Shah</dc:creator>
				<category><![CDATA[Apache CXF]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://xebee.xebia.in/?p=12100</guid>
		<description><![CDATA[Recently, I was looking for a Java Script client to test my Web Services. After my recent findings on CXF, I found out that it can also create JavaScript clients using tools. Since existing tools had ANT support for generating Java Script client and my current requirements was to use maven. After not finding any [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was looking for a Java Script client to test my Web Services. After my recent <a href="http://xebee.xebia.in/2012/01/25/what-made-me-to-choose-cxf-over-axis2/">findings on CXF</a>, I found out that it can also create JavaScript clients using tools. Since existing tools had ANT support for generating Java Script client and my current requirements was to use maven. After not finding any such configuration, I dig thoroughly the cxf-codegen-plugin, I came up with below configuration for maven to generate JavaScript artifacts.<br />
<span id="more-12100"></span><br />
Below are the guidelines to generate JavaScript artifacts and integrate it with existing JavaScript client.</p>
<p><strong>Create a maven based web project (or use your existing web project) and modify pom.xml as below</strong></p>
<pre class="brush: plain; title: ; notranslate">
&lt;plugin&gt;
	&lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
	&lt;artifactId&gt;cxf-codegen-plugin&lt;/artifactId&gt;
	&lt;version&gt;2.5.2&lt;/version&gt;
	&lt;executions&gt;
		&lt;execution&gt;
			&lt;configuration&gt;
				&lt;sourceRoot&gt;${project.build.directory}&lt;/sourceRoot&gt;
				&lt;wsdlOptions&gt;
					&lt;wsdlOption&gt;
						&lt;wsdl&gt;http://cxf_ws.cloudfoundry.com/sampleService?wsdl&lt;/wsdl&gt;
					&lt;/wsdlOption&gt;
				&lt;/wsdlOptions&gt;
			&lt;/configuration&gt;
			&lt;goals&gt;
				&lt;goal&gt;wsdl2js&lt;/goal&gt;
			&lt;/goals&gt;
		&lt;/execution&gt;
	&lt;/executions&gt;
&lt;/plugin&gt;
</pre>
<p>In the pom mentioned above, sourceRoot tag in the configuration has been used to indicate directory to generate artifacts and wsdlOption has been used to mention the wsdl file location.</p>
<p><strong>Execute below maven command to generate JavaScript artifacts.</strong></p>
<p>mvn generate-sources</p>
<p>Once you run above command, a new java script file gets generated at the mentioned destination directory, with the same name as wsdl definition name.</p>
<p><strong>Digging deeper into generated artifact.</strong></p>
<p>In brief about generated JavaScript artifact, There will be an operation function for every exposed web service operation and there will be a serialization and a deserialization functions for every operation function. The serialize function is used to convert the JavaScript object to an XML request format and the deserialize function converts the XML response to the corresponding JavaScript object.<br />
There will be a separate function which is used to map all these operation functions with their equivalent serialization/deserialization functions. This function is know as service function and gets generated by reading the service definition from the mentioned wsdl file in pom. The generated service function code starts with a comment given below.</p>
<pre class="brush: plain; title: ; notranslate">
// Definitions for service: {http://test.com/}SampleCXFServiceService
// Javascript for {http://test.com/}SampleCXFService
</pre>
<p><strong>Integrating generated artifact with JavaScript client code.</strong></p>
<p>Modify your client side JavaScript to incorporate generated artifact changes. For example if wsdl definition name is SampleCXFService then a  SampleCXFService.js file will get generated as an artifact. You need to include this SampleCXFService.js artifact in your client js. Other than that you also need to <a href="http://www.apache.org/dyn/closer.cgi?path=/cxf/2.5.2/apache-cxf-2.5.2.zip">download</a> CXF JavaScript utility file (cxf-utils.js) and include it in client JavaScript. This is a part of CXF distribution and can be found from apache-cxf-2.5.2-src\rt\javascript\javascript-rt\src\main\resources\org\apache\cxf\javascript location.</p>
<p>Add a JavaScript function (i.e. invokeService() ) to invoke the web service and store the result in a variable or use it directly(like in the snippet given below).</p>
<p><strong>Code snippet for client JavaScript:</strong></p>
<pre class="brush: plain; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;cxf-utils.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;SampleCXFService.js&quot;&gt;&lt;/script&gt;

&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;
	var SampleService = new test_com__SampleCXFService();
	SampleService.url = &quot;http://cxf_ws.cloudfoundry.com/sampleService&quot;;

	function invokeService()
	{
	  var name = $('#inputTextId').val();
	  &lt;!-- Operation function invocation by passing name as input parameter --&gt;
	  SampleService.getMessage(successResponse, errorResponse, name);
	}

	&lt;!-- Function gets called for a successResponse. --&gt;
	function sucessResponse(response)
	{
		&lt;!-- Using response text to populate result on UI on success--&gt;
		$('#result').text(response.getReturn());
	}

	&lt;!-- Function gets called for an error. --&gt;
	function errorResponse(error)
	{
  	    alert(&quot;Error message is &quot; + error);
	}
&lt;/script&gt;
</pre>
<p>The first 2 lines are used to get the reference of web service using service function. The  invokeService() function simply delegating call to operation functions. There are two callback functions also in client js.</p>
<ul>
<li>successResponse(response) : This function retrieves the response object in callback process and gets called after a successful response.</li>
<li>errorResponse(error): In case of web service invocation failure, this function retrieves the error message in the callback process and display that message in an alert.</li>
</ul>
<p><strong>References:</strong></p>
<p><a href="http://cxf.apache.org/docs/overview.html">http://cxf.apache.org/docs/overview.html</a><br />
<a href="http://cxf.apache.org/docs/wsdl-to-javascript.html">http://cxf.apache.org/docs/wsdl-to-javascript.html</a></p>
<img src="http://feeds.feedburner.com/~r/Xebia/Xebee/~4/uyrldHSDw_A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://xebee.xebia.in/2012/02/24/javascript-client-for-web-service-using-cxf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://xebee.xebia.in/2012/02/24/javascript-client-for-web-service-using-cxf/</feedburner:origLink></item>
		<item>
		<title>Android Social API’s and Updates in Ice Cream Sandwich</title>
		<link>http://feedproxy.google.com/~r/Xebia/Xebee/~3/iw7blIoJ94I/</link>
		<comments>http://xebee.xebia.in/2012/02/23/android-social-apis/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 09:10:50 +0000</pubDate>
		<dc:creator>Paramvir Singh</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Mobile Apps]]></category>
		<category><![CDATA[Social API]]></category>
		<category><![CDATA[android development]]></category>
		<category><![CDATA[Android4.0]]></category>
		<category><![CDATA[ContactsContract]]></category>
		<category><![CDATA[Ice Cream Sandwich]]></category>
		<category><![CDATA[ICS]]></category>

		<guid isPermaLink="false">http://xebee.xebia.in/?p=12204</guid>
		<description><![CDATA[Giving users “power to share ” seamlessly  is a feature we will find in all popular and frequently used Mobile applications. Being social is crucial for applications. Users love to share and Android knows that. Acting prudently, Android has provided API's as well as inherent support using Intents for social integration. Here, I will explicate the [...]]]></description>
			<content:encoded><![CDATA[<p>Giving users “power to share ” seamlessly  is a feature we will find in all popular and frequently used Mobile applications. Being social is crucial for applications. Users love to share and Android knows that. Acting prudently, Android has provided API's as well as inherent support using <a href="http://developer.android.com/reference/android/content/Intent.html" target="_blank">Intents</a><b> </b>for social integration. Here, I will explicate the API's developers can use to integrate social features with their applications.<span id="more-12204"></span></p>
<p><b> </b></p>
<p><b> </b><b>ContactsContract</b>:</p>
<p>We (developers) usually use this API to get user's contacts list. The important thing about this API is that one Contact row has different information(phone number, email id, name, photo etc.) for the same person aggregated from different sources like local contacts book, Facebook account, Skype, Gmail account etc. The whole contacts database is <b>extensible </b>and is managed in a <b>three tier data model </b>using following three classes under ContactsContract package:</p>
<ul>
<li>RawContacts</li>
<li>Data</li>
<li>Contacts<img src="http://xebee.xebia.in/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" title="More..." /></li>
</ul>
<div>
<div id="attachment_12251" class="wp-caption aligncenter" style="width: 660px"><a rel="attachment wp-att-12251" href="http://xebee.xebia.in/2012/02/23/android-social-apis/contactscontract-3/"><img class="size-large wp-image-12251   " height="400" width="650" title="ContactsContract" src="http://xebee.xebia.in/wp-content/uploads/2012/02/ContactsContract2-1024x621.jpg" /></a><p class="wp-caption-text">ContactsContract</p></div>
</div>
<div>
<div>
<dl id="attachment_12184"> </dl>
</div>
</div>
<p>We can do basic operations like insert, update, delete as well as query the contacts database. For example, to insert a contact :</p>
<pre class="brush: java; title: ; notranslate">
ContentValues values = new ContentValues();
values.put(RawContacts.ACCOUNT_TYPE, accountType);
values.put(RawContacts.ACCOUNT_NAME, accountName);
Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);
</pre>
<p><b>What Android4.0 (ICS) added to it:</b></p>
<ul>
<li><b>Easy access with high resolution photos</b>: In this version, the people to which users are most connected will be arranged into a magazine like UI. According to Android developer team “This is to support emotional connections between humans and the devices they carry”.<br />
For this purpose higher resolution pictures will be used ( 256x256 instead of 98x98).</li>
</ul>
<ul>
<li><b>Social Stream for Sync Adapters: </b>Through this “biggest new edition”, social applications can display recent online activities of all the contacts in the device user’s contact list. The activities would be visible in the contact list itself. This is achieved by <b>Sync Adapters. </b>Sync adapters can synchronize the raw contacts data  available locally on the device with the contact data available in the cloud resources like Facebook, Skype and other social  apps. In current update, the Sync Adapters now can also fetch update status, photos and other user posts via social stream. Following two classes are important:</li>
</ul>
<ol>
<li><a href="http://developer.android.com/reference/android/provider/ContactsContract.Contacts.StreamItems.html" target="_blank">StreamItems</a>: Stream items contain the recent social updates of a particular user under its Raw Contact data. Also contain the comments, photos and other useful information related to that social update.</li>
<li><a href="http://developer.android.com/reference/android/provider/ContactsContract.StreamItems.StreamItemPhotos.html" target="_blank">StreamItemPhotos</a>: Contains the photos related to a single social update by the user.</li>
</ol>
<ul>
<li><b>The “ME” Contact: </b>This will contain device user’s personal contact  information and profile data. Applications can access the “ME” profile information for display and verification purpose.</li>
</ul>
<ul>
<li><b>Adding a new connection is easy: </b>This is another important update in ICS. Now user can connect to a person on any social website (Facebook, Google plus) by clicking an option in the contact detail page of that person in the device's people app.</li>
</ul>
<div><b><br />
</b></div>
<p><b>NFC Reloaded with Beam:</b></p>
<p>NFC or Near Field Communication is one of the latest buzzwords in mobile sphere. Besides its acclaimed uses in e-commerce, mobile payments and enterprises it is becoming a new media of sharing. This "<a href="http://www.slideshare.net/ParamvirSingh1/near-field-communication-10509831" title="Slides: NFC, the &quot;tap&quot; technology" target="_blank">tap</a>" technology can be used for exchanging any type of data between two mobile devices.</p>
<p>Good thing is, NFC APIs are exposed to the developers and are available under <a href="http://developer.android.com/reference/android/nfc/package-summary.html" title="android.nfc packager summary" target="_blank">android.nfc</a> package.</p>
<p>In 4.0, a new application "Beam" is introduced to make tap-and-share feature  more intuitive. Using Beam, users can share apps, contacts, music, videos and other media contents and files instantly by single tap or touch of two NFC enabled devices.</p>
<p>Beam uses "NDEF push" to transfer data between devices when two devices come in close proximity. NDEF is a special format for NFC data and stands for "NFC Data Exchange Format". Two important classes used for NFC communication are:</p>
<ul>
<li>NDEFMessage: Container for NDEFRecords.</li>
<li>NDEFRecord: Contains the payload data, id and the type of data. if payload data is large, it is divided into   more than one NDEFRecords.</li>
</ul>
<p><b><br />
</b><strong>Intents To Share:</strong></p>
<p>Intents are the mainstay of Android system. Apart from regular usage of intents to start another activities, passing data across activities and applications, receiving broadcasts and triggering a service, intents can perform an interesting job for us: to give apps the power to "share" and that without a much extra effort. The simplest case is to create "Activity chooser " dialog to chose a social app capable of sharing:</p>
<pre class="brush: java; title: ; notranslate">
Intent intent=new Intent(android.content.Intent.ACTION_SEND);
intent.setType(&quot;text/plain&quot;);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
// Add data to the intent, the receiving app will decide what to do with it.
intent.putExtra(Intent.EXTRA_SUBJECT, “Here goes the subject...”);
intent.putExtra(Intent.EXTRA_TEXT, “Here goes the message body...”);
&lt;pre&gt;</pre>
<p><strong>Updates in 4.0: </strong>In this version, a new tool is introduced : <a href="http://developer.android.com/reference/android/widget/ShareActionProvider.html" title="ShareActionProvider" target="_blank">ShareActionProvider</a> . This will create a "share" button in the Action Bar. It is a sub-class of ActionProvider. ActionProviders are responsible for creating views to do the required action that will accomplish a given task. ShareActionProvider will create view for "share" task.</p>
<p>For using ShareActionProvider, modify the onCreateOptionsMenu() method in the Activity:</p>
<pre class="brush: java; title: ; notranslate">

public boolean onCreateOptionsMenu(Menu menu) {

MenuItem menuItem1 = menu.findItem(R.id.menu_item);

mShareActionProvider = (ShareActionProvider) menuItem1.getActionProvider();

mShareActionProvider.setShareHistoryFileName(&quot;custom_share_history.xml&quot;);

}
</pre>
<p>This will create a list of share targets the user can chose from to perform the sharing. The order of the share targets will depend on the past usage of the user which is saved in a history file. We can either use the default history file or we can maintain a custom history file and use that file throughout the application.</p>
<p>The ICS release has brought exciting goodies for developers and updates in social API's are most appealing.</p>
<img src="http://feeds.feedburner.com/~r/Xebia/Xebee/~4/iw7blIoJ94I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://xebee.xebia.in/2012/02/23/android-social-apis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://xebee.xebia.in/2012/02/23/android-social-apis/</feedburner:origLink></item>
		<item>
		<title>Event Driven Architecture – EDA</title>
		<link>http://feedproxy.google.com/~r/Xebia/Xebee/~3/nk-DdoBJo-8/</link>
		<comments>http://xebee.xebia.in/2012/02/20/event-driven-architecture-eda/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 07:22:14 +0000</pubDate>
		<dc:creator>Anant</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://xebee.xebia.in/?p=11515</guid>
		<description><![CDATA[We live in an event driven world. Companies, employees and even animals survive and thrive in this world on their ability to respond to any given opportunities and threats. These opportunities and threats occur in more unpredictable manner then any economic theory or sixth sense can map or forecast them. So to handle them we [...]]]></description>
			<content:encoded><![CDATA[<p>We live in an event driven world. Companies, employees and even animals survive and thrive in this world on their ability to respond to any given opportunities and threats.</p>
<p>These opportunities and threats occur in more unpredictable manner then any economic theory or sixth sense can map or forecast them. So to handle them we need event based handlers that are externally determined. <span id="more-11515"></span></p>
<p>Have a look at the below picture:</p>

<a href='http://xebee.xebia.in/2012/02/20/event-driven-architecture-eda/eda-2/' title='EDA'><img src="http://xebee.xebia.in/wp-content/uploads/2012/02/EDA1.bmp" class="attachment-thumbnail" alt="EDA" title="EDA" /></a>

<p>To give more sense to above picture:</p>
<p><strong>Event :</strong> It can be any damn thing which happens in this world or even universe like in this picture a striking light/ football match/finding water on moon etc. etc.</p>
<p><strong>Event listener &amp; generator :</strong>This element will listen an event (as a listener) and thereafter creates and send a signal to the Event Engine (as a generator).</p>
<p><strong>Event Engine :</strong> Upon receiving a signal this element will process the details and then send it to clients.</p>
<p><strong>Client :</strong> They all will catch the event and interrupt in the manner they want.</p>
<p>Gear up your imagination with the example below:</p>
<p>Imagine your air flight is running late (Event for us, although not the pleasant one). Now what could be the action plan in perfect world:</p>
<p>Your booked cab can be notified for the same so that they can adjust their bookings by assigning a new cab to you and may be book your cab for someone else.</p>
<p>In the same manner hotel reservation can also be handled when notified about your air flight delay.</p>
<p>Even your travel agent can look for other alternative routes or any other flights which can be taken if you have tight schedule. He can even notify the people at seminar you suppose to attend for your delayed plan.</p>
<p>The most important thing to catch here is  <em>"when an air flight gets delayed, the airline doesn't know any of these above cases."</em></p>
<p>Airline will just announce the delay or cancellation of a flight (which is a Event). The event will be announced to everything which says it's interested in that flight, which may be no one, a passenger or may be several agents for each passenger on the flight. The event listener &amp; generator (cab, hotel and travel agent) decides how to react to the notification. Thus processing the notification by re assigning in case of cab or re booking in case of hotel (Event Engine). After that they will send the confirmation notification to clients.</p>
<p><strong>Magento</strong> (CMS in PHP) uses EDA as its core of existence. Let's look how can we define an event and its affect in Magento.</p>
<p>Within Magento you can dispatch an event as simple as by calling a method like :</p>
<p><em>BaseController</em>::dispatchEvent('custom_event', array('data1'=&gt;$data));</p>
<p>This method accepts two parameters - event unique identifier and associative array of data passed to listener.</p>
<p>In Listener custom class, all the data dispatched by event will be captured and a listener would be added :</p>
<p>class Listener<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;/**<br />
&nbsp;&nbsp;&nbsp;&nbsp;* function to take out the 'object' key from $data passed to Listener<br />
&nbsp;&nbsp;&nbsp;&nbsp;*/<br />
&nbsp;&nbsp;&nbsp;&nbsp;public static function addListener($data)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$object = $data-&gt;getEvent()-&gt;getObject();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$object-&gt;doSomething();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</p>
<p>In some cases, we need to process the request as per the event received.</p>
<p>public static function processEvent($object)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;foreach($object-&gt;getEvent() as $event)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSomeprocess($event);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</p>
<p>The above Airline example is a simple case of Event Driven Architecture (EDA), it has more complex parts named as <strong>Complex event processing (CEP)</strong></p>
<p>Complex event processing (CEP) in above cases could be like delay in flight can affect the airport management, crew allocation, opening of gates, passengers intimation, subsequent delay in on going journey of that flight.</p>
<p>If you notice that event (Air flight delay) which is fired resulted in some services. Thus a service is triggered by incoming events. Hence, making its way to <strong>Service oriented architecture</strong> (SOA).</p>
<p>So in today's IT world where we talk more about events and services, we can easily state that  <strong>SOA 2.0</strong> evolves with the implications of both SOA and EDA architectures.</p>
<p>Hopefully, in next blog we will discuss more about SOA and EDA as winning combination.</p>
<img src="http://feeds.feedburner.com/~r/Xebia/Xebee/~4/nk-DdoBJo-8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://xebee.xebia.in/2012/02/20/event-driven-architecture-eda/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://xebee.xebia.in/2012/02/20/event-driven-architecture-eda/</feedburner:origLink></item>
		<item>
		<title>Liferay Service Builder</title>
		<link>http://feedproxy.google.com/~r/Xebia/Xebee/~3/_QKXcGIo-L8/</link>
		<comments>http://xebee.xebia.in/2012/02/16/liferay-service-builder/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 17:52:51 +0000</pubDate>
		<dc:creator>Robin Nagpal</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Liferay]]></category>
		<category><![CDATA[Portal]]></category>
		<category><![CDATA[Service Builder]]></category>

		<guid isPermaLink="false">http://xebee.xebia.in/?p=11999</guid>
		<description><![CDATA[Why another blog on Service builder ? Since you have landed on this post, we know that you are looking for a good reference for Liferay Service Builder, and by now you might be frustrated by the minimal documentation from Liferay, or are enervated by scrolling down the liferay forums, or you have been hopping [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Why another blog on Service builder ?</strong><br />
Since you have landed on this post, we know that you are looking for a good reference for Liferay Service Builder, and by now you might be frustrated by the minimal documentation from Liferay, or are enervated by scrolling down the liferay forums, or you have been hopping from one  blog to other since long. There is not even a single sufficient article/blog  which explains service builder in detail. I and my colleague <a href="http://xebee.xebia.in/author/pgarg/">Pratik</a>, faced the same problem some time ago, and we then decided to write a series of blogs which will help you in getting a good understanding of Service Builder.</p>
<p><span id="more-11999"></span><br />
We are using Liferay 5.2.3 for developing a web based collaboration portal with a very huge user base. Portal requires development of many custom portlets, which means handling CRUDs around old and new entities. We then started searching for some tools which could increase our pace of development of portlets and we came across Liferay Service Builder. This tool has great power but its effective usage requires good level of understanding. So here is the series of upcoming blogs which will introduce the liferay service builder concepts. We will start with "Service Builder Basics" and then dive deeper into advanced topics.  Here is a snapshot of different spaces.</p>
<ol>
<li>Service Builder Basics</li>
<li>Service Builder Finders</li>
<li>Advantages , Disadvantages , Tips and Tricks</li>
<li>Remote Services</li>
<li>Caching</li>
<li>Transactions</li>
<li>Testing</li>
</ol>
<p><strong>What is service builder ?</strong><br />
Liferay provides a code generation utility called Service Builder, created with an intention to get rid of most boilerplate work during portlet development. Liferay internally uses Spring and Hibernate, which basically means if you are not using service builder, you will end up writing the service layers, pojo’s , dao’s , sql scripts and configuration files if not using annotations. Service Builder does all this with little instructions. To get a good hang of service builder lets walk through an example and run though the various stages starting with concept of an entity and ending with the deployment of that entity inside a portlet with suitable views.</p>
<p><span style="font-size: large;"><strong>Email Example </strong></span><br />
Lets say we need an entity of “Email” which has attributes such as  from , to , cc, body, date and text.</p>
<p><span style="font-size: large;"><strong>Configuration</strong></span><br />
Create a service.xml file in your portlet as location - "portlet/docroot/WEB-INF/service.xml".  service.xml should stick to <a href="http://www.liferay.com/dtd/liferay-service-builder_5_2_0.dtd%20">this</a> schema definitions. Add entry for Email entity in service.xml.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;entity name=&quot;Email&quot; local-service=&quot;true&quot; remote-service=&quot;false&quot; table=&quot;Email&quot;&gt;
   	 &lt;column name=&quot;id&quot; type=&quot;long&quot; primary=&quot;true&quot;&gt;
   	 &lt;column name=&quot;to&quot; type=&quot;String&quot;&gt;
   	 &lt;column name=&quot;from&quot; type=&quot;String&quot;&gt;
   	 &lt;column name=&quot;subject&quot; type=&quot;String&quot;&gt;
   	 &lt;column name=&quot;content&quot; type=&quot;String&quot;&gt;
   	 &lt;column name=&quot;date&quot; type=&quot;Date&quot;&gt;

   	 &lt;!--  Finders --&gt;
   	 &lt;finder name=&quot;To&quot; return-type=&quot;Collection&quot;&gt;
   		 &lt;finder-column name=&quot;to&quot;&gt;&lt;/finder-column&gt;
          &lt;/finder&gt;
   	 &lt;finder name=&quot;From&quot; return-type=&quot;Collection&quot;&gt;
   		 &lt;finder-column name=&quot;from&quot;&gt;&lt;/finder-column&gt;
         &lt;/finder&gt;
   	 &lt;finder name=&quot;Subject&quot; return-type=&quot;Collection&quot;&gt;
   		 &lt;finder-column name=&quot;subject&quot;&gt;&lt;/finder-column&gt;
         &lt;/finder&gt;
   	&lt;finder name=&quot;Date&quot; return-type=&quot;Collection&quot;&gt;
   		 &lt;finder-column name=&quot;date&quot;&gt;&lt;/finder-column&gt;
         &lt;/finder&gt;
&lt;/entity&gt;
</pre>
<ul>
<li>entity refers to a new model which we want to create</li>
<li>name attribute refers to the name of the entity</li>
<li>column tag represents the different fields in entity or columns in table</li>
<li>type refers to the data-type . Please note you cannot establish one-to-many or many-to-many relationships using this.</li>
<li>finder tag is used to create find utility methods</li>
</ul>
<p><span style="font-size: large;"><strong>Code Generation</strong></span><br />
Run "ant build-service" from the command (will work only if liferay bin is included in your path). Below is the explanation of all the classes that will be generated. Liferay strictly follows program to interface design so every impl will have its corresponding interface.</p>
<p><span style="font-size: large;"><strong>Generated classes.</strong></span><br />
Service Builder generates three types of classes i.e. Model, Service and Persistence</p>
<p><span style="font-size: medium;"><strong> </strong></span></p>
<p><span style="font-size: medium;"><strong>Model Objects</strong></span></p>
<p>These objects are nothing but the data/value objects.</p>
<p><a href="http://xebee.xebia.in/2012/02/16/liferay-service-builder/email_model_1/" rel="attachment wp-att-12036"><img src="http://xebee.xebia.in/wp-content/uploads/2012/02/email_model_1.png" title="email_model_1" class="aligncenter size-full wp-image-12036" width="650" height="400" /></a>Following is the list of model classes generated when you run service builder</p>
<ul>
<li><strong>BaseModel</strong> - This is the Base class provided by liferay which is extended by every model/entity object. This is analogous to object class in Java.<strong> </strong></li>
<li><strong>BaseModelImpl </strong>- Basic implementation provided by liferay for BaseModel.<strong> </strong></li>
<li><strong>EmailModel </strong>- Interface for the getters/setters of all the fields that are specified in the service.xml for this entity.<strong> </strong></li>
<li><strong>Email </strong>- This is interface for Email entity.<strong> </strong></li>
<li><strong>EmailModelImpl</strong> - Implementation for the EmailModel methods and couple of other utility methods like clone , toString etc.</li>
<li><strong>EmailImpl</strong> - By Default this class is empty. The purpose of this class is to provide a placeholder to have custom methods on the entity (which are not generated by default) . For instance, if you want to make this entity rich by having  methods like validate “to” field , you can add method something like this
<pre class="brush: java; title: ; notranslate"> …
&lt;pre&gt;public boolean validateToAddress(){
//Add code to validate this.to
}
…
</pre>
<p>Now once you add this method in the Impl , you need to have this inside a corresponding interface also which is Email. To add this method signature just run the "build-service" target again and method will be added to EmailInterface. Please note that the method cannot be added inside the EmailModelImpl because in case if we change the entity in future or just run the ant build-service, those custom written methods will get deleted.</li>
</ul>
<p><span style="font-size: medium;"><strong> </strong></span></p>
<p><span style="font-size: medium;"><strong>Service Objects</strong></span></p>
<p><span style="font-size: medium;"><strong> </strong></span> Once you have you model objects, you need services to operate on them, and service builders generates these as well</p>
<div width="100%"><a href="http://xebee.xebia.in/2012/02/16/liferay-service-builder/email_service/" rel="attachment wp-att-12018"><img src="http://xebee.xebia.in/wp-content/uploads/2012/02/email_service.png" title="email_service" class="aligncenter size-full wp-image-12018" width="650" height="283" /></a><br />
Following are the classes generated by service builder for service layer</div>
<ul>
<li><strong>EmailLocalService </strong>:  Interface containing all the crud operations that can be performed on the Email entity. for e.g add/delete/get/update/find<strong> </strong></li>
<li><strong>EmailLocalServiceBaseImpl</strong> : Implementation for the EmailLocalService .This class is injected will the serviceImpl’s and persistenceImpl’s of all entities present in the service.xml. One service may need to call other service to do business operations. Injection of these service and persistence impls fully equipts base impl to do such type of operations.<strong> </strong></li>
<li><strong>EmailLocalServiceImpl</strong> : This class has the same role as EmailImpl in the model layer. If you want to add custom methods in the service layer for this model, then you can add the implementation in this class and run the ant build-service, and the new method signature will be pushed into EmailLocalService as well.<strong> </strong></li>
<li><strong>EmailLocalServiceUtil</strong> : Since we are using spring, ideally we should be able to inject the EmailLocalServiceImpl instance into a java class of view layer (e.g ActionClasses in struts or PageClass in Wicked), but in liferay if you are using JSP Portlet , it will not be possible to inject this dependency . So this util contains the same method signatures as the EmailLocalService but with static qualifier, so that you can use them directly. Internally it will look up that impl from the spring context and then execute the methods on it.<strong> </strong></li>
<li><strong>EmailLocalServiceClp</strong> : Clp or ClassLoaderProxy objects are used to serialize the objects. In this case it will be used to serialize EmailLocalServiceImpl. These clps are used for remote services which will be discussed in detail later.</li>
</ul>
<p><span style="font-size: medium;"><strong>Persistence objects<br />
</strong></span></p>
<p>Persistence classes contain all the code for dealing with hibernate sessions and fetching the actual model objects</p>
<p><a href="http://xebee.xebia.in/2012/02/16/liferay-service-builder/email_persistence_1/" rel="attachment wp-att-12039"><img src="http://xebee.xebia.in/wp-content/uploads/2012/02/email_persistence_1.png" title="email_persistence_1" class="aligncenter size-full wp-image-12039" width="650" height="377" /></a></p>
<ul>
<li><strong> BasePersistence</strong> - BasePersistence class is provided by liferay which every persistence impl extends. Some of the methods are registerListener , unregisterListener which are used to associate listeners with events occurring on the Entity Table. for e.g addition of new entity.<strong> </strong></li>
<li><strong>SessionFactory</strong> - As the name suggests, this classes is used for the database sessions.We rarely have to deal directly with this class. This class is extended by the BasePersitenceImpl.<strong> </strong></li>
<li><strong>BasePersistenceImpl</strong> - Default implementation for the BasePersistence and SessionFactory.<strong> </strong></li>
<li><strong>EmailPersistence</strong> - Interface for the basic CRUD operation that can be done on the Email Model.</li>
<li><strong>EmailPersistenceImpl</strong> - Implementation for the EmailPersistence. Again this class is also injected with the persistence impl of all the entities specified in the service.xml. This persistence impl is <strong>not same</strong> as the ModelImpl or LocalServiceImpl, because you cannot write your custom methods in this class. If you have to create a custom persistence method then you need to create a finder. This will be discussed in our next blog.</li>
</ul>
<p><span style="font-size: medium;"><strong>Generated sql’s</strong></span></p>
<p><strong>tables.sql</strong> - This sql contains the basic template for table creation. This has to be tweaked as per the database used.</p>
<pre class="brush: sql; title: ; notranslate">
create table Email (
    id_ LONG not null primary key,
    to_ VARCHAR(75) null,
    from_ VARCHAR(75) null,
    subject VARCHAR(75) null,
    content VARCHAR(75) null,
    date_ DATE null
);
</pre>
<p><strong>indexes.sql</strong> : This sql lists the indexes on those fields which are specified as finders in the service.xml.</p>
<pre class="brush: sql; title: ; notranslate">
create index IX_936DE65F on Email (date_);
create index IX_19F9ECE3 on Email (from_);
create index IX_8DEFA35A on Email (subject);
create index IX_92C5C772 on Email (to_);
</pre>
<p><strong><br />
<span style="font-size: x-large;">Code Utilization</span></strong></p>
<p>Lets take the use case of displaying all the emails  that were created yesterday.  So, to fetch emails by date, our portlet will call service class, which will call persistence class, and this will return the list of emails created yesterday. Lets start in t the reverse order and see how to write custom methods in each layer.</p>
<p><strong>Persistence layer</strong></p>
<p>This finder entry shown below, which we added while creating our Email entity,  is responsible for creation of a finder method in EmailPersestenceImpl.java and  and also in EmailPersistence.java.</p>
<pre class="brush: xml; title: ; notranslate">
	&lt;finder name=&quot;Date&quot; return-type=&quot;Collection&quot;&gt;
   		 &lt;finder-column name=&quot;date&quot;&gt;
   	 &lt;/finder-column&gt;&lt;/finder&gt;
</pre>
<p>The method which gets added has the following signature:</p>
<pre class="brush: java; title: ; notranslate">
	public java.util.List&lt;com.xebia.general.model.email&gt; findByDate(
   	 java.util.Date date) throws com.liferay.portal.SystemException;
</pre>
<p><strong>Service Layer</strong></p>
<p>Our service layer should have a custom method which will take a date and then call the persistence layer to get all the emails corresponding to that date.  Our custom method will go into EmailLocalServiceImpl.java and will look like</p>
<pre class="brush: java; title: ; notranslate">
public  List&lt;email&gt; getAllEmailsByDate(Date createdDate) throws SystemException{
   		 List&lt;email&gt; emailsByDate = emailPersistence.findByDate(createdDate);
   		 return emailsByDate;
    }
</pre>
<p>After adding this method run service builder. Service Builder then pushes this method in the corresponding service and util classes. The new method that is added in EmailLocalService.java will look like</p>
<pre class="brush: java; title: ; notranslate">
	@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public java.util.List&lt;com.xebia.general.model.email&gt; getAllEmailsByDate(
   	 java.util.Date createdDate) throws com.liferay.portal.SystemException;
</pre>
<p>and in EmaiLocalServiceUtil.java</p>
<pre class="brush: java; title: ; notranslate">
	public static java.util.List&lt;com.xebia.general.model.email&gt; getAllEmailsByDate(
   	 java.util.Date createdDate) throws com.liferay.portal.SystemException {
   	 return getService().getAllEmailsByDate(createdDate);
    }
</pre>
<p><strong>Portlet code</strong></p>
<p>We now have the method for fetching emails by date in both persistence and service layer. Lets call the LocalServiceUtil class to get yesterday's emails</p>
<pre class="brush: java; title: ; notranslate">
List&lt;email&gt; emailsByDate = EmailLocalServiceUtil.getAllEmailsByDate(yesterday);
</pre>
<p>We would now like to conclude the "Service Builder Basics". After reading this post you should know: the classes generated by liferay, using of the generated classes, and placeholders for adding your custom code. In the next post we will add some entities in Email, and will then see how to use one-to-many, many-to-many, or write custom sqls by using finders.</p>
<img src="http://feeds.feedburner.com/~r/Xebia/Xebee/~4/_QKXcGIo-L8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://xebee.xebia.in/2012/02/16/liferay-service-builder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://xebee.xebia.in/2012/02/16/liferay-service-builder/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 10.102 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-03-05 13:33:28 -->

