01: /******************************************************************************
02: * Copyright (C) Lars Ivar Almli. All rights reserved. *
03: * ---------------------------------------------------------------------------*
04: * This file is part of MActor. *
05: * *
06: * MActor is free software; you can redistribute it and/or modify *
07: * it under the terms of the GNU General Public License as published by *
08: * the Free Software Foundation; either version 2 of the License, or *
09: * (at your option) any later version. *
10: * *
11: * MActor is distributed in the hope that it will be useful, *
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14: * GNU General Public License for more details. *
15: * *
16: * You should have received a copy of the GNU General Public License *
17: * along with MActor; if not, write to the Free Software *
18: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
19: ******************************************************************************/package org.mactor.brokers.http;
20:
21: import java.util.HashMap;
22: import java.util.Map;
23:
24: /**
25: * Singleton that maintains all http servers
26: *
27: * @author Lars Ivar Almli
28: */
29: public class HttpServerManager {
30: private static Map<String, HttpServer> servers = new HashMap<String, HttpServer>();
31:
32: public static synchronized HttpServer getHttpServer(
33: int listeningPort) {
34: String port = listeningPort + "";
35: if (!servers.containsKey(port)) {
36: HttpServer s = new HttpServer(listeningPort);
37: servers.put(port, s);
38: }
39: return servers.get(port);
40: }
41:
42: public static void main(String[] args) throws Exception {
43: HttpServer s = getHttpServer(5551);
44: s.addRequestListener("/abc", new HttpRequestListener() {
45: public HttpResponse onRequest(HttpRequest request) {
46: HttpResponse r = new HttpResponse();
47: r.setData("<a>yes</a>".getBytes());
48: r.addHeader("Content-type", "text/xml");
49: return r;
50: }
51: });
52: }
53: }
|