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.core.examples.servlet;
28:
29: import java.io.IOException;
30: import java.io.PrintWriter;
31: import javax.servlet.http.HttpServletRequest;
32: import javax.servlet.http.HttpServletResponse;
33: import org.cougaar.core.servlet.ComponentServlet;
34:
35: /**
36: * A servlet that listens on path "/hello" and prints "hello world!"
37: * back to the client.
38: * <p>
39: * To load this servlet, add the following to any agent's XML
40: * configuration:<pre>
41: * <component
42: * class="org.cougaar.core.examples.servlet.HelloServlet">
43: * <argument>/hello</argument>
44: * </component>
45: * </pre>
46: * For example, if this component was added to agent "X", the browser
47: * URL to invoke this servlet would be:<pre>
48: * <a href="http://localhost:8800/$X/hello">
49: * http://localhost:8800/$X/hello</a>
50: * </pre>
51: * <p>
52: * Although not illustrated below, this servlet's subclassing of
53: * "ComponentServlet" allows it to access the agent's ServiceBroker
54: * just like a regular Cougaar plugin.
55: */
56: public class HelloServlet extends ComponentServlet {
57: public void doGet(HttpServletRequest request,
58: HttpServletResponse response) throws IOException {
59: response.setContentType("text/html");
60: PrintWriter out = response.getWriter();
61: out.print("Hello world!");
62: }
63: }
|