001    /*
002    * Licensed to the Apache Software Foundation (ASF) under one or more
003    * contributor license agreements.  See the NOTICE file distributed with
004    * this work for additional information regarding copyright ownership.
005    * The ASF licenses this file to You under the Apache License, Version 2.0
006    * (the "License"); you may not use this file except in compliance with
007    * the License.  You may obtain a copy of the License at
008    *
009    *     http://www.apache.org/licenses/LICENSE-2.0
010    *
011    * Unless required by applicable law or agreed to in writing, software
012    * distributed under the License is distributed on an "AS IS" BASIS,
013    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014    * See the License for the specific language governing permissions and
015    * limitations under the License.
016    */
017    /* $Id: RequestInfoExample.java 514091 2007-03-03 06:26:39Z jdillon $
018     *
019     */
020    
021    import java.io.*;
022    import java.util.*;
023    import javax.servlet.*;
024    import javax.servlet.http.*;
025    
026    import util.HTMLFilter;
027    
028    /**
029     * Example servlet showing request information.
030     *
031     * @author James Duncan Davidson <duncan@eng.sun.com>
032     */
033    
034    public class RequestInfoExample extends HttpServlet {
035    
036    
037        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
038    
039        public void doGet(HttpServletRequest request,
040                          HttpServletResponse response)
041            throws IOException, ServletException
042        {
043            response.setContentType("text/html");
044    
045            PrintWriter out = response.getWriter();
046            out.println("<html>");
047            out.println("<body>");
048            out.println("<head>");
049    
050            String title = rb.getString("requestinfo.title");
051            out.println("<title>" + title + "</title>");
052            out.println("</head>");
053            out.println("<body bgcolor=\"white\">");
054    
055            // img stuff not req'd for source code html showing
056            // all links relative!
057    
058            // XXX
059            // making these absolute till we work out the
060            // addition of a PathInfo issue
061            
062            out.println("<a href=\"../reqinfo.html\">");
063            out.println("<img src=\"../images/code.gif\" height=24 " +
064                        "width=24 align=right border=0 alt=\"view code\"></a>");
065            out.println("<a href=\"../index.html\">");
066            out.println("<img src=\"../images/return.gif\" height=24 " +
067                        "width=24 align=right border=0 alt=\"return\"></a>");
068    
069            out.println("<h3>" + title + "</h3>");
070            out.println("<table border=0><tr><td>");
071            out.println(rb.getString("requestinfo.label.method"));
072            out.println("</td><td>");
073            out.println(request.getMethod());
074            out.println("</td></tr><tr><td>");
075            out.println(rb.getString("requestinfo.label.requesturi"));
076            out.println("</td><td>");        
077            out.println(HTMLFilter.filter(request.getRequestURI()));
078            out.println("</td></tr><tr><td>");        
079            out.println(rb.getString("requestinfo.label.protocol"));
080            out.println("</td><td>");        
081            out.println(request.getProtocol());
082            out.println("</td></tr><tr><td>");
083            out.println(rb.getString("requestinfo.label.pathinfo"));
084            out.println("</td><td>");        
085            out.println(HTMLFilter.filter(request.getPathInfo()));
086            out.println("</td></tr><tr><td>");
087            out.println(rb.getString("requestinfo.label.remoteaddr"));
088    
089            String cipherSuite=
090                (String)request.getAttribute("javax.servlet.request.cipher_suite");
091            out.println("</td><td>");                
092            out.println(request.getRemoteAddr());
093            out.println("</table>");
094    
095            if(cipherSuite!=null){
096                out.println("</td></tr><tr><td>");  
097                out.println("SSLCipherSuite:");
098                out.println("</td>");
099                out.println("<td>");      
100                out.println(request.getAttribute("javax.servlet.request.cipher_suite"));
101                out.println("</td>");     
102            }
103            
104        }
105    
106        public void doPost(HttpServletRequest request,
107                          HttpServletResponse response)
108            throws IOException, ServletException
109        {
110            doGet(request, response);
111        }
112    
113    }
114