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: 135.2 KB): HTTPS / SSH
$ hg clone http://hg.openstatic.org/placebohttp
commit 34: c7dfd452b26c
parent 33: 76efabe6b8ff
branch: default
added showdata feature for vikram
xitiomet
4 months ago

Changed (Δ1.6 KB):

raw changeset »

src/PlaceboBase.java (11 lines added, 2 lines removed)

src/org/openstatic/http/HttpRequest.java (13 lines added, 0 lines removed)

src/org/openstatic/http/PlaceboHttpServer.java (11 lines added, 0 lines removed)

src/org/openstatic/placebo/ControlPanel.java (12 lines added, 0 lines removed)

src/org/openstatic/placebo/CoreServer.java (8 lines added, 0 lines removed)

Up to file-list src/PlaceboBase.java:

@@ -10,7 +10,8 @@ public class PlaceboBase
10
10
    {
11
11
        System.err.println("Openstatic.org HTTP Server");
12
12
        System.err.println("");
13
        System.err.println("  --debug                        Turn debugging output on.");
13
        System.err.println("  --debug                        Turn debugging output on");
14
        System.err.println("  --showdata                     Show response data (debug must be on)");
14
15
        System.err.println("  --root [path]                  Set webroot");
15
16
        System.err.println("  --port [port]                  Specify HTTP listening port");
16
17
        System.err.println("  --help                         display this menu");
@@ -22,8 +23,9 @@ public class PlaceboBase
22
23
    
23
24
    public static void main(String[] args)
24
25
    {
25
        int http_port = 80;
26
        int http_port = 8090;
26
27
        boolean debug = false;
28
        boolean show_data = false;
27
29
        String web_root = "placebohttp.jar/www";
28
30
        boolean start_engine = false;
29
31
        Hashtable<String, String> plugins = new Hashtable<String, String>();
@@ -71,6 +73,11 @@ public class PlaceboBase
71
73
                System.err.println("----------------------------------");
72
74
                debug = true;
73
75
            }
76
77
            if (arg.equals("--showdata"))
78
            {
79
                show_data = true;
80
            }
74
81
            
75
82
            if (arg.equals("--headless"))
76
83
            {
@@ -86,6 +93,7 @@ public class PlaceboBase
86
93
            x.setPort(http_port);
87
94
            x.setWebRoot(web_root);
88
95
            x.setDebug(debug);
96
            x.setShowData(show_data);
89
97
            x.start();
90
98
            x.addPlugins(plugins);
91
99
        } else {
@@ -93,6 +101,7 @@ public class PlaceboBase
93
101
            cp.setPort(http_port);
94
102
            cp.setWebRoot(web_root);
95
103
            cp.setDebug(debug);
104
            cp.setShowData(show_data);
96
105
            cp.setPlugins(plugins);
97
106
        }
98
107
    }

Up to file-list src/org/openstatic/http/HttpRequest.java:

@@ -123,9 +123,22 @@ public class HttpRequest
123
123
        try
124
124
        {
125
125
            int inputByte;
126
            if (this.myServer.isShowData())
127
            {
128
                this.myServer.getDebugStream().println("-------------Outbound Data-------------");
129
            }
126
130
            while ( (inputByte = data.read()) > -1 )
127
131
            {
128
132
                this.socket_output_stream.write(inputByte);
133
                if (this.myServer.isShowData())
134
                {
135
                    this.myServer.getDebugStream().print((char) inputByte);
136
                }
137
            }
138
            if (this.myServer.isShowData())
139
            {
140
                this.myServer.getDebugStream().println("");
141
                this.myServer.getDebugStream().println("---------------------------------------");
129
142
            }
130
143
            data.close();
131
144
            this.socket_output_stream.flush();

Up to file-list src/org/openstatic/http/PlaceboHttpServer.java:

@@ -13,6 +13,7 @@ public class PlaceboHttpServer extends T
13
13
    private String myName;
14
14
    private PrintStream debug_stream;
15
15
    private boolean debug_mode;
16
    private boolean show_data;
16
17
    private boolean keep_running;
17
18
    private Hashtable<String, PlaceboSession> sessions;
18
19
    private LinkedBlockingQueue<PlaceboSession> session_queue;
@@ -166,11 +167,21 @@ public class PlaceboHttpServer extends T
166
167
    {
167
168
        this.debug_mode = value;
168
169
    }
170
171
    public void setShowData(boolean value)
172
    {
173
        this.show_data = value;
174
    }
169
175
    
170
176
    public boolean isDebug()
171
177
    {
172
178
        return this.debug_mode;
173
179
    }
180
181
    public boolean isShowData()
182
    {
183
        return this.show_data;
184
    }
174
185
    
175
186
    public void setDebugStream(OutputStream value)
176
187
    {

Up to file-list src/org/openstatic/placebo/ControlPanel.java:

@@ -39,6 +39,7 @@ public class ControlPanel extends JFrame
39
39
    private JTextField url_path;
40
40
    private JTextField url_class_name;
41
41
    private JCheckBox debug_field;
42
    private JCheckBox show_data_field;  
42
43
    private DefaultListModel apps;
43
44
    private DefaultListModel sessions;
44
45
    private JTextAreaOutputStream log_output;
@@ -65,6 +66,11 @@ public class ControlPanel extends JFrame
65
66
    {
66
67
        this.debug_field.setSelected(value);
67
68
    }
69
70
    public void setShowData(boolean value)
71
    {
72
        this.show_data_field.setSelected(value);
73
    }
68
74
    
69
75
    public void setWebRoot(String value)
70
76
    {
@@ -119,6 +125,9 @@ public class ControlPanel extends JFrame
119
125
        JLabel debug_label = new JLabel("Debug:", JLabel.TRAILING);
120
126
        debug_field = new JCheckBox();
121
127
128
        JLabel show_data_label = new JLabel("Show Data:", JLabel.TRAILING);
129
        show_data_field = new JCheckBox();
130
122
131
        start_btn = new JButton("Start Server");
123
132
        start_btn.setActionCommand("start");
124
133
        start_btn.addActionListener(this);
@@ -134,6 +143,8 @@ public class ControlPanel extends JFrame
134
143
        pane.add(root_field);
135
144
        pane.add(debug_label);
136
145
        pane.add(debug_field);
146
        pane.add(show_data_label);
147
        pane.add(show_data_field);
137
148
        main_pane.add(pane, BorderLayout.PAGE_START);
138
149
        
139
150
        JPanel button_pane = new JPanel(new GridLayout(0,2,6,6));
@@ -243,6 +254,7 @@ public class ControlPanel extends JFrame
243
254
            core.setPort(Integer.valueOf(port_field.getText()).intValue());
244
255
            core.setWebRoot(root_field.getText());
245
256
            core.setDebug(debug_field.isSelected());
257
            core.setShowData(show_data_field.isSelected());
246
258
            core.setDebugStream(log_output);
247
259
            
248
260
            core.start();

Up to file-list src/org/openstatic/placebo/CoreServer.java:

@@ -23,6 +23,7 @@ public class CoreServer extends Thread
23
23
    private int http_port;
24
24
    private String web_root;
25
25
    private boolean debug;
26
    private boolean show_data;
26
27
    private OutputStream debug_out;
27
28
    private boolean keep_running;
28
29
    private PlaceboHttpServer server;
@@ -35,6 +36,7 @@ public class CoreServer extends Thread
35
36
        this.debug_out = System.err;
36
37
        this.keep_running = true;
37
38
        this.debug = false;
39
        this.show_data = false;
38
40
        this.server = new PlaceboHttpServer(http_port);
39
41
        this.plugins = new Hashtable<String, PlaceboPlugin>();
40
42
    }
@@ -124,6 +126,11 @@ public class CoreServer extends Thread
124
126
        this.debug = value;
125
127
    }
126
128
    
129
    public void setShowData(boolean value)
130
    {
131
        this.show_data = value;
132
    }
133
    
127
134
    public void setWebRoot(String value)
128
135
    {
129
136
        this.web_root = value;
@@ -150,6 +157,7 @@ public class CoreServer extends Thread
150
157
    {
151
158
        // Create new server object
152
159
        server.setDebug(debug);
160
        server.setShowData(show_data);
153
161
        server.setDebugStream(debug_out);
154
162
        server.setPort(this.http_port);
155
163
        // Launch thread.