01: /*
02: * <copyright>
03: *
04: * Copyright 2000-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.lib.web.service;
28:
29: import java.io.IOException;
30: import java.io.PrintWriter;
31: import java.util.List;
32: import java.util.Random;
33:
34: import javax.servlet.Servlet;
35: import javax.servlet.ServletConfig;
36: import javax.servlet.ServletException;
37: import javax.servlet.ServletRequest;
38: import javax.servlet.ServletResponse;
39: import javax.servlet.http.HttpServletRequest;
40: import javax.servlet.http.HttpServletResponse;
41:
42: import org.cougaar.lib.web.arch.ServletRegistry;
43: import org.cougaar.lib.web.arch.root.GlobalRegistry;
44:
45: /**
46: * A servlet that generates a top-level HTML welcome page in response
47: * to the "/" path.
48: */
49: public class WelcomeServlet implements Servlet {
50:
51: private final String localNode;
52:
53: public WelcomeServlet(String localNode) {
54: this .localNode = localNode;
55: }
56:
57: public void service(ServletRequest sreq, ServletResponse sres)
58: throws ServletException, IOException {
59:
60: // cast
61: HttpServletRequest req = (HttpServletRequest) sreq;
62: HttpServletResponse res = (HttpServletResponse) sres;
63:
64: // write response
65: res.setContentType("text/html");
66: PrintWriter out = res.getWriter();
67: out
68: .print("<html><head><title>"
69: + "Welcome to Cougaar"
70: + "</title></head><body>\n"
71: + "<h2>Welcome to "
72: + "<a href=\"http://www.cougaar.org\">Cougaar</a></h2>\n"
73: + "Options:<ul>\n"
74: + "<li><a href=\"/agents\"><b>Local</b> agents on node "
75: + localNode
76: + "</a></li><p>\n"
77: + "<li><a href=\"/agents?suffix=.\"><b>All</b> agents in the society</a>"
78: + "</li>\n" + "</ul>\n" + "</body></html>");
79: out.close();
80: }
81:
82: // etc
83: private ServletConfig config;
84:
85: public void init(ServletConfig config) {
86: this .config = config;
87: }
88:
89: public ServletConfig getServletConfig() {
90: return config;
91: }
92:
93: public String getServletInfo() {
94: return "welcome";
95: }
96:
97: public void destroy() {
98: }
99: }
|