01: /*
02: * $Id: Main.java 6825 2006-04-04 03:00:44Z dfs $
03: *
04: * Copyright 2001,2006 Daniel F. Savarese
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.savarese.org/software/ApacheLicense-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package org.savarese.barehttp;
20:
21: import java.io.IOException;
22:
23: /**
24: * The BareHTTP server, a sample program that starts an {@link HTTPServer}
25: * instance. The program expects two arguments: a port
26: * number and a fully-qualified directory pathname specifying the
27: * document root. It could easily be expanded to allow the
28: * specification of a binding address and maximum number of
29: * connections.
30: *
31: * @author <a href="http://www.savarese.org/">Daniel F. Savarese</a>
32: */
33: public final class Main {
34:
35: private Main() {
36: }
37:
38: // Static only so we can stop the server in a unit test.
39: static HTTPServer server = null;
40:
41: /**
42: * Starts an {@link HTTPServer} instance on a specified port
43: * allowing {@link HTTPServer#DEFAULT_MAX_CONNECTIONS}. No
44: * provisions are made for terminating the program. The program
45: * must be terminated by SIGKILL, Ctrl-C, or whatever OS-specific
46: * mechanism exists to kill a running process.
47: *
48: * @param args The program arguments: a port number and document
49: * root directory.
50: * @throws Exception if the {@link HTTPServer} cannot be instantiated
51: * or started.
52: */
53: public static void main(String[] args) throws IOException {
54: if (args.length != 2) {
55: System.err.println("usage: HTTPServer port documentRoot");
56: return;
57: }
58:
59: server = new HTTPServer(args[1], Integer.parseInt(args[0]),
60: HTTPServer.DEFAULT_MAX_CONNECTIONS);
61:
62: server.start();
63: }
64:
65: }
|