API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.web.server.impl. JOTStaticWebServer 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

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

import java.util.Hashtable;
import net.jot.logger.JOTLogger;
import net.jot.logger.JOTLoggerLocation;

/**
 * Implements a minimalistic web server (static content)
 * It just serves content in the root folder and allow browsing/ looking at content
 * within rootFolder and subfolders.
 * Only support the http GET method.
 * @author tcolar
 */
public class JOTStaticWebServer {

    public final JOTMiniServer server = new JOTMiniServer();
    public final static String ROOT_FOLDER = "ROOT_FOLDER";
    JOTLoggerLocation logger=new JOTLoggerLocation(JOTLogger.CAT_SERVER,getClass());

    public void start(int port, String rootFolder)
    {
        try
        {
            Hashtable params=new Hashtable();
            params.put(ROOT_FOLDER,rootFolder);
            logger.info("Server started on port "+port);
            System.out.println("Server started on port "+port);
            server.start(port, JOTStaticServerHandler.class, params);
        } catch (Exception e)
        {
            logger.exception("Failed starting the server.", e);
            System.out.println("Failed starting the server.");
            e.printStackTrace();
        }
    }

    public void stop()
    {
        server.stop();
    }

    public static void main(String args[])
    {
        new JOTStaticWebServer().start(8066,"/tmp/");
    }
}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar