Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
771 blopes 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
import java.io.IOException;
18
import java.io.PrintWriter;
19
import java.util.ResourceBundle;
20
 
21
import javax.servlet.ServletException;
22
import javax.servlet.http.HttpServlet;
23
import javax.servlet.http.HttpServletRequest;
24
import javax.servlet.http.HttpServletResponse;
25
 
26
import util.HTMLFilter;
27
 
28
/**
29
 * Example servlet showing request information.
30
 */
31
public class RequestInfoExample extends HttpServlet {
32
 
33
    private static final long serialVersionUID = 1L;
34
 
35
    @Override
36
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
37
        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings", request.getLocale());
38
 
39
        response.setContentType("text/html");
40
        response.setCharacterEncoding("UTF-8");
41
 
42
        PrintWriter out = response.getWriter();
43
        out.println("<!DOCTYPE html><html>");
44
        out.println("<head>");
45
        out.println("<meta charset=\"UTF-8\" />");
46
 
47
        String title = rb.getString("requestinfo.title");
48
        out.println("<title>" + title + "</title>");
49
        out.println("</head>");
50
        out.println("<body bgcolor=\"white\">");
51
 
52
        /*
53
         * Can't use relative paths since this servlet might have pathInfo. Allows for deployment to a different context
54
         * path but otherwise assumes that the web application structure is not changed.
55
         */
56
        String baseURI = request.getServletContext().getContextPath() + "/servlets";
57
 
58
        out.println("<a href=\"" + baseURI + "/reqinfo.html\">");
59
        out.println("<img src=\"" + baseURI + "/images/code.gif\" height=24 " +
60
                "width=24 align=right border=0 alt=\"view code\"></a>");
61
        out.println("<a href=\"" + baseURI + "/index.html\">");
62
        out.println("<img src=\"" + baseURI + "/images/return.gif\" height=24 " +
63
                "width=24 align=right border=0 alt=\"return\"></a>");
64
 
65
        out.println("<h3>" + title + "</h3>");
66
        out.println("<table border=0><tr><td>");
67
        out.println(rb.getString("requestinfo.label.method"));
68
        out.println("</td><td>");
69
        out.println(HTMLFilter.filter(request.getMethod()));
70
        out.println("</td></tr><tr><td>");
71
        out.println(rb.getString("requestinfo.label.requesturi"));
72
        out.println("</td><td>");
73
        out.println(HTMLFilter.filter(request.getRequestURI()));
74
        out.println("</td></tr><tr><td>");
75
        out.println(rb.getString("requestinfo.label.protocol"));
76
        out.println("</td><td>");
77
        out.println(HTMLFilter.filter(request.getProtocol()));
78
        out.println("</td></tr><tr><td>");
79
        out.println(rb.getString("requestinfo.label.pathinfo"));
80
        out.println("</td><td>");
81
        out.println(HTMLFilter.filter(request.getPathInfo()));
82
        out.println("</td></tr><tr><td>");
83
        out.println(rb.getString("requestinfo.label.remoteaddr"));
84
        out.println("</td><td>");
85
        out.println(HTMLFilter.filter(request.getRemoteAddr()));
86
        out.println("</td></tr>");
87
 
88
        String cipherSuite = (String) request.getAttribute("javax.servlet.request.cipher_suite");
89
        if (cipherSuite != null) {
90
            out.println("<tr><td>");
91
            out.println("SSLCipherSuite:");
92
            out.println("</td><td>");
93
            out.println(HTMLFilter.filter(cipherSuite));
94
            out.println("</td></tr>");
95
        }
96
 
97
        out.println("</table>");
98
    }
99
 
100
    @Override
101
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
102
        doGet(request, response);
103
    }
104
 
105
}
106