API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.web.server. JOTWebRequestHandlerBase View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.jot.web.server;

import java.net.Socket;
import java.util.Date;
import net.jot.logger.JOTLogger;
import net.jot.logger.JOTLoggerLocation;

/**
 * Base implementation of a request handler providing a parsed request object
 * giving easy access to request and response
 * TODO: provide a response helper too
 * @author thibautc
 */
public abstract class JOTWebRequestHandlerBase implements JOTServerRequestHandler
{

    private Socket socket;
    public JOTWebRequest request;
    public JOTWebResponse response;
    private static final JOTLoggerLocation logger=new JOTLoggerLocation(JOTLogger.CAT_SERVER,JOTWebRequestHandlerBase.class);

    public void handle(Socket socket) throws Exception
    {
        long startTime=-1;
        if(logger.isDebugEnabled())
        {
            startTime=new Date().getTime();
        }

        this.socket = socket;
        request = JOTRequestParser.parseRequest(socket);
        response = new JOTWebResponse(socket, request);
        handle();
        // note: that wil cleanup the request too
        response.destroy();

        if(logger.isDebugEnabled())
        {
            long time=new Date().getTime()-startTime;
            logger.debug("Handled the request "+request.getServletPath()+" in "+time+" ms");
        }
    }

    /**
     * Implement this to handle your requesthandler.
     * Note that you can/should make use of the provided "request" object. 
     */
    public abstract void handle() throws Exception;
}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar