Wednesday, May 5, 2010

Use Jetty with Spring

1) Insert these beans to the application-context.xml

    <bean name="smpp.gw.httpListener" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="destroy">
        <constructor-arg index="0" value="8080"/>
        <property name="handler" ref="smsc.mtHttpRequestHandler"/>
    </bean>

    <bean id="anyHandler" class="path.to.AnyHandler">
            ..................................
            ..................................
    </bean>

2) The "AnyHandler" class shold have to extends the AbstractHandler class.

     import org.eclipse.jetty.server.Request;
     import org.eclipse.jetty.server.handler.AbstractHandler;

     import javax.servlet.ServletException;
     import javax.servlet.http.HttpServletRequest;
     import javax.servlet.http.HttpServletResponse;
     import java.io.IOException;
    
     public class HttpRequestHandler extends AbstractHandler {

        public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
            System.out.println(">>>> Request received. <<<");
            // Can do anything using request and response
            ......................................
            ......................................
        }
    }

Thursday, February 18, 2010

Ten Techniques To Transform

Hi Friends...
I'm going to die...... :( I can't find any medicine to treat this illness. But fortunately i met two specialist. Both of them were overcome this illness earlier. So they ask me to follow 10 medical treatments to change my life style. I believe i can .....!!!

1) Build up the confidence among others.
2) Select what you can do.
3) Continuous progress.
4) Don't be fear to know what you don't know.
5) Start from any where, don't waist time to find the best.
6) Make the good things be habits.
7) Tell all the issues when doing some thing before the end.
8) Learn the concepts not the technology.
9) Break down to small peace's when you got a task. (Divide and conquer)
10) THINK how to OVERCOME.

Friday, December 18, 2009

Spring : Create instance with constructor arguments

If our java class has a constructor like this with argument.

public class Home() {
    private String name;

    public Home(String s) {
         name = s;   
    }
}

We can write our spring bean like this.

       <bean id="home1" class="<class.path>.Home">
           <constructor-arg value="My_Home"/>
       </bean>

Sunday, November 8, 2009

Cron job for linux.



For more information visit to the original site.
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Example(s)

If you wished to have a script named /root/backup.sh run every day at 3am, my crontab entry would look like as follows:

(a) Install your cronjob:
<code> # crontab -e
</code>(b)Append following entry:
<code>0 3 * * * /root/backup.sh
</code>Run five minutes after midnight, every day:<code>
5 0 * * * /path/to/command</code>
Run at 2:15pm on the first of every month:
<code>15 14 1 * * /path/to/command
</code>Run at 10 pm on weekdays:<code>
0 22 * * 1-5 /path/to/command </code>
Run 23 minutes after midnigbt, 2am, 4am ..., everyday:<code>
23 0-23/2 * * * /path/to/command
</code>Run at 5 after 4 every sunday:<code>
5 4 * * sun /path/to/command</code>

How do I disabling Email output?

By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1.<br /> For example:
0 3 * * * /root/backup.sh >/dev/null 2>&1


To mail output to particluer email account let us say vivek@nixcraft.in you need to define MAILTO variable to your cron job:
MAILTO="vivek@nixcraft.in"
0 3 * * * /root/backup.sh >/dev/null 2>&1



Thursday, August 20, 2009

The BASEDIR environment variable is not defined correctly

Tomcat Issue

The BASEDIR environment variable is not defined correctly
This environment variable is needed to run this program

This will occur due to using a copy of tomcat which is packed someone else.

The solution for this is go to the bin and change the mod into 777 of all .sh file.
chmod 777 *.sh