Sunday, December 27, 2009

My Picks of 2009 !

Technology/Industry

  • Best emerging application : Google Wave ( We use for everything now)
  • Flop application/framework : Mule ESB ( !@#$)
  • Emerging Concept : Multi Paradigm Programming (Hitting the balance rite)
  • Best Blog Post : State design pattern ( He he !)
  • Best I learned/ing : Scala (Change of gears ! )
  • Regret : Failure to convince docbook to our engineering

Politics (Going back to SL in 2010 -- He he )
  • Political Incident of the year: Do I need to say ?
  • Best Politician : Not awarded
  • Worst Politician : Obama ( Where is Mr Clinton ? )

Sports
  • Sporting Incident : Wimbledon Final Again (Roger, u didn't deserve the title)
  • Best Sportsman : Gautam Gambhir -Cricket ( Got everything in his kit )
  • Best Sportswoman : Not awarded
  • Worst sporting incident : Henry's Handball :)

Entertainment (Tamil)

Entertainment (English)
  • Best Song : The Script Break Even ( What a pathos melody)
  • Best Female Singer : Kelly Clarkson (Song "Already Gone" from "All I ever wanted" )
  • Best Male Singer : Danny O'Donoghue (The script break even)
  • Best Movie : Hangover (Avatar Narrowly misses out )
  • Biggest Flop : Wanted (Even Anjelina cannot cure ! )
  • Best Actor : Will Smith ( Seven Pounds )
  • Best Actress : Zoë Saldaña (Avatar)

Novels/Contemporaries/Biographies Read this year
  • The Namesake (Jhumba Lahiry) -- By far the best contemporary I ever read
  • Unaccustomed Earth (Jhumba Lahiri)
  • True Colors (Adam Gilchrist)
  • One Night At The Call Center (Chetan Bagat)
  • Anal Kaatru (Jeyamohan-Tamil)
  • Q & A (Vikas Swarp)


Special Mentions
  • Best movie I watched this year - Music and Lyrics (Superb movie, don't miss)
  • The song I listen most # times - Way Back Into Love
  • To see my 2008 picks Check Here

Monday, June 29, 2009

How to enforce Checkstyle in SVN commits : Simple Guide

This is a simple tutorial on how to setup Checkstyle into Subversion hooker.

CheckStyle Introduction

Checkstyle is going to be the tool we use for enforcing out code style at repository level.
There are good valid reasons for using it.
1) Very comprehensive way of controlling the code style. It does come with standard Sun code style enforcement. But one can always modify the XML file to relax or change the standard.
2) It doesn't change the code. It just enforce the check and tells you what are the violation. This is exactly what we want. We could have used Jalopy. But it simply modifies the code which is being enforced. The ownership of the code still belongs to programmer. So we just wants to check the code style and tell the programmer about the violation. That's it.
3) Of course its open source
4) Better way for automation. Easy to integrate with Maven and Ant.
5) More importantly the subversion checker framework supports it nicely !

So lets get a hand-on experience now.

1) Download the checkstyle distribution from http://checkstyle.sourceforge.net . I use the version 5.0
2) Create a sample project with src directory and add a few java classes. (Idea : Better you copy your file templates from your IDE and use them here. Once you format, you can copy them back and use !)
3) Now just try to enforce Sun code style with your sample src

java -jar checkstyle-all-5.0.jar -c <checkstyle-dir>/sun_checks.xml -r <sample-project-dir>/src

This command will just traverse through src directory and check the code style of java classes against the sun_checks.xml standard. sun_checks.xml is the sample file given by CheckStyle which has the sun standards configured.

4) Now we are comfortably placed in writing the svn hooker to enforce this check.

Subversion, Subversion Hooker and Subversioncheker

In this section we will see how this checkstyle command can be configured in Subversion so that for each commit the checksyle will be enforced. Subversion provides an excellent flexibility for doing this. Those who have already worked on Subversion knows, if we commit a source without commit message eventually the commit will fail. This setting is done through a hooker. You can get more information here.

So lets write our hooker and test the work. Since svn repository would have been already setup in your environment and its a System Admin job, I recommend you to use this very simple steps to setup your svn repository without further delay (If you don't have it already).

Now I assume, you must have setup your subversion with your sample project, started the svn server daemon and checkout the sample project to another directory !

Now its time to write our svn hooker script. There is a good framework called svnchecker to write svn hooker scripts easily. Download the 0.3 version from here. (The project is renamed to Repoguard with no release yet !)

Now writing svn hooker is very simple. Follow these steps

1) Go to your svnrepos/hooks directory (This is the directory where we have our svn hooks)
2) Copy the pre-commit.tmpl file to pre-commit (Provided you haven't done it so far)
3) Add the following command before the "exit 0" line
<svnchecker-0.3-dir>/Main.py PreCommit $REPOS $TXN || exit 1

4) svnchecker needs a configuration file named svncheckerconfig.ini for the relevant configurations. The file can be inside the hooker directory itself. Add the following settings inside that file.

[Default]
#This property tells Subversionchecker about all checks
#(UnitTests, AccessRights, XMLValidator etc) it should execute.
#Separated with comma (",")
Main.PreCommitChecks=Checkstyle

#Path of java executable to run Checkstyle command
Checkstyle.Java=java

#Classpath for executing Checkstyle rules
Checkstyle.Classpath=
<checkstyle-dir>/checkstyle-all-5.0.jar

#Configuration file for Checkstyle to run its rules.
Checkstyle.ConfigFile=/sun_checks.xml

#In case of failures, where should Subversionchecker redirect the errors
Checkstyle.FailureHandlers=Console


5) Now you restart the svn daemon again

6) Try to commit the checkout sources with changes. Or add a new java class now and see whether your commit fails if the code is not adhere to sun java standard. Your commits will eventually fails !

Client side tips :
1) Tune your IDE to make use of sun check style. Right now IntelliJ IDEA has a plug-in for Checkstyle. You can use it. But the IDEA reformatter doesn't support importing checkstyle. So you may have to manually modify the IDEA code style to sync with sun style or vice-versa.

Now give your developers hard time :)

Code styles and their strict enforcement

"At 6.00 pm, Jonathan got SVN update, found lots of conflicts. He tried to do svn diff to see what were the changes. He realized most of the conflicts are due to in-proper code conventions used by the peer commiter. By the time he fixed and committed the code it was 9.00 pm. His girl friend was dating with Tom !"

"Alice is asked to do a code review on a new comer's code. She first checked the code convention. It was poor and terrible. She spent one hour before actually went in to review the code standards and patterns"

"Shekhar is annoyed finding a code which catches "Exception" instead of a specific Exception class. Often irritated when seeing a jdbc connection is closed inside a try clause instead of a finally clause"

"Lew Huang have just read some of the Vendor's Prototype API samples. The sample programming codes do not follow any sort of standards. They are all messy. Finally Lew recommended not to sign the contract with that particular "Vendor" "

Everyday we see there are many cases like these. I will be only a fool if I am to explain why you need programming styles and code reviews. These are widely accepted methodologies and an integral part of Agile's success story.

But how often we take this too easy and granted? We forget to format the code before committing to source repository. We often break others' codes and style. Even if we do format, each and everyone sometimes adapt to different code styles. These always lead to nightmare for your colleague, your co-developer, your team, your reviewer, your company and of course yourself too.

So the answer is simple. What if we enforce the code style checking at repository level? What if a source commit fails when trying to commit something which is not conformed to the accepted standard. Sound nice yeah? (I tried to convince my management to fail the commits if there is no relevant test cases. The idea didn't impress many including myself ;) later )

I tried my hand on this now. I selected Subversion and Checkstyle and tried to enforce the codestyle formatting. I think lots of companies adapted this for many many years. This is first of many hookers I am trying to experiment. Failing commits based on lack of testcases would be next to come !

Next Section : Tutorial on enforcing codestyle in Subversion

Sunday, June 28, 2009

Back to business .. My blogging

Well its been a long break. I had my foot on different ships simultaneously. I had an assignment with Sun, doing my higher studies at RMIT and then my main job at hSenid. Somewhere on the way I lost my plot, difficult to manage all three at sametime and realised I neither did justice to myself nor to my employers.


So it was a tough call, I consulted my mentor and few friends , then decided to quit Sun. Quiting Sun wasn't an easy decision. I had a great chance to continue there even after my studies. But the main thing missing there was the fun. As far as I am concerned, one will have to enjoy his work otherwise he or she better quit. I love doing researches, design and fair amount of programming. Nothing else thrills my job except those. So I informed this to Sun and now I stick with hSenid and RMIT only which I feel is the right combination. The work and study greatly complement each other.

As far as blogging is concerned, I won't be blogging from my Sun site anymore. That will somehow relieve some obligations too. Could I have blogged about IDEA plugin? .. Could I have criticised Sun's very own Glassfish .. I doubt !

Back to business, Today itself I will write a tutorial on code formatting CheckStyle best practice with source control. Also I will try to continue my State pattern article.

So as usual Stay Tuned !

Wednesday, October 22, 2008

Sun started shining !



Last week, it was a usual busy day for me. Preparing some assignments, there was a presentation on "GREEN IT". More than that, the current project I am working on, which is very challenging and getting my toil out (What does this toil mean? Sometime I pick few words used by Melbourne train commuters ;) ).

One afternoon I received an email from one of a Sun employee asking for an interview appointment with Sun to become RMIT's Sun Campus Ambassador program. I was little thrilled about it, not sure what was this about though. So as usual, I did a bit of googling and found this ambassador program is really the way forward to meet my dreams :) . So I scheduled a time on last Friday and then fell busy with my other works.

Friday was one of my toughest days and probably I deserved. Myself included superb team (Arpan, Thilagah and Susan) had to show an ecommerce demo which almost has all the J2EE technologies used I think. It was "meant" to be SOA and I hope we achieved it for some extent. We were the only group got everything worked as expected with the proper design patterns. So we were little over confidence. I didn't really test anything, assuming it would be just a walk through for our team. It wasn't turned out to be. It really killed our time. I must have finished the demo in the morning and should have come back home and attended the stand up meeting. It didn't happen. Finally we somehow managed to get it working. But by the time it was little late and I completely forgot my interview !

When I was in the train, I received the reminder alarm, but for my sake, the train got delayed and I got the call from Sun when I was inside the bus(I am still a public transport commuter. Advantage : enough time for podcasts! ). I politely apologized for the delay, rescheduled the interview in 15 minutes time.

As it turned out to be, the interview was very smooth. I in fact have already been familiar with most of those technologies. Only exception was opensolaris. But that even wouldn't be problem after the "Project Indiana". I just love GNOME with its memory leaks! Need to write a post about it another time!


So as usual, my blog had a looooong buildup. But the real story starts only now! What is Sun Ambassador Program ? Is it a job, fun or passion? For me it is nothing but all about passion. The responsibilities are really interesting and very passionate. You are given hell lot of Sun materials and you need to study it or rather learn it! I am anyway doing this more often than not. Then you need to arrange few demos to your university which again I am indirectly doing to my colleagues these days ! And the last but not the least you need to maintain a Sun blog and manage few Sun related user groups. There is no surprise that I would have delighted and accepted the challenge. You got to work just few hours a week as this is more of a student program and not a professional program.

So what are the benefits ? There are lot. First of all, you will have the SUN flavor in your shirt! You suddenly start receiving mails about Jonathan and Gosling ! It is really interesting. And you will learn many many sun technologies. If you have enough passion on open source, you can build communities within your university, have meet ups etc etc.

I recon, most of the universities should start chasing Sun to introduce this program to their respective computer science departments. Currently there are about 500+ students from 30 odd countries. This is a very small number when compared to the industry use of Java technologies. I think University of Moratuwa, which is one of the popular universities which contributes to open source significantly, should start looking at this. Apache is not the only open source world. I know there are few concerns with Star Office approaches, the licensing terms of MySQL blah blah. But nevertheless, it is a great platform for those students I promise.

So back to some of my personal stuff (Sofar written is not personal ? ) . Senthil used to tell me why I target Google in most of my blog posts. And I used to answer, it is not about targeting Google (Who the dare am I to do that ? A dog bark won't harm a star! ). But I just tried to give my honest reviews, analyzing the pros and cons of each of Google's new technologies. I was one of the very few who started using Google Reader which for me is the best RSS reader by now. But I really hate the open source MASK by few of the giant companies. One of the most important open source attribute is it's diversity. But see how many open source projects in the world are driven entirely by a single company ? Calculate and find it :)

The post started with something and is proceeding with a wrong path. So better I should stop. So whats the morale of the post?

I find Sun Ambassador Program is a better way forward to promote open source technologies in universities. As a student, it is win win for me. I learn many things and I contribute back to community. I wish other companies start doing this. Google's SOC is such an attempt. But it is very limited to a small bunch of skilled guys.

Thats all for the day. I really wanted to make this blog purely technical. But today it is little deviated. Never mind.

See you with the next post .. Bye!

Sunday, September 28, 2008

Can't wait more : Publishing my web os Vision! WEBINDOWS

Recently I have prepared a vision and scope document for a web operating system which is named WEBINDOWS ! Its been once month since I started preparing this vision document, and now I am working on a BRS for this product.

I had to shape up the vision and scope document more prettier and accountable. But I am really scared of Google. It can any time announce its web-os. So it won't be good if I publish my document after that [It might be the same story to IE8 features after the Chrome announcement!]. People might think I crapped few from Google. But it is not really the case. Because google hasn't publicly published any such documents or features as by now.

So planned to maintain this document publically. So I can see how google's vision matches mine when their announcement comes :)

I will more more on this. But for the time being just have a look on the doc.

Warning : Copying or Reproduction of this document without the author's consent is illegal under Australian law!

Click Here to download the document

Step by Step tutorial on CAS -Part 5: How to bypass accepting certificate from client side

Oh well, After a week break, we have come to the last part of this tutorial. This section is an option and specific to certain requirements only.
As I mentioned in the part1, not every time you need SSL application and mandatory to trust the certificate. Think about an application running inside a company LAN and there are no hostnames for your local machines. We normally use ipaddress to communicate/access local servers. In such case, if there is a design constraint to use SSL for a particular application [in this case, a CAS system], we will get into a trouble. How to avoid using the hostnames ? How do we avoid validating the certificate by the client ? Is there a way that we can bypass the certificate trusting procedure and proceed with the flow ?
The answer is ugly yes. Though we are fundamentally deviating from the purpose of SSL, we can still do this. This ugly solution is not new to java world. But it relates a much to this tutorial topic, So I thought of including this as well.

jdk has a TrustManageFactory and a default TrustManager for trusting the server and client certificates. Similarly it has aHostnameVerifier for the hostname verification [Is there anything like ipverifier ?].
What we are doing here is, we will create a dummy TrustManager and a dummy HostnameVerifier and set them as default.

Following is the DummyTrustManage.
package coolsolutions.ssl.dummy;

import com.sun.net.ssl.X509TrustManager;

import java.io.PrintStream;
import java.security.cert.X509Certificate;

public class DummyTrustManager implements X509TrustManager {

public DummyTrustManager() {
}

public boolean isClientTrusted(X509Certificate cert[]) {
return true;
}

public boolean isServerTrusted(X509Certificate cert[]) {
return true;
}

public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}

Following is the Dummy Hostname verifier

package coolsolutions.ssl.dummy;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;

public class DummyHostnameVerifier implements HostnameVerifier, com.sun.net.ssl.HostnameVerifier {

public boolean verify(String s, SSLSession sslSession) {
return true;
}

public boolean verify(String s, String s1) {
return true;
}
}

Now we need to set there dummy objects into ssl context and also set them as default.

package coolsolutions.ssl.dummy;

import com.sun.net.ssl.SSLContext;
import com.sun.net.ssl.TrustManager;

import java.security.SecureRandom;
import java.security.cert.CertificateException;


public class DummySSLInitializer {


public static void initDummySsl() {
final javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[]{
new javax.net.ssl.X509TrustManager() {
public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String string)
throws CertificateException {

}

public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String string)
throws CertificateException {

}

public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}

}
};

try {

final javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new SecureRandom());
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new DummyHostnameVerifier());

com.sun.net.ssl.SSLContext sunSSLcontext = SSLContext.getInstance("TLS");
sunSSLcontext.init(null, new TrustManager[]{new DummyTrustManager()}, new SecureRandom());
com.sun.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sunSSLcontext.getSocketFactory());
com.sun.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new DummyHostnameVerifier());
} catch (final Exception e) {
e.printStackTrace();
}
}

}
Well .. Now we need to call the initDummySsl() method of the DummySSLInitializer class in the start up.
In our tutorial, if we need to apply this in the cas client, then have these bean definition in your client's applicationContext-security.xml


<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass">
<value>hsenidmobile.main.ssl.DummySslInitializer</value>
</property>
<property name="targetMethod">
<value>initDummySsl</value>
</property>
</bean>

Now what will happen is, when the application loaded, the dummy ssl initialization will happen, so everytime the client is about to verify the hostname and trust the certificate, it will just by pass the logic and proceed with the flow. It is extremely insecure, given the nature of why we need SSL in our application. I would rather recommend to use hostname [of course!] instead of this ugly method. But still it is fancy for testing purposes and applications inside a strict firewalls.


Hope these series will be helpful for you all. If you have any doubts or issues in setting up, please drop me a mail to jkumaranc AT yahoo dot com. Let me see whether I can give a hand :)

Cool
Part1 : Introduction
Part2 : Deploying CAS server
Part3 : Configuring SSL
Part4 : Deploying casified application
Part 5: How to bypass accepting certificate from client side [This Section]