tag:blogger.com,1999:blog-232577742024-03-13T13:34:50.832+05:30Sandarenu's BlogAll about Me and My Experiences...Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.comBlogger154125tag:blogger.com,1999:blog-23257774.post-75381093163586284242023-01-05T19:00:00.004+05:302023-01-05T19:00:57.836+05:30Getting Started with Kubernetes - Part 1<p> Kubernetes is an open-source platform for automating the deployment, scaling, and management of containerized applications. It has become the de-facto standard for container orchestration, and is widely used in production environments.<br /><br />If you're new to Kubernetes, you may find it overwhelming to get started. Fortunately, there are several tools and distributions that make it easier to get up and running with Kubernetes, even if you're just starting out.<br />One such tool is K3S, a lightweight Kubernetes distribution designed for easy installation and low resource usage.</p><p><a href="https://sandarenu.github.io/posts/introductons-to-kubernetes-part-1/">Find out how to install K3S in my new blog</a><br /><br /></p><div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-78829368736200245642016-03-22T23:07:00.001+05:302016-03-22T23:07:11.711+05:30Getting Started with React Native<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://facebook.github.io/react-native/">React Native</a> is a
framework that allows us to create Native Android and iOS applications
using JavaScripts by Facebook. It is a extention of <a href="http://facebook.github.io/react/">React JavaScript framework</a>
available for Web application development. With React-Native we can
create native android or iOS applications without knowing much about
native application development. It opens up the native application
development to web developers who knows JavaScript and CSS.<br />
<br />
<a href="http://sandarenu.github.io/post/getting-started-with-react-native/">Read more at my new blog >> </a></div>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-47526746494630127092016-02-12T04:35:00.001+05:302016-02-12T04:35:13.642+05:30Understanding Guava Lists.transform()<div dir="ltr" style="text-align: left;" trbidi="on">
Guava is a wonderful library by Google. Before Java 8 Guava was one of the best ways to use functional programming in Java.<br />
<br />
I’ve being using Guava in one of my projects and came accross an
strance issue reasontly. I had a list of items and I wanted to convert
them to different object and filter some of those items.<br />
<br />
After filtering I was changing some values in the list items. But
what was strange was thay when I printed the list back it was not
showing the changed value. It was still showing the original value. Code
would look something similar to below.<br />
<br />
<a href="http://sandarenu.github.io/post/understanding-guava-lists-transform/">Read more on this at my new Blog >> </a></div>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-37843959019641055232014-08-02T22:57:00.000+05:302014-08-02T22:57:02.368+05:30 Easy way to Mock REST services<div dir="ltr" style="text-align: left;" trbidi="on">
New post on <a href="http://sandarenu.github.io/posts/easy_way_to_mock_rest_services/">"Easy way to Mock REST services"</a></div>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-50989387740943493192014-07-04T04:54:00.002+05:302014-07-04T04:54:22.796+05:30Caution with Java Autoboxing<div dir="ltr" style="text-align: left;" trbidi="on">
New blog past <a href="http://sandarenu.github.io/posts/caution_with_java_autoboxing/">"Caution with Java Autoboxing"</a><br />
<br /></div>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-87281493770598629672014-07-01T23:53:00.000+05:302014-07-01T23:53:16.450+05:30Experimenting new blog<div dir="ltr" style="text-align: left;" trbidi="on">
I'm experimenting a new blog powered by Hugo static site generation at <a href="http://sandarenu.github.io/">http://sandarenu.github.io</a> . Have a look and give your feedback.... </div>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-69599795257735412002014-06-03T16:02:00.002+05:302014-06-03T16:02:40.444+05:30Simple Introduction to Scalaz<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://github.com/scalaz/scalaz" target="_blank">Scalaz</a> is a great library to make your Scala code more compact and to reduce some boilerplates. But getting started with it requires considerable effort. With its large collection of different operator and very functional nature most people are afraid to use it. Specially for people like me who are with more imperative programming background, it is not easy to get familiar with scalaz.<br />
<br />Recently InfoQ published a presentation named <a href="http://www.infoq.com/presentations/scalaz-introduction" target="_blank">"Scalaz for Rest of us" </a>by Adam Rosien, which introduces some basic building blocks of scalaz. Explanations are really simple and will help you to shed your fears on scalaz. <br />
<br /></div>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-40557607154204715242013-07-02T08:56:00.001+05:302013-07-02T08:56:20.320+05:30Trying out Eclipse Kepler <div dir="ltr" style="text-align: left;" trbidi="on">
Yesterday I downloaded the new version of Eclipse IDE;<a href="http://www.eclipse.org/downloads/" target="_blank"> Eclipse Kepler.</a><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-wy4X_MSUuRg/UdJIBjM1jUI/AAAAAAAAA_w/Xt4Jr3S5k-8/s473/eclipse_kepler.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="218" src="http://4.bp.blogspot.com/-wy4X_MSUuRg/UdJIBjM1jUI/AAAAAAAAA_w/Xt4Jr3S5k-8/s320/eclipse_kepler.jpg" width="320" /></a></div>
<br />
<br />
So far the experience is great. It is much faster than Juno. Main problem I had with Juno is that it is damn slow even with the updates provided later by eclipse to fix the slowness issue. But Kepler seems to have fixed all those issues properly.<br />
<br />
Most notable improvement for me so far is the improved Eclipse Marketplace. Now we can select multiple plugins once and do the installation together. Previously we had to install plugins one-by-one. And also conflict resolution related to plugin installation had been improved. Previously when there is a conflict, eclipse only tell that installation cannot be completed, but now it says exactly which plugin causes the problem and gives option to continue installation without it.<br />
<br />
One problem I had was that there is no official support for Scala-IDE for Kepler. But managed to find a <a href="http://ubuntuone.com/2sDTp5j4rOKg1swHJKINZV" target="_blank">scala-ide build</a> from <a href="https://groups.google.com/forum/?fromgroups#!topic/scala-ide-dev/B6gmd_gYnSk" target="_blank">scala-ide google group</a>. It was working fine, so until official version is available I'll be able servile with it.</div>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com1tag:blogger.com,1999:blog-23257774.post-1965967301960199132013-03-15T07:17:00.000+05:302013-03-15T07:45:13.213+05:30Alternative for Google Reader, Feedly<div dir="ltr" style="text-align: left;" trbidi="on">
Google has announced that they are going to discontinue Google Reader from 1st of July 2013. It is really sad news since I use reader everyday to keep up-to-date with various blogs. <br />
<br />
After seeing this news, first thing I wanted to do was to find and alternative. First one I came across is <a href="http://www.feedly.com/" target="_blank">Feedly</a>. It is a web based reader and has plugins for chrome, firefox, safari and apps for android and iOS. Best thing with Feedly is that you can login with Google account and it will automatically import all your feeds from Reader. After getting used to the UI, it seems to be really nice tool. For the moment I'm going to use Feedly.<br />
<br />
I'm also thinking about finding a good desktop reader as well. Since I'm using Linux there are lot of readers available. Have to try some and find a good one. </div>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com1tag:blogger.com,1999:blog-23257774.post-20236312611606112782012-12-20T08:08:00.000+05:302012-12-20T08:08:43.579+05:30Changing System Time in Xen VM<div dir="ltr" style="text-align: left;" trbidi="on">
Yesterday I wanted to change the system time in one of our test servers. Server was a Xen VM running redhat linux. I used <span style="font-family: Courier New, Courier, monospace;">date --set="20 Dec 2012 00:30:00"</span> command, but when I checked the <span style="font-family: Courier New, Courier, monospace;">date</span> again it showed the previous date not the date I've set using <span style="font-family: Courier New, Courier, monospace;">date</span> command. <div>
<br /></div>
<div>
After doing some searching I found out that by default VM clock is synchronized with its host Xen Server; so changing date is not possible. We need to disable this time synchronization before updating date in the VM. To do that I had to execute following command in VM linux console.</div>
<div>
<span style="font-family: Courier New, Courier, monospace;">/sbin/sysctl -e xen.independent_wallclock=1</span></div>
<div>
<br /></div>
<div>
After that I was able to change the system time using date command.</div>
<div>
<br /></div>
</div>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-41225921217985169062012-12-06T07:43:00.000+05:302012-12-06T07:44:43.104+05:30Stubbing Asynchronous Http Services using Wiremock<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://github.com/tomakehurst/wiremock" target="_blank">Wiremock</a> is simple library which can be used to stub Http Services. It is a handy tool when you want to write unit tests against some Http service(eg: Http REST web service). It has direct support for JUnit using <span style="font-family: Courier New, Courier, monospace;">@Rule</span> feature. We can write unit tests to stub different http requests and verify those requests and responses very easily.<br />
<br />
One weakness of wiremock was it only supported synchronous http request mocking(i.e: You send the request and stubbed wiremock server send the response). But I wanted to mock Asynchronous REST server. In asynchronous scenario in addition direct http response, server is initiating another call back request to the server. This method is commonly used by web service operations which take lots of time to process. Flow of such operation would look like follows.<br />
<br />
When a client want to get some operation done;<br />
1) Client sends the request to the server<br />
2) Server accept that request and give that accepted response as direct http response<br />
3) Server do the processing and send the actual result as a new http request to the client<br />
<br />
This feature is implemented in <a href="http://github.com/sandarenu/wiremock" target="_blank">my wiremock forked repository</a>. Still this is not being merged to <a href="http://github.com/tomakehurst/wiremock" target="_blank">main wiremock repository</a>. So if you are interested in this you'll have to clone my forked repo, build it locally and publish the jar file to your local maven repository.<br />
<br />
Stubbing asynchronous request is easy.<br />
<script src="https://gist.github.com/4221220.js"> </script>
<br />
<br />
In most asynchronous http services, some kind of Id is being used to map original request with the asynchronous response. There can be two ways of doing this.<br />
1) Server generates transactionId and sends it with the immediate response<br />
2) Client sends the transactionId and server echo that when it sends back asynchronous response<br />
<br />
If you want to use the second method with wiremock, you can use <span style="font-family: Courier New, Courier, monospace;">setEchoField</span> method.<br />
<script src="https://gist.github.com/4221282.js"> </script>
<br />
At the moment there is a one limitation with this. You can only use this facility with JSON requests and responses.<br />
<br />
You can find the complete test class at <a href="http://github.com/sandarenu/wiremock/blob/master/src/test/java/com/github/tomakehurst/wiremock/WireMockSendCallbackRequestAsResponseTest.java" target="_blank">github.</a></div>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com4tag:blogger.com,1999:blog-23257774.post-37804535744284095192012-07-25T08:26:00.001+05:302012-08-09T14:39:57.693+05:30Useful GIT Commands<p>This is collection of useful GIT commands I use in my day today work. Just posting here to keep as my own reference.</p><p>Revert changes made to your working copy:</p><p><span style="font-family: 'courier new', courier;">git checkout .</span></p><p>Revert changes made to the index (i.e., that you have added):</p><p><span style="font-family: 'courier new', courier;">git reset</span></p><p>Revert a change that you have committed, do this:</p><p><span style="font-family: 'courier new', courier;">git revert ...</span></p><p>View commits not yet pushed to remote:</p><p><span style="font-family: 'courier new', courier;">git log --branches --not --remotes</span></p><p>Not pushed most recent commit with branch name:</p><p><span style="font-family: 'courier new', courier;"><span style="font-family: 'courier new', courier;">git log --branches --not --remotes --simplify-by-decoration --decorate --oneline</span></span></p><p><span style="font-family: 'courier new', courier;"><span style="font-family: Helvetica, Arial, sans-serif;">Difference between two branches:</span></span></p><p><span style="font-family: 'courier new', courier;">git diff --stat --color master..branch </span></p><p><span style="text-align: left; text-indent: -10px; font-size: x-small;">Here the order of branch name is merge-target..merge-source.</span></p><p><span style="text-align: left; text-indent: -10px;">Create remote tracking branch:</span></p><p><span style="text-align: left; text-indent: -10px; font-family: 'courier new', courier;">git branch --track feature1 origin/my-remote-branch</span></p><p><span style="text-align: left; text-indent: -10px; font-size: x-small;">Here git fetch/pull from feature1 branch will get the updates from my-remote-branch</span></p><p><span style="text-align: left; text-indent: -10px;">Create new local branch from remote branch:</span></p><p><span style="text-align: left; text-indent: -10px; font-family: 'courier new', courier;"><span style="font-family: 'courier new', courier;">git branch --no-track feature2 origin/master</span></span></p><p><span style="text-align: left; text-indent: -10px; font-family: arial, helvetica, sans-serif;">Push local branch to remote repository:</span></p><p><span style="text-align: left; text-indent: -10px; font-family: 'courier new', courier;">git push origing feature2</span></p><p>Checkout specific file from differrent branch:</p><p><pre><code>git checkout remote/branch path/to/file</code></pre></p><div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-48756477488373628202012-04-27T07:15:00.001+05:302012-04-27T07:15:04.997+05:30Exclude resource files from jar file created with SBT<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
I use SBT to build my scala projects. In addition to scala source files I have some resource files in my project. Those are some configuration files and localization resource files.<br />
<br />
When I build the jar file using SBT<span style="font-family: 'Courier New', Courier, monospace;"> package</span> command all of those resource files also get included in the jar file. When those resource files are included inside the jar, modifying them becomes difficult. I have to extract the jar file, edit them and create the jar file again.<br />
<br />
Ideal way of handling resource files are not to include them in the jar file, rather keep them separately and include them in the class path when running the application. How to exclude them from SBT package task was the problem I had. After some googling I found out that this can be achieved by including <span style="font-family: 'Courier New', Courier, monospace;"><b>mapping</b></span> task in the build. Following is sample build file which uses <span style="font-family: 'Courier New', Courier, monospace;">mapping</span> to exclude various types of resource files.<br />
<br />
<br />
<div class="scala" style="background-color: #f0f0f0; border: 1px solid #d0d0d0; color: #000066; font-family: monospace;">
<a href="http://scala-lang.org/" style="color: #000060;"><span style="color: blue; font-weight: bold;">val</span></a> excludeFileRegx <span style="color: navy;">=</span> <span style="color: #6666ff;">""</span><span style="color: #6666ff;">"(.*?)<span style="color: blue; font-weight: bold;">\.</span>(properties|props|conf|dsl|txt|xml)$"</span><span style="color: #6666ff;">""</span>.<span style="color: black;">r</span><br />
<br />
lazy <a href="http://scala-lang.org/" style="color: #000060;"><span style="color: blue; font-weight: bold;">val</span></a> myapp <span style="color: navy;">=</span> Project<span style="color: #f78811;">(</span>id <span style="color: navy;">=</span> <span style="color: #6666ff;">"myapp"</span>, base <span style="color: navy;">=</span> file<span style="color: #f78811;">(</span><span style="color: #6666ff;">"myapp"</span><span style="color: #f78811;">)</span>,<br />
settings <span style="color: navy;">=</span> baseSettings ++ Seq<span style="color: #f78811;">(</span><br />
name <span style="color: navy;">:=</span> <span style="color: #6666ff;">"My App"</span>,<br />
mappings in <span style="color: #f78811;">(</span>Compile, packageBin<span style="color: #f78811;">)</span> ~<span style="color: navy;">=</span> <span style="color: #f78811;">{</span> <span style="color: #f78811;">(</span>ms<span style="color: navy;">:</span> Seq<span style="color: #f78811;">[</span><span style="color: #f78811;">(</span>File, String<span style="color: #f78811;">)</span><span style="color: #f78811;">]</span><span style="color: #f78811;">)</span> <span style="color: navy;">=></span><br />
ms filter <span style="color: #f78811;">{</span><br />
<a href="http://scala-lang.org/" style="color: #000060;"><span style="color: blue; font-weight: bold;">case</span></a> <span style="color: #f78811;">(</span>file, toPath<span style="color: #f78811;">) </span> <span style="color: navy;">=></span><span style="color: #f78811;">{</span><br />
<a href="http://scala-lang.org/" style="color: #000060;"><span style="color: blue; font-weight: bold;">val</span></a> shouldExclude <span style="color: navy;">=</span> excludeFileRegx.<span style="color: black;">pattern</span>.<span style="color: black;">matcher</span><span style="color: #f78811;">(</span>file.<span style="color: black;">getName</span><span style="color: #f78811;">)</span>.<span style="color: black;">matches</span><br />
<span style="color: green; font-style: italic;">// println("===========" + file + " " + shouldExclude)</span><br />
<span style="color: navy;">!</span>shouldExclude<br />
<span style="color: #f78811;">}</span><br />
<span style="color: #f78811;">}</span><br />
<span style="color: #f78811;">}</span>,<br />
libraryDependencies ++<span style="color: navy;">=</span> Seq <span style="color: #f78811;">(</span>dispatch<span style="color: #f78811;">)</span>,<br />
libraryDependencies ++<span style="color: navy;">=</span> testDependencies<span style="color: #f78811;">)</span><span style="color: #f78811;">)</span></div>
</div>
<br /></div><div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com3tag:blogger.com,1999:blog-23257774.post-88418628292334088002012-01-19T07:01:00.000+05:302012-01-19T07:01:21.532+05:30Solving no-interface issue in Wireshark on Ubuntu 11.10Recently I switched to Ubuntu 11.10 as OS in my development machine. Previously I was using Fedora 12. When I installed Wireshark in ubuntu and run it, wireshark didn't show any interfaces which can capture packets. I think it is because wireshark was not run as root user. In fedora when I start wireshark it ask to run as root and get the password. In ubuntu it was not like that.<br />
So after doing some googleing found a solution at a blog post by <a href="http://www.tavshed.com/?p=104" title="tavshed's blog post">tavshed</a>.<br />
<br />
<pre class="bash"><span style="color: #c20cb9; font-weight: bold;">sudo</span> groupadd wireshark
<span style="color: #c20cb9; font-weight: bold;">sudo</span> usermod <span style="color: #660033;">-a</span> <span style="color: #660033;">-G</span> wireshark YOUR_USER_NAME
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chgrp</span> wireshark <span style="font-weight: bold;">/</span>usr<span style="font-weight: bold;">/</span>bin<span style="font-weight: bold;">/</span>dumpcap
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> 750 <span style="font-weight: bold;">/</span>usr<span style="font-weight: bold;">/</span>bin<span style="font-weight: bold;">/</span>dumpcap
<span style="color: #c20cb9; font-weight: bold;">sudo</span> setcap cap_net_raw,<span style="color: #007800;">cap_net_admin</span>=eip <span style="font-weight: bold;">/</span>usr<span style="font-weight: bold;">/</span>bin<span style="font-weight: bold;">/</span>dumpcap
<span style="color: #c20cb9; font-weight: bold;">sudo</span> getcap <span style="font-weight: bold;">/</span>usr<span style="font-weight: bold;">/</span>bin<span style="font-weight: bold;">/</span>dumpcap</pre>
<pre class="bash"><span style="color: #c20cb9; font-weight: bold;">sudo</span> chmod +xs /usr/bin/dumpcap</pre><div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com4tag:blogger.com,1999:blog-23257774.post-52065988381439674772011-11-18T07:02:00.001+05:302011-11-18T07:17:00.906+05:30Creating Java Command Line Applications using jLineMost common way of writing a command line application in java is to use BufferedReader to read user input. But if you want more features like tab completion, you have to write code to handle it from the scratch in BufferedReader method.<br />
<br />
There is a nice library called jLine <a href="http://jline.sourceforge.net/">http://jline.sourceforge.net/</a> which can be used to write nice CLI apps without much effort. It has out of the box support for;<br />
<br />
<ul>
<li>Command History </li>
<li>Tab completion </li>
<li>Line editing </li>
<li>Custom Key Bindings </li>
<li>Character masking</li>
</ul>
<div>
I've written simple sample application on how to use jLine. You can check that out in github <a href="https://github.com/sandarenu/sample-apps/tree/master/java-cli-app">https://github.com/sandarenu/sample-apps/tree/master/java-cli-app</a>. </div><div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com1tag:blogger.com,1999:blog-23257774.post-14968037097922633302011-10-17T07:48:00.001+05:302011-10-17T07:48:46.216+05:30Another Tech Genius Passed Away...<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-UQe_73304RE/TpuQZsRaHqI/AAAAAAAAA6w/r58YJaSiK_E/s1600/dennis_ritchie.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-UQe_73304RE/TpuQZsRaHqI/AAAAAAAAA6w/r58YJaSiK_E/s1600/dennis_ritchie.jpg" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Dennis Ritche, co-author of C programming language and one of the creators of Unix operating system has passed away last week. His inventions changed the way how we do things in the computer industry.<br />
Thank You Dennis....<br />
<br />
It is really sad to see that two of the great minds in technology world passed away in a month...<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com1tag:blogger.com,1999:blog-23257774.post-88260535750961512412011-10-06T13:49:00.001+05:302011-10-06T13:49:21.352+05:30Remembering Steve JobsSteve Jobs, one of the greatest visionaries of our time has passed away on Wednesday(5th Oct 2011). He was 56.<br />
<br />
At 2005 Stanford address quated on his own mortality, saying:<br />
<b>“Remembering that I’ll be dead soon is the most important tool I’ve ever encountered to help me make the big choices in life. Because almost everything — all external expectations, all pride, all fear of embarrassment or failure - these things just fall away in the face of death, leaving only what is truly important.</b>”<br />
<br /><a href="http://2.bp.blogspot.com/-gAIl8wSyvFk/To1jlXOfKrI/AAAAAAAAA6s/FbPJQV_wbMI/s1600/Steve-Jobs.jpeg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-gAIl8wSyvFk/To1jlXOfKrI/AAAAAAAAA6s/FbPJQV_wbMI/s1600/Steve-Jobs.jpeg" /></a>
<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-34873411014622932392011-09-08T08:29:00.001+05:302011-09-08T08:29:11.737+05:30How to Use Multiple GIT AccountsYesterday at HMS we moved some of our projects to GIT from SVN repository. So in order to access that office GIT repository I had to create a new ssh key using my office email address. I already had a ssh key which I used to access my GitHub account. So once I created new key I was unable to access GitHub since in normal configuration ssh can only have one public key.<br />
But I wanted to find a way which I can use both office GIT server login and my GitHub login. After doing some searching on google I found a solution to that. For that we'll have to create ssh config file. So I created following config file at my .ssh folder<br />
vi ~/.ssh/config<br />
<br />
<code><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">
# hms-git<br />
Host hms-git<br />
HostName git.myoffice.com<br />
User git<br />
IdentityFile /home/sandarenu/.ssh/id_rsa<br />
<br />
# github<br />
Host github.com<br />
HostName github.com<br />
User git<br />
IdentityFile /home/sandarenu/.ssh/id_rsa_github</span><br />
<br />
</code>
Once this config file is saved I could clone office git projects using<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> git clone git@hms-git:myproject</span><br />
<br />
To clone GitHub project I could use<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> git clone git@github.com:sandarenu/task_tracker.git</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br /></span><div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-43128984384111912282011-07-08T07:55:00.000+05:302011-07-08T07:55:32.190+05:30Using SoapUI for Web Service Testing<a href="http://www.soapui.org/">SoapUI</a> is a great tool which can be used to test web services. In this post I'll show you how to set up SoapUI project for WS testing.<br />
<br />
Create new project from File ->New SoapUI Project, and in "New Project Dialog" give name and the location of the WSDL file.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-TkfxF_g1XF8/Tgvgt3-58GI/AAAAAAAAA5w/0fB_Zo3t7IM/s1600/new-ws-project.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="160" src="http://3.bp.blogspot.com/-TkfxF_g1XF8/Tgvgt3-58GI/AAAAAAAAA5w/0fB_Zo3t7IM/s320/new-ws-project.png" width="320" /></a></div><br />
<br />
You can find the sample wsdl file I used for testing in github <a href="https://github.com/sandarenu/soapui-test">https://github.com/sandarenu/soapui-test</a>. <br />
<br />
<u><b>Web Service Mocking</b></u><br />
<br />
Service mocking is required when you are writing a web service clients and either you don't have the web service implemented or you don't have the access to the real service. Here's how to do that using SoapUI.<br />
<br />
Create Mock of the web service by right clicking on the project and selecting 'Generate MockService'.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-ztbKFhaXn0s/Tgvgubo8k1I/AAAAAAAAA50/Q_lwfPMKmwc/s1600/mock-service-config.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="168" src="http://2.bp.blogspot.com/-ztbKFhaXn0s/Tgvgubo8k1I/AAAAAAAAA50/Q_lwfPMKmwc/s320/mock-service-config.png" width="320" /></a></div><br />
Once mock service is created you can mock the operations by clicking on the small icon in the service mock dialog.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-SVBD4n8CfC0/TgvgtVUGGmI/AAAAAAAAA5s/EoIyYvrk9-s/s1600/project-structure.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="168" src="http://2.bp.blogspot.com/-SVBD4n8CfC0/TgvgtVUGGmI/AAAAAAAAA5s/EoIyYvrk9-s/s320/project-structure.png" width="320" /></a></div><br />
<br />
Double click on the operation you just mocked and you'll get a dialog to configure mock responses.<br />
You can configure any number of mock responses and then select how those response to be dispatched when our mock service receives WS request. There are many dispatching strategies available such as "Script", "Sequence", "Query Match", etc...<br />
<br />
When you do some integration testing you need your mock service to respond based on different parameters of the requests you send. In such cases you can either use "Script" or "Query Match" dispatch mechanism.<br />
<br />
<u><b>Web Service Testing</b></u><br />
We can use SoapUI to create test cases to test a Web Service we developed. To create a test suite right click on the project and select "New TestSuite" from the context menu. Then right click on the test suite we just created and select "New TestCase".<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-7o0ex8jh50A/TgvgsGpI6cI/AAAAAAAAA5k/1Vcm8vn4SDQ/s1600/testcase.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="168" src="http://4.bp.blogspot.com/-7o0ex8jh50A/TgvgsGpI6cI/AAAAAAAAA5k/1Vcm8vn4SDQ/s320/testcase.png" width="320" /></a></div><br />
<br />
Once we have created the test case we can add test steps to it. Lets add a test step to test time for time zone 'lk'. Right click on the test steps dialog and select "Test Request" and create the request you want to test.<br />
Once test request is created we can add assertion step to it. Click the "Assertions" button at the bottom of the test request editor.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-yezUBg8G8_Y/TgvgvPHk4-I/AAAAAAAAA54/5kLGRm-CmWg/s1600/mock-operation.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="168" src="http://3.bp.blogspot.com/-yezUBg8G8_Y/TgvgvPHk4-I/AAAAAAAAA54/5kLGRm-CmWg/s320/mock-operation.png" width="320" /></a></div><br />
<br />
Right click on the assertion editor and add "xPath Match"<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-utW4JTUFqFw/Tgvgq74yJRI/AAAAAAAAA5c/C_EZ4SqQQ1E/s1600/xquery-match-assertion.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="266" src="http://1.bp.blogspot.com/-utW4JTUFqFw/Tgvgq74yJRI/AAAAAAAAA5c/C_EZ4SqQQ1E/s320/xquery-match-assertion.png" width="320" /></a></div> Put //Time as "xQuery Expression" and put value you are expecting as "Expected Result"<br />
<br />
Now you can test this request using the Mock WS you created before. Start the mock service by clicking on the small green arrow found in the top of the "TimeServiceMock". Then open the test case you created above by double clicking it. Then run the test case again by clicking small green arrow in the to of the dialog box.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-ddFhBlNBsdM/ThZpPkNdWqI/AAAAAAAAA6I/tkRXfIaRMLw/s1600/run-test-case.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://2.bp.blogspot.com/-ddFhBlNBsdM/ThZpPkNdWqI/AAAAAAAAA6I/tkRXfIaRMLw/s320/run-test-case.png" width="320" /></a></div><br />
If every thing went well you'll be able get success result for your test case.<br />
<br />
This is just the start. You can then add more test cases and assertions and improve your test suite. SoapUI site has good documentation on how to do functional testing. <a href="http://www.soapui.org/Getting-Started/functional-testing.html">http://www.soapui.org/Getting-Started/functional-testing.html</a><br />
You can refer that and get more information.<br />
<br />
You can also find the SoapUI project for this example at https://github.com/sandarenu/soapui-test. Download it and open it using "File -> Import Project"<br />
<br />
Happy Testing.....<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com2tag:blogger.com,1999:blog-23257774.post-46851470560285894862011-07-03T14:04:00.001+05:302011-07-03T14:05:06.207+05:30Solving 'symbol lookup error' in new Eclipse 3.7 Indigo in FedoraWhen I downloaded and run the latest eclipse 3.7 Indigo release, it crashed with a strange error.<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">symbol lookup error: /usr/lib/libwebkit-1.0.so.2: undefined symbol: soup_content_decoder_get_typ</span>e<br />
<br />
After some searching in the web I found out that it is due that I'm having an older version of <b><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">libsoup</span></b> library. I had libsoup-2.28.1-1.fc12.i686 in my fedora 12.<br />
Issue was solved by updating that library using yum.<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">yum update libsoup</span><br />
<div><br />
</div><div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com3tag:blogger.com,1999:blog-23257774.post-4642893029048015192011-05-06T11:05:00.000+05:302011-05-06T11:05:57.986+05:30Hibernate HQL Select Query Based on Item in a One-to-Many RelationshipFew days back I had a situation where I have to fetch some data based on a value of an item stored in one-to-many relationship. I my project I had two classes like below. I had to fetch all the Oders that has particular item.<br />
<br />
<pre style="background: #ffffff; color: black;"><span style="color: maroon; font-weight: bold;">class</span> Order <span style="color: purple;">{</span>
<span style="color: maroon; font-weight: bold;">private</span> <span style="color: #bb7977; font-weight: bold;">List</span><span style="color: #808030;"><</span>Item<span style="color: #808030;">></span> items<span style="color: purple;">;</span>
<span style="color: dimgrey;">//more code ...</span>
<span style="color: purple;">}</span>
<span style="color: maroon; font-weight: bold;">class</span> Item <span style="color: purple;">{</span>
<span style="color: maroon; font-weight: bold;">private</span> <span style="color: #bb7977; font-weight: bold;">String</span> itemId<span style="color: purple;">;</span>
<span style="color: maroon; font-weight: bold;">private</span> <span style="color: #bb7977; font-weight: bold;">String</span> name<span style="color: purple;">;</span>
<span style="color: dimgrey;">//more code ...</span>
<span style="color: purple;">}</span>
</pre><br />
With native SQL it was not that difficult, but since I've used Hibernate I wanted to find a way to do it in HQL. After some searching in Google I found out how to do it.<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">select o from Order o left join o.items its where its.itemId = :itemId</span><div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com1tag:blogger.com,1999:blog-23257774.post-53283217959757633392011-04-21T07:48:00.000+05:302011-04-21T07:48:11.517+05:30Different views for your blogRecently Blogger started providing different views for the blogs created in it. They are very cute way to view our blogs in different angles. Following is snapshot view of my blog.<div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-nJiNMA4HAvE/Ta-TkQaSp8I/AAAAAAAAA5Y/CdxkxjRXDzg/s1600/blogger_snapshot.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="210" src="http://2.bp.blogspot.com/-nJiNMA4HAvE/Ta-TkQaSp8I/AAAAAAAAA5Y/CdxkxjRXDzg/s400/blogger_snapshot.jpg" width="400" /></a></div><div> <div><br />
</div><div><br />
</div><div><br />
</div><div><br />
</div><div><br />
</div><div><br />
</div><div><br />
</div><div><br />
</div><div><br />
</div><div><br />
</div><div><br />
</div><div>Try my blog on those different views using following urls.</div><div><a href="http://sandarenu.blogspot.com/view/flipcard">http://sandarenu.blogspot.com/view/flipcard</a></div><div><a href="http://sandarenu.blogspot.com/view/mosaic">http://sandarenu.blogspot.com/view/mosaic</a></div><div><a href="http://sandarenu.blogspot.com/view/sidebar">http://sandarenu.blogspot.com/view/sidebar</a></div><div><a href="http://sandarenu.blogspot.com/view/snapshot">http://sandarenu.blogspot.com/view/snapshot</a></div><div><a href="http://sandarenu.blogspot.com/view/timeslide">http://sandarenu.blogspot.com/view/timeslide</a></div></div></div><div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-39433992147647949762011-04-21T07:34:00.000+05:302011-04-21T07:34:08.614+05:30After Long Time.......Its being long time since my last post......<br />
Hopping to do some posts more frequently in coming months. So keep your fingers crossed :)<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0tag:blogger.com,1999:blog-23257774.post-9243604798173384192010-05-04T07:43:00.000+05:302010-05-04T07:43:19.345+05:30MySql - Ms Sql Server Database PortabilityFew weeks back I was given a task to migrate a Java application using MySQL as its database to MS SQL Server. It was actually not a full migration, rather application should be able work with both MySQL and MS SQL Server. Since we had used Hibernate in our application I thought it will be a easy thing. But when I dig deep in to the application and started migration I was proved to be wrong. I encounter lot of issues and hence thought of documenting them so any one can get some help. Major headache was the difference in some direct SQL commands used in the application. Following are the list of issues I encounter and how I solved them.<br />
<br />
<br />
1. JDBC Driver Issue with the Microsoft JDBC Driver<br />
First thought of using JDBC driver provided by<a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=99B21B65-E98F-4A61-B811-19912601FDC9&displaylang=en"> Microsoft for MS SQL Server 2005</a>. But when I ran the test cases I got few issues with it.<br />
1). Gave execption "org.hibernate.MappingException: No Dialect mapping for JDBC type: -9 "<br />
After some investigation found out that it was due to NVARCHAR datatype. There is another opensource driver called <a href="http://jtds.sourceforge.net/">jtds</a>. Which is more actively developed as well. With that driver I did not get that MappingException.<br />
<br />
2. Data type differences<br />
For queries like "<span style="font-family: "Courier New",Courier,monospace;">SELECT count(id) From myTable</span>", MySql JDBC driver returns datatype java.math.BigInteger and with MsSQL jtds JDBC driver we get datatype java.lang.Integer. So I had to convert it to string first and then convert to long<br />
<span style="font-family: "Courier New",Courier,monospace;">String countStr = summaryRow[1] == null? "0": String.valueOf(summaryRow[1]);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> long count = Long.parseLong(countStr);</span><br />
<br />
3. Nullable Unique columns not supported in MsSql Server. In Sql Server NULL is taken as a value and hence can't have multiple rows with null, but in MySql we can have Nullable unique columns. So when table schema is generated through Hibernate we have to execute additional update query to perform a workaround for this issue. Here we add new column called 'my-table_id_add' to the table. <br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">declare unique_key_list_my-table cursor for</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> select OBJECT_NAME(OBJECT_ID)</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> FROM sys.objects</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> WHERE type_desc LIKE '%CONSTRAINT' and OBJECT_NAME(OBJECT_ID) LIKE 'UQ__my-table%'</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">OPEN unique_key_list_my-table</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> FETCH NEXT FROM unique_key_list_my-table INTO @keyName</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> set @RowNum = 0</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> WHILE @@FETCH_STATUS = 0</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> BEGIN</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> set @RowNum = @RowNum + 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> print cast(@RowNum as char(1)) + ' ' + @keyName</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> if not @keyName is null</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> begin</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> select @sql = 'ALTER TABLE [my-table] DROP CONSTRAINT [' + @keyName + ']'</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> execute sp_executesql @sql</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> end</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> FETCH NEXT FROM unique_key_list_my-table INTO @keyName</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> END</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">CLOSE unique_key_list_my-table</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">DEALLOCATE unique_key_list_my-table</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">ALTER TABLE my-table ADD my-table_id_add AS (CASE WHEN my-table_id IS NULL THEN CAST(id AS VARCHAR(30)) ELSE my-table_id END);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;">ALTER TABLE my-table ADD CONSTRAINT UQ__my-table_my-table_id UNIQUE(my-table_id_add);</span><br />
<br />
<br />
4. <span style="font-family: "Courier New",Courier,monospace;">TIMESTAMP</span> in MS Sql server is not functionally same as MySQL. Have to use <span style="font-family: "Courier New",Courier,monospace;">GETDATE()</span> function for that.<br />
e.g: <span style="font-family: "Courier New",Courier,monospace;">Create table timestamp_test DATETIME default(GETDATE())</span><br />
<br />
5. In Ms Sql Server we can't use '<span style="font-family: "Courier New",Courier,monospace;">user</span>' as table/field name, but that is possible in MySql. <br />
<br />
6. <span style="font-family: "Courier New",Courier,monospace;">LIMIT</span> is not supported in Ms Sql Server and there is no easy way if we want go select some range of data. In MySql we use "<span style="font-family: "Courier New",Courier,monospace;">SELECT * FROM my-table LIMIT 10, 20</span>" to select records from 10 to 20, but in Ms Sql Server we have to use something like "<span style="font-family: "Courier New",Courier,monospace;">SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY id) as row FROM my-table ) a WHERE row > 10 and row <= 20</span>"<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com1tag:blogger.com,1999:blog-23257774.post-20122098318775839172010-02-17T14:48:00.000+05:302010-02-17T14:48:31.701+05:30Integrating YUI Compressor to your Maven Web ProjectSize of the javascript files and css files in a website has a big affect on its performance. Especially in slow connections lot of time will be spent on downloading those files. We recently came across such situation. Our website was using jQuery and some other javascipt libraries. Some of them were more than 100kb. Sometimes it took more than 10 seconds to load a page. When we view the loading statistics using developer-tools in Chrome it showed that browser had downloaded more than 500kb of scripts and css.<br />
<br />
One way to reduce this script size is to compress them. Our script files contained lot of comments, licencing statements, nice formattings, long meaningful variable names etc... which increases the file size. <a href="http://developer.yahoo.com/yui/compressor/" target="_blank">YUI Compressor</a> is a free utility by Yahoo which can be use to compress our scripts by removing above mentioned things. It is jar file and you can use that and compress file by file.<br />
<br />
But that is not very practicle to keep those minimized scripts in develepment since after minimizing you won't be able read them and edit them when needed. Best method is to do the minization when you create the war file. Luckly there is a <a href="http://alchim.sourceforge.net/yuicompressor-maven-plugin/" target="_blank">maven plugin for this</a>. Following is the plugin component you can add to your maven pom.<br />
<br />
<style type="text/css">
.code0 { font-size: small; font-family: Consolas, "Courier New", Courier, Monospace; color: #000000; background-color: #ffffff; }
.code1 { margin: 0em; }
.code2 { margin: 0em; width: 100%; background-color: #f0f0f0; }
.code3 { color: #006400; }
.code4 { color: #000000; }
.code5 { color: #008b8b; font-weight: bold; }
.code6 { color: #00008b; }
</style><br />
<div class="code0"><pre class="code1"><span class="code3"><</span><span class="code4">plugins</span><span class="code3">></span></pre><pre class="code2"><span class="code3">....</span></pre><pre class="code1"><span class="code3"><</span><span class="code4">plugin</span><span class="code3">></span></pre><pre class="code2"><span class="code3"><</span><span class="code4">groupId</span><span class="code3">></span><span class="code4">org</span><span class="code3">.</span><span class="code4">apache</span><span class="code3">.</span><span class="code4">maven</span><span class="code3">.</span><span class="code4">plugins</span><span class="code3"></</span><span class="code4">groupId</span><span class="code3">></span></pre><pre class="code1"><span class="code3"><</span><span class="code4">artifactId</span><span class="code3">></span><span class="code4">maven</span><span class="code3">-</span><span class="code4">war</span><span class="code3">-</span><span class="code4">plugin</span><span class="code3"></</span><span class="code4">artifactId</span><span class="code3">></span></pre><pre class="code2"><span class="code3"><</span><span class="code4">configuration</span><span class="code3">></span></pre><pre class="code1"><span class="code3"><</span><span class="code4">webResources</span><span class="code3">></span></pre><pre class="code2"><span class="code3"><</span><span class="code4">resource</span><span class="code3">></span></pre><pre class="code1"><span class="code3"><</span><span class="code4">directory</span><span class="code3">></span></pre><pre class="code2"><span class="code4">$</span><span class="code3">{</span><span class="code4">project</span><span class="code3">.</span><span class="code4">build</span><span class="code3">.</span><span class="code4">directory</span><span class="code3">}/</span><span class="code4">minimized</span></pre><pre class="code1"><span class="code3"></</span><span class="code4">directory</span><span class="code3">></span></pre><pre class="code2"><span class="code3"><</span><span class="code4">targetPath</span><span class="code3">>/</</span><span class="code4">targetPath</span><span class="code3">></span></pre><pre class="code1"><span class="code3"><</span><span class="code4">filtering</span><span class="code3">></span><span class="code5">false</span><span class="code3"></</span><span class="code4">filtering</span><span class="code3">></span></pre><pre class="code2"><span class="code3"></</span><span class="code4">resource</span><span class="code3">></span></pre><pre class="code1"><span class="code3"></</span><span class="code4">webResources</span><span class="code3">></span></pre><pre class="code2"><span class="code3"></</span><span class="code4">configuration</span><span class="code3">></span></pre><pre class="code1"><span class="code3"></</span><span class="code4">plugin</span><span class="code3">></span></pre><pre class="code2"><span class="code3"><</span><span class="code4">plugin</span><span class="code3">></span></pre><pre class="code1"><span class="code3"><</span><span class="code4">groupId</span><span class="code3">></span><span class="code4">net</span><span class="code3">.</span><span class="code4">sf</span><span class="code3">.</span><span class="code4">alchim</span><span class="code3"></</span><span class="code4">groupId</span><span class="code3">></span></pre><pre class="code2"><span class="code3"><</span><span class="code4">artifactId</span><span class="code3">></span><span class="code4">yuicompressor</span><span class="code3">-</span><span class="code4">maven</span><span class="code3">-</span><span class="code4">plugin</span><span class="code3"></</span><span class="code4">artifactId</span><span class="code3">></span></pre><pre class="code1"><span class="code3"><</span><span class="code4">version</span><span class="code3">></span><span class="code6">0.7.1</span><span class="code3"></</span><span class="code4">version</span><span class="code3">></span></pre><pre class="code2"><span class="code3"><</span><span class="code4">executions</span><span class="code3">></span></pre><pre class="code1"><span class="code3"><</span><span class="code4">execution</span><span class="code3">></span></pre><pre class="code2"><span class="code3"><</span><span class="code4">goals</span><span class="code3">></span></pre><pre class="code1"><span class="code3"><</span><span class="code4">goal</span><span class="code3">></span><span class="code4">compress</span><span class="code3"></</span><span class="code4">goal</span><span class="code3">></span></pre><pre class="code2"><span class="code3"></</span><span class="code4">goals</span><span class="code3">></span></pre><pre class="code1"><span class="code3"></</span><span class="code4">execution</span><span class="code3">></span></pre><pre class="code2"><span class="code3"></</span><span class="code4">executions</span><span class="code3">></span></pre><pre class="code1"><span class="code3"><</span><span class="code4">configuration</span><span class="code3">></span></pre><pre class="code2"><span class="code3"><</span><span class="code4">webappDirectory</span><span class="code3">></span></pre><pre class="code1"><span class="code4">$</span><span class="code3">{</span><span class="code4">project</span><span class="code3">.</span><span class="code4">build</span><span class="code3">.</span><span class="code4">directory</span><span class="code3">}/</span><span class="code4">minimized</span></pre><pre class="code2"><span class="code3"></</span><span class="code4">webappDirectory</span><span class="code3">></span></pre><pre class="code1"><span class="code3"><</span><span class="code4">nosuffix</span><span class="code3">></span><span class="code5">true</span><span class="code3"></</span><span class="code4">nosuffix</span><span class="code3">></span></pre><pre class="code2"><span class="code3"></</span><span class="code4">configuration</span><span class="code3">></span></pre><pre class="code1"><span class="code3"></</span><span class="code4">plugin</span><span class="code3">></span></pre><pre class="code2"><span class="code3">....</span></pre><pre class="code1"><span class="code3"></</span><span class="code4">plugins</span><span class="code3">></span></pre></div><br />
<br />
<br />
When you run mnv clean package YUI compressor will compress the scripts and put them in target/minimized folder and those will be used to create the war file.<div class="blogger-post-footer"><hr /> <a href="http://sandarenu.blogspot.com">Sandarenu's Blog</a></div>Chathurika Sandarenuhttp://www.blogger.com/profile/09693066218739498153noreply@blogger.com0