xitiomet is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

xitiomet / placebohttp http://openstatic.org/

Embeded Http server for gcj/java applications. PlaceboHttp uses an automatic session management system, Treating each session as a HttpRequest queue.

Clone this repository (size: 154.6 KB): HTTPS / SSH
hg clone https://bitbucket.org/xitiomet/placebohttp
hg clone ssh://hg@bitbucket.org/xitiomet/placebohttp

placebohttp / src / PlaceboBase.java

/*
    Copyright (C) 2010 Brian Dunigan

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import org.openstatic.placebo.CoreServer;
import org.openstatic.placebo.ControlPanel;

import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Properties;

public class PlaceboBase
{
    public static void help()
    {
        System.err.println("Openstatic.org HTTP Server");
        System.err.println("");
        System.err.println("  --debug                        Turn debugging output on");
        System.err.println("  --showdata                     Show response data (debug must be on)");
        System.err.println("  --root [path]                  Set webroot");
        System.err.println("  --port [port]                  Specify HTTP listening port");
        System.err.println("  --help                         display this menu");
        System.err.println("  --plugin [path] [class]        Add A plugin to server");
        System.err.println("  --headless                     Start up without swing");
        System.err.println("  --start                        Start server immediately");
        System.err.println("  --var [key] [val]              Define global variable for plugins");
        System.err.println("");
        System.err.println("");
    }
    
    public static void main(String[] args)
    {
        int http_port = 9040;
        boolean debug = false;
        boolean show_data = false;
        boolean start_gui = false;
        String web_root = "placebohttp.jar/www";
        boolean start_engine = false;
        Hashtable<String, String> plugins = new Hashtable<String, String>();
        Properties global_settings = new Properties();

        for (int i = 0; i < args.length; i++)
        {
            String arg = args[i].toLowerCase();
            String arg_p1 = null;
            String arg_p2 = null;
            
            if (i + 1 < args.length)
            {
                arg_p1 = args[i+1];
            }
            
            if (i + 2 < args.length)
            {
                arg_p2 = args[i+2];
            }
            
            if (arg.equals("--port"))
            {
                http_port = Integer.valueOf(arg_p1);
            }

            if (arg.equals("--help"))
            {
                help();
                System.exit(0);
            }

            if (arg.equals("--var"))
            {
                global_settings.setProperty(arg_p1, arg_p2);
            }

            if (arg.equals("--root"))
            {
                web_root = arg_p1;
            }
            
            if (arg.equals("--plugin"))
            {
                plugins.put(arg_p1, arg_p2);
            }
            
            if (arg.equals("--debug"))
            {
                System.err.println("Openstatic.org Placebo HTTP Server");
                System.err.println("----------------------------------");
                debug = true;
            }

            if (arg.equals("--showdata"))
            {
                show_data = true;
            }
            
            if (arg.equals("--headless"))
            {
                start_engine = true;
            }
            
            if (arg.equals("--start"))
            {
                start_gui = true;
            }
        }
        
        
        
        if (start_engine)
        {
            CoreServer x = new CoreServer(global_settings);
            x.setPort(http_port);
            x.setWebRoot(web_root);
            x.setDebug(debug);
            x.setShowData(show_data);
            x.start();
            x.addPlugins(plugins);
        } else {
            ControlPanel cp = new ControlPanel();
            cp.setGlobalSettings(global_settings);
            cp.setPort(http_port);
            cp.setWebRoot(web_root);
            cp.setDebug(debug);
            cp.setShowData(show_data);
            cp.setPlugins(plugins);
            if (start_gui)
            {
                cp.start_server();
            }
        }
    }
    
}