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 664175 2008-06-06 22:43:44Z djencks $ 018 * 019 */ 020 021 import java.io.IOException; 022 import java.io.PrintWriter; 023 import java.util.ResourceBundle; 024 025 import javax.servlet.ServletException; 026 import javax.servlet.http.HttpServlet; 027 import javax.servlet.http.HttpServletRequest; 028 import javax.servlet.http.HttpServletResponse; 029 030 import util.HTMLFilter; 031 032 /** 033 * Example servlet showing request information. 034 * 035 * @author James Duncan Davidson <duncan@eng.sun.com> 036 */ 037 038 public class RequestInfoExample extends HttpServlet { 039 040 041 ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"); 042 043 public void doGet(HttpServletRequest request, 044 HttpServletResponse response) 045 throws IOException, ServletException { 046 response.setContentType("text/html"); 047 048 PrintWriter out = response.getWriter(); 049 out.println("<html>"); 050 out.println("<body>"); 051 out.println("<head>"); 052 053 String title = rb.getString("requestinfo.title"); 054 out.println("<title>" + title + "</title>"); 055 out.println("</head>"); 056 out.println("<body bgcolor=\"white\">"); 057 058 // img stuff not req'd for source code html showing 059 // all links relative! 060 061 // XXX 062 // making these absolute till we work out the 063 // addition of a PathInfo issue 064 065 out.println("<a href=\"../reqinfo.html\">"); 066 out.println("<img src=\"../images/code.gif\" height=24 " + 067 "width=24 align=right border=0 alt=\"view code\"></a>"); 068 out.println("<a href=\"../index.html\">"); 069 out.println("<img src=\"../images/return.gif\" height=24 " + 070 "width=24 align=right border=0 alt=\"return\"></a>"); 071 072 out.println("<h3>" + title + "</h3>"); 073 out.println("<table border=0><tr><td>"); 074 out.println(rb.getString("requestinfo.label.method")); 075 out.println("</td><td>"); 076 out.println(request.getMethod()); 077 out.println("</td></tr><tr><td>"); 078 out.println(rb.getString("requestinfo.label.requesturi")); 079 out.println("</td><td>"); 080 out.println(HTMLFilter.filter(request.getRequestURI())); 081 out.println("</td></tr><tr><td>"); 082 out.println(rb.getString("requestinfo.label.protocol")); 083 out.println("</td><td>"); 084 out.println(request.getProtocol()); 085 out.println("</td></tr><tr><td>"); 086 out.println(rb.getString("requestinfo.label.pathinfo")); 087 out.println("</td><td>"); 088 out.println(HTMLFilter.filter(request.getPathInfo())); 089 out.println("</td></tr><tr><td>"); 090 out.println(rb.getString("requestinfo.label.remoteaddr")); 091 092 String cipherSuite = 093 (String) request.getAttribute("javax.servlet.request.cipher_suite"); 094 out.println("</td><td>"); 095 out.println(request.getRemoteAddr()); 096 out.println("</table>"); 097 098 if (cipherSuite != null) { 099 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