View Javadoc

1   /*
2   * Licensed to the Apache Software Foundation (ASF) under one or more
3   * contributor license agreements.  See the NOTICE file distributed with
4   * this work for additional information regarding copyright ownership.
5   * The ASF licenses this file to You under the Apache License, Version 2.0
6   * (the "License"); you may not use this file except in compliance with
7   * the License.  You may obtain a copy of the License at
8   *
9   *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17  /* $Id: RequestInfoExample.java 664175 2008-06-06 22:43:44Z djencks $
18   *
19   */
20  
21  import java.io.IOException;
22  import java.io.PrintWriter;
23  import java.util.ResourceBundle;
24  
25  import javax.servlet.ServletException;
26  import javax.servlet.http.HttpServlet;
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  import util.HTMLFilter;
31  
32  /**
33   * Example servlet showing request information.
34   *
35   * @author James Duncan Davidson <duncan@eng.sun.com>
36   */
37  
38  public class RequestInfoExample extends HttpServlet {
39  
40  
41      ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
42  
43      public void doGet(HttpServletRequest request,
44                        HttpServletResponse response)
45              throws IOException, ServletException {
46          response.setContentType("text/html");
47  
48          PrintWriter out = response.getWriter();
49          out.println("<html>");
50          out.println("<body>");
51          out.println("<head>");
52  
53          String title = rb.getString("requestinfo.title");
54          out.println("<title>" + title + "</title>");
55          out.println("</head>");
56          out.println("<body bgcolor=\"white\">");
57  
58          // img stuff not req'd for source code html showing
59          // all links relative!
60  
61          // XXX
62          // making these absolute till we work out the
63          // addition of a PathInfo issue
64  
65          out.println("<a href=\"../reqinfo.html\">");
66          out.println("<img src=\"../images/code.gif\" height=24 " +
67                  "width=24 align=right border=0 alt=\"view code\"></a>");
68          out.println("<a href=\"../index.html\">");
69          out.println("<img src=\"../images/return.gif\" height=24 " +
70                  "width=24 align=right border=0 alt=\"return\"></a>");
71  
72          out.println("<h3>" + title + "</h3>");
73          out.println("<table border=0><tr><td>");
74          out.println(rb.getString("requestinfo.label.method"));
75          out.println("</td><td>");
76          out.println(request.getMethod());
77          out.println("</td></tr><tr><td>");
78          out.println(rb.getString("requestinfo.label.requesturi"));
79          out.println("</td><td>");
80          out.println(HTMLFilter.filter(request.getRequestURI()));
81          out.println("</td></tr><tr><td>");
82          out.println(rb.getString("requestinfo.label.protocol"));
83          out.println("</td><td>");
84          out.println(request.getProtocol());
85          out.println("</td></tr><tr><td>");
86          out.println(rb.getString("requestinfo.label.pathinfo"));
87          out.println("</td><td>");
88          out.println(HTMLFilter.filter(request.getPathInfo()));
89          out.println("</td></tr><tr><td>");
90          out.println(rb.getString("requestinfo.label.remoteaddr"));
91  
92          String cipherSuite =
93                  (String) request.getAttribute("javax.servlet.request.cipher_suite");
94          out.println("</td><td>");
95          out.println(request.getRemoteAddr());
96          out.println("</table>");
97  
98          if (cipherSuite != null) {
99              out.println("</td></tr><tr><td>");
100             out.println("SSLCipherSuite:");
101             out.println("</td>");
102             out.println("<td>");
103             out.println(request.getAttribute("javax.servlet.request.cipher_suite"));
104             out.println("</td>");
105         }
106 
107     }
108 
109     public void doPost(HttpServletRequest request,
110                        HttpServletResponse response)
111             throws IOException, ServletException {
112         doGet(request, response);
113     }
114 
115 }
116