Wednesday, November 11, 2009

How to access JNDI from Spring's Application Context

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/MyDataSource"/>

<bean id="userDao" class="">
<!-- Spring will do the cast automatically (as usual) -->
<property name="dataSource" ref="dataSource"/>

Tuesday, November 10, 2009

Spring JMS message consumer ( JBoss MQ )

  1. Create a new web project in eclipse.
  2. Under the WEB-INF/lib folder copy the following jar files
    1. commons-logging.jar
    2. spring.jar
    3. spring-jms.jar
  3. Create a listener bean
  4. package com.test.jms.pojo;
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.MessageListener;
    import javax.jms.TextMessage;
    public class Listener1 implements MessageListener {
     public void onMessage(Message message) {
      if (message instanceof TextMessage) {
       try {
        System.out.println(((TextMessage) message).getText());
       } catch (JMSException ex) {
        throw new RuntimeException(ex);
      } else {
       throw new IllegalArgumentException(
         "Message must be of type TextMessage");
  5. Create Spring configuration file.
  6. <beans xmlns:xsi=""
     <bean class="com.test.jms.pojo.Listener1" id="listener1">
       <property name="connectionFactory" ref="connectionFactory"></property>
       <property name="destination" ref="c8queue"></property>
       <property name="messageListener" ref="listener1"></property>
      <bean class="org.springframework.jms.core.JmsTemplate" id="jmsTemplate">
       <property name="connectionFactory" ref="connectionFactory"></property>
      <bean class="org.springframework.jndi.JndiObjectFactoryBean" id="c8queue">
       <property name="jndiName" value="queue/c8queue"></property>
       <property name="jndiTemplate" ref="jndiTemplate"></property>
       <property name="resourceRef" value="false"></property>
      <bean class="org.springframework.jndi.JndiObjectFactoryBean" id="connectionFactory">
       <property name="jndiName" value="ConnectionFactory"></property>
       <property name="jndiTemplate" ref="jndiTemplate"></property>
       <property name="resourceRef" value="false"></property>
      <bean class="org.springframework.jndi.JndiTemplate" id="jndiTemplate">
       <property name="environment">
         <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory </prop>
         <prop key="java.naming.provider.url">jnp://localhost:1099</prop>
         <prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces </prop>
  7. Create queue in Jboss
    1. In folder $JBOSS_HOME/server/default/deploy/jms create a file yourProj-service.xml
    2. <server>
       <mbean code="" name=",name=c8queue">
        <depends optional-attribute-name="DestinationManager"> </depends>
        <depends optional-attribute-name="SecurityManager"> </depends>
        <attribute name="MessageCounterHistoryDayLimit">-1</attribute>
        <attribute name="SecurityConf">
          <role name="guest" read="true" write="true">
           <role create="false" name="publisher" read="true" write="true">
            <role create="false" name="noacc" read="false" write="false"></role>
  8. Edit web.xml to load spring configuration
  9. <web-app id="WebApp_ID" version="2.5"
     xmlns:xsi="" xmlns=""
  10. Restart the server

    Monday, November 9, 2009

    Wedding shopping in Delhi

    Two weeks back me and my bro. were shopping for my wedding, I earlier decided to wear suit but then after discussion with my friends I finalized to sherwani, looking for suit for my bro we went though a lot of shops in karol bagh but we didn't find anything that justified the price. we then shifted our focus towards CP, were the collection of suits was nice and we could easily finalize suit for sumit. for sherwani my friends suggested chandini chowk, we went there and found a good collection of sherwanis, most of the shops were quite congested with little or no space to even change but the level of bargining that you do was amazing, for instance we finalized on a sherwani that the deler was quoting to be as Rs 12500, and will some barganing we were able to buy the same sherwani for Rs 5000. So whenever you are looking forward to shop for sarees, lahenga, sherwani, etc. Chandini Chowk is the place to look for.
    and if you plan to go there don't miss the paranthe wali gali and natraj ke dhahi bhalle :)

    Sunday, November 8, 2009

    Karmic Koala - a worth upgrade.

    Recently I upgraded my ubuntu from 9.04 to 9.10, and as always I am really happy after installing the new verison, its looks have improved, even the console is very beautifull, hardware support for Nvidia cards can be seen right from the installation screen. overall I would say that it is worth spending few hrs and upgrade.

    Thursday, November 5, 2009

    Mata Vaishno Devi Yatra 09

    As every year Maa called us this year also, since so many years every yatra has been memorable but this one had interesting experiences. One day before we boarded on the train on Thursday, 22nd Oct evening there were few cancellations from the people who were expected to travel with us this may sound strange but over the years I have seen this is a normal trend that happens when we plan 2 months in advance. varun on the other hand planned to join us at the eleventh hour. even the start was shaky as most of our tickets got confirmed the same day we were not sure about our coatch. but some how we found our seats and the train in an overnight journey took us to Jammu, I was surprised to see a lot of people in karta as this being not a weekend travel I was expecting much less traffic. we quickly got ready in keshav ashram, and started yatra, I was keenly looking forward towards baan ganga but it was a disappointing scene to find very less water in the stream, which draws us to a conclusion that one should not prefer planning yatra on Oct , as far as I remember I have seen ample of water when I used to come around Nov, Feb, March. I had a new camera and enjoyed taking a lot of pics all the way up and down the hill, a silly mistake from me was enough for 4 of us to miss the train (on our way back to delhi) in the end, and it will be a memorable evening how we struggled all night to find some place to sleep for few hours.

    Sunday, September 27, 2009

    My last month of being a bachelor.

    This sounds scary, isint it. Somehow I don't feel scared or over exited or anything like that. One month from now I am going to get married with a girl whome I have known since quite some time now, I am happy that I am stepping into the next phase of this "circle of life", I don't know how most of the people at this stage would be feeling like but I am sure they too must be feeling some sort of mixed feelings including the fear that they i'll loose the indipendence that they are used to, increased financial focus to save and spend very conservatively, now you won't have to cook anymore :), a slight fear that the new person will gel well with your family or not, and finally a big time question of whether this is the starting point or the end point of happiness in your life.
    Statistics collected from the people that I know who got married it looks like life becomes more stabilized and organised and you become a serious person. If you are a software developer I can put in simple words it is like you started using frameworks rather that adhoc coding methodologies :)
    Last few weeks some of my friends put up a question to me saying you must be very exited as it is just around a month left for your marriage, humm.... it was a difficult question for me, I have asked this question to me many times that are people during this time on the seventh sky, or they are too troubled by the questions going in their head. because I for sure don't see my self on seventh sky but in my case I know her since quite some time and so the understanding is quite clear and the question don't seem to bother me a lot, and thats when I start analyzing that I am so boring kind of a person, or people of my age group closing in to thirty become like this.
    I am quite positive overall, I am not working too hard on it, not changing anything in my lifestyle, not planning too much and just trying to wait and watch how life takes this twist.

    Saturday, September 26, 2009

    Which internal TV Tuner should you buy for Linux (Ubuntu 9.04)

    If you are in India there is a TV tuner available with the name Tech Com ( SSD-TV-675) this card works out of box with Ubuntu 9.10, it has a Philips 7130 chipset.

    Work with Messaging Queues (JMS) without an Application Server

    Ever been to a situation where your web application running on Tomcat has to exchange messages with a queue (JMS) , try Mule ESB.

    Java Interview Questions

    These questions my previous company used to ask during an interview session.

    difference between abstraction & encapsulation.
    difference between aggregation and composition.
    what is polymorphism
    difference between method overloading and method overriding.
    what is dynamic class loading and static class loading
    what are class variables

    what is the difference between class variables and instance variables are static variables class variables.

    what do know about serialization
    explain collection framework hirerchy
    what is the difference between arraylist and vector
    what are webservices
    how do u create a request for webservice
    format of response from webservice
    explain MVC architecture
    what is the use of TAG libraries in JSP
    life cycle of formbean (in struts) when it is called first time etc.
    in context to struts, how do you show errors in JSP

    Monday, August 24, 2009

    PHP Framework - CodeIgniter

    After working in Java for a couple of years I was more or less in love with the nice frameworks the language has Spring, Hibernate, Struts to name a few this was something which I always felt was missing in PHP, I have herd quite a lot about cake but never used it, I tried learning symfony some time back but it was kinda difficult to learn and implement, recently was working on a project at my home, and I started looking for options that I had for PHP frameworks, I came across this new name CodeIgniter, I had a look at its video tutorial, it looked fantastic in first sight, I started using it in my project, after having it used for a around a month I now feel that PHP no more lacks a quality framework, I don't know about others but CodeIgniter is really cool.

    Saturday, August 22, 2009

    Java Interview Questions

    I was recently interviewed for a project, here is a log of questions.
    1. Threads have priorities 1 to 9, which is the highest and which one is the lowest.
    2. I have a class which has two methods add and subtract, both the methods are synchronized, a thread went into add method and the same time another thread tries to get into subtract method, which it wait for first thread to complete add or will it go into subtract thread.
    3. What are critical sections.
    4. Which one is a better practice to have functions synchronized or to have synchronize block.
    5. What are the different states that a thread goes through.
    Servlets & JSP
    1. what are servlet config and servlet context, how are they different than each other.
    2. What are the different ways of maintaining session.
    3. How do we maintain session in a clustered environment.
    4. Describe life cycle of a JSP.
    1. What is heap memory.
    2. What are Xms and Xms.
    3. How do we maintain transactions in Hibernate.
    4. What are Spring IOC and Dependency Injection, how are they different than each other.
    5. What are the benifits of using Spring IOC.
    6. I have a class which has two variables name and roll no, this class is serialized, now I have two different conditions in one I do not want rollno to ge serialized, how can serialized interface help me in this.

    Monday, July 13, 2009

    Last few years

    I wanted to document this since around a year now but didn't get enough time, life has become busy, Well this story started long back when I used to work in small companies and I always dreamed to someday join big software companies CMM3 or CMM5 level, after around 3 years of working in small companies I joined a news media organization which had an online division. I worked there for over two and a half years all this time was amazing, full of fun, learning and experimenting, I almost fell in love creating and maintaining heavy traffic web applications. I clearly remember there was a day when my manager asked me that sometimes he wonders what makes me stay in that company in such small salary at the back of my head I always knew that what I am learning is far more precious than the salary that I am drawing. It was not that I always wrote nice code as a software engineer adds years to his experience he refines himself in how to code efficiently, the news company being a product company gave me enough of opportunity to improve upon my skills and gave me and my team the liberty to write good code which we could maintain for a long time, well at first this may sound foolish that which company won't like to give time to write good code but the fact is bitter, managers want things done in stiff timelines and they are most of the time ready to compromise on the quality of code. as a result of which a large chunk of developers never learn quality coding and if few wants to write good code they get frustrated while almost forced to write bad code.
    In the same company once our marketing manager advised the business manager that instead of building a big technical team for development for online applications we should get most of the things outsourced to IT companies, when my manager put this idea in front of me I was also happy that we as a technical team can now focus on bigger aspects rather than just coding, but then I asked my manager that who would guarantee the quality of code that we get from the outsourcing company, I mean it is fine that they give us a working application once but then if we have to maintain it, it should be good in terms of code quality and so I suggested that invite some CMMi Level 5 company, due to budget limitations we could not afford CMMi 5 companies and a small company was invited who had an experience in News media portals, we gave them a small project first it was very expensive ( compared to be done by our in-house team) and the quality was pathetic. I was not happy and kept pinging my manager about that that if we cannot afford a cmm5 we better do it ourself. That company was not given anymore projects and we continued to work with our in-house team.
    After working for a long time in this wonderful company I decided to move on, my plan to do so was not because there was some problem with the job but I slowly started feeling that I am getting outdated in terms of technology and my hunger to code in cutting edge technologies was not getting satisfied. First big hurdle was the technology that I worked in LAMP it is an excellent stack for websites but big software companies mostly used Java for their projects. but I still managed to get into a mid sized CMMI Level 5 company in Delhi, getting into this company was a dream come true to me as I wanted to get into on such since long time now. I joined this organization as a Technical Analyst and my first task was to tune up MySQL stored procedures for an American Airline company. I was being billed to the client but I was not getting work to do, initially I felt bad about wasting me time in office and taking home salary, but very quickly I realized that there are no projects in the technology that I am used to work on, I was heart broken as this was someplace that I always wanted to be into and now when I was there these guys had no work for me, so I bought books and started reading, I read struts once, didn't understand much, read the book again because I had 8 hrs a day to read books, this was amazing I quickly started picking up java, and some very helpful people around helped me out while I used to write some sample code, after some time I was moved to another project that had Mainframe to Open source migration and the code was to be written in Java, I was worked in Java very actively over there and got confidence that I can code in this language. one thing more that I learnt in my one year spent in this company was that even CMMi Level 5 companies do not write good code ( I agree that exceptions are always there ) I felt that the kind of code that teams are churning out is no way of any standard compared to what companies showcase themselves as.
    Code quality and job security were my top concerns when I again started looking out, my luck was good this time and I got hired by one of the top Indian Software company, It has been ~11 months me being here, all this time I have coded for 12 hrs everyday and learnt Spring, hibernate, webservices, etc. and I am happy to find some people who are concerned about the quality of code.

    Saturday, July 11, 2009

    VMWare Workstation 6.5 not working with Ubuntu 9.04 x64

    Recently I had a tough time working with Ubuntu 9.04 x64 on my desktop, one of the issue was that Google Appengine plugin for eclipse was giving error ( as of now they don't have a 64 bit version for GWT plugin) and the second was VMWare 6.5, after some googling around this VMWare issue got resolved just run the script provided at and VMWare will work

    Sunday, May 3, 2009

    Avertv ultra 116 not working in linux

    Recently I bought a desktop and installed my fav OS Ubuntu, this time I tried their latest release 9.04 64bit. with my new machine I bought a TV tuner card avertv ultra 116, It has now been a struggle for over a week to get it working, still no results. in ghaziabad I used avertv super 007 it was some struggle to get it working but after some time it worked great, this one seems give even more pain to get it flying.

    Friday, May 1, 2009

    Setting up a svn (Subversion) server

    Easy steps to setup svn server on your linux machine.
    #useradd repos
    #su repos
    $svnadmin create ~/repository1
    $vi ~/repository1/conf/svnserv.conf
    anon-access = read
    auth-access = write
    $svn import /projects/myproj file:///home/repos/repository1/myroj
    #svnserve -d

    Sunday, March 8, 2009

    Eclipse Ganymede not working on Ubuntu 8.04 ( Hardy Heron)

    This is something that I also faced quite a number of times when I used to work on Hardy, this time again one of my friend got stuck in the same issue as he starts Ganymede he gets a popup prompt with nothing written in it.
    a little googleing leads to these steps that work..

    sudo apt-get install xulrunner
    append to eclipse.ini

    Sunday, February 22, 2009

    Ubuntu 8.10 is good

    Nice work by ubuntu team again, I liked everything after I installed it, especially my wifi, webcam, ( Dell 1525 lappy) worked out-of-box.

    One thing slightly missing mplayer in the add remove programs small googling and u find this, I am looking fwd towards 9.