01: /*
02: * Copyright (c) xsocket.org, 2006 - 2008. All rights reserved.
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
19: * The latest copy of this software may be found on http://www.xsocket.org/
20: */
21: package org.xsocket.connection.http;
22:
23: import java.io.IOException;
24: import java.io.PrintWriter;
25: import java.util.Enumeration;
26:
27: import javax.servlet.ServletException;
28: import javax.servlet.http.HttpServlet;
29: import javax.servlet.http.HttpServletRequest;
30: import javax.servlet.http.HttpServletResponse;
31:
32: /**
33: *
34: * @author grro@xsocket.org
35: */
36: public final class HeaderInfoServlet extends HttpServlet {
37:
38: private static final long serialVersionUID = 6489398831844159793L;
39:
40: @Override
41: protected void doGet(HttpServletRequest req,
42: HttpServletResponse resp) throws ServletException,
43: IOException {
44: handle("GET", req, resp);
45: }
46:
47: @Override
48: protected void doPost(HttpServletRequest req,
49: HttpServletResponse resp) throws ServletException,
50: IOException {
51: handle("POST", req, resp);
52: }
53:
54: @SuppressWarnings("unchecked")
55: private void handle(String method, HttpServletRequest req,
56: HttpServletResponse resp) throws ServletException,
57: IOException {
58: resp.setContentType("text/plain");
59: PrintWriter writer = resp.getWriter();
60:
61: writer.write("method= " + method + "\r\n");
62:
63: for (Enumeration<String> en = req.getHeaderNames(); en
64: .hasMoreElements();) {
65: String headername = en.nextElement();
66:
67: for (Enumeration<String> en2 = req.getHeaders(headername); en2
68: .hasMoreElements();) {
69: String headervalue = en2.nextElement();
70: writer.write("[header] " + headername + ": "
71: + headervalue + "\r\n");
72: }
73: }
74:
75: writer.close();
76: }
77: }
|