View Javadoc

1   /***
2    *  The contents of this file are subject to the Mozilla Public
3    *  License Version 1.1 (the "License"); you may not use this file
4    *  except in compliance with the License. You may obtain a copy of
5    *  the License at http://www.mozilla.org/MPL/
6    *
7    *  Software distributed under the License is distributed on an "AS
8    *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9    *  implied. See the License for the specific language governing
10   *  rights and limitations under the License.
11   *
12   *  The Original Code is pow2toolkit library.
13   *
14   *  The Initial Owner of the Original Code is
15   *  Power Of Two S.R.L. (www.pow2.com)
16   *
17   *  Portions created by Power Of Two S.R.L. are
18   *  Copyright (C) Power Of Two S.R.L.
19   *  All Rights Reserved.
20   *
21   * Contributor(s):
22   */
23  
24  package com.pow2.servlets;
25  
26  import java.io.*;
27  import javax.servlet.*;
28  import javax.servlet.http.*;
29  
30  import org.apache.log4j.Category;
31  
32  import com.pow2.util.ServletUtil;
33  
34  
35  /***
36   * Simple HTTP Dump servlet.
37   * <br>
38   * Dumps the incoming HTTP request object and logs its content.
39   */
40  public class HTTPDumpServlet extends HttpServlet
41  {
42    /***  Log4J category */
43    private Category cat = Category.getInstance(this.getClass());
44  
45  
46    /***
47     *  Default constructor
48     */
49    public HTTPDumpServlet()
50    {
51      super();
52    }
53  
54  
55    /***
56     * Process GET and POST methods.
57     * <br>
58     * Redirects to <code>doPost()</code>.
59     *
60     * @param request the request object 
61     * @param response the response object 
62     * @throws ServletException if any error occurs
63     * @throws IOException if any I/O error occurs
64     */
65    public void doGet(HttpServletRequest  request,
66                      HttpServletResponse response)
67               throws ServletException, IOException
68    {
69    	doPost(request, response);
70    }
71    
72    
73    /***
74     * Dump the incoming HTTP request.
75     *
76     * @param request the request object 
77     * @param response the response object 
78     * @throws ServletException if any error occurs
79     * @throws IOException if any I/O error occurs
80     */
81    public void doPost(HttpServletRequest  request,
82  					 HttpServletResponse response)
83  			 throws ServletException, IOException
84    {
85  	response.setContentType("text/html");
86  	String buf = ServletUtil.dumpRequest(request);
87  	cat.info("HTTP dump:\n" + buf + "\n");
88    }
89  }