001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2007 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.lib.web.micro.base;
028:
029: import java.io.BufferedReader;
030: import java.io.IOException;
031: import java.io.PrintWriter;
032: import java.util.Enumeration;
033: import javax.servlet.ServletException;
034: import javax.servlet.http.HttpServlet;
035: import javax.servlet.http.HttpServletRequest;
036: import javax.servlet.http.HttpServletResponse;
037:
038: /**
039: * This servlet is a minimal test servlet for server debugging.
040: */
041: public class SnoopServlet extends HttpServlet {
042:
043: public void doGet(HttpServletRequest req, HttpServletResponse res)
044: throws IOException, ServletException {
045: if ("/404".equals(req.getRequestURI())) {
046: res.sendError(404, "not found");
047: PrintWriter out = res.getWriter();
048: out.println("not_found_here");
049: return;
050: }
051:
052: res.setContentType("text/html");
053: PrintWriter out = res.getWriter();
054: out.println("<html><body><h1>HELLO WORLD!</h1><p>");
055:
056: out.println("<pre>");
057: out.println("req.serverName=" + req.getServerName());
058: out.println("req.serverPort=" + req.getServerPort());
059: out.println("req.remoteAddr=" + req.getRemoteAddr());
060: out.println("req.remoteHost=" + req.getRemoteHost());
061: out.println("req.secure=" + req.isSecure());
062: out.println("req.scheme=" + req.getScheme());
063: out.println("req.protocol=" + req.getProtocol());
064: out.println("req.contentLength=" + req.getContentLength());
065: out.println("req.contentType=" + req.getContentType());
066: for (Enumeration en = req.getParameterNames(); en
067: .hasMoreElements();) {
068: String s = (String) en.nextElement();
069: out.println("req.param " + s + "=" + req.getParameter(s));
070: }
071: out.println("req.method=" + req.getMethod());
072: out.println("req.pathInfo=" + req.getPathInfo());
073: out.println("req.servletPath=" + req.getServletPath());
074: out.println("req.queryString=" + req.getQueryString());
075: out.println("req.requestURI=" + req.getRequestURI());
076: out.println("req.requestURL=" + req.getRequestURL());
077: for (Enumeration en = req.getHeaderNames(); en
078: .hasMoreElements();) {
079: String s = (String) en.nextElement();
080: out.println("req.header " + s + "=" + req.getHeader(s));
081: }
082: BufferedReader br = req.getReader();
083: while (true) {
084: String s = br.readLine();
085: if (s == null)
086: break;
087: out.println("req.body " + s);
088: }
089: out.println("</pre>");
090:
091: out.print("<form method=\"GET\" action=\"");
092: out.print(req.getRequestURI());
093: out.println("\">");
094: out.println("Foo: <select name=\"foo\">");
095: out.println(" <option>Alpha</option>");
096: out.println(" <option>Beta</option>");
097: out.println("</select>");
098: out.println("<input type=\"submit\" value=\"Submit\">\n"
099: + "</form>");
100:
101: out.println("</body></html>");
102: }
103: }
|