1 17 18 19 package org.apache.catalina.valves; 20 21 22 import java.io.IOException ; 23 import java.util.Enumeration ; 24 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.Cookie ; 27 28 import org.apache.catalina.connector.Request; 29 import org.apache.catalina.connector.Response; 30 import org.apache.catalina.util.StringManager; 31 import org.apache.commons.logging.Log; 32 33 34 46 47 public class RequestDumperValve 48 extends ValveBase { 49 50 51 53 54 57 private static final String info = 58 "org.apache.catalina.valves.RequestDumperValve/1.0"; 59 60 61 64 protected static StringManager sm = 65 StringManager.getManager(Constants.Package); 66 67 68 70 71 74 public String getInfo() { 75 76 return (info); 77 78 } 79 80 81 83 84 94 public void invoke(Request request, Response response) 95 throws IOException , ServletException { 96 97 Log log = container.getLogger(); 98 99 log.info("REQUEST URI =" + request.getRequestURI()); 101 log.info(" authType=" + request.getAuthType()); 102 log.info(" characterEncoding=" + request.getCharacterEncoding()); 103 log.info(" contentLength=" + request.getContentLength()); 104 log.info(" contentType=" + request.getContentType()); 105 log.info(" contextPath=" + request.getContextPath()); 106 Cookie cookies[] = request.getCookies(); 107 if (cookies != null) { 108 for (int i = 0; i < cookies.length; i++) 109 log.info(" cookie=" + cookies[i].getName() + "=" + 110 cookies[i].getValue()); 111 } 112 Enumeration hnames = request.getHeaderNames(); 113 while (hnames.hasMoreElements()) { 114 String hname = (String ) hnames.nextElement(); 115 Enumeration hvalues = request.getHeaders(hname); 116 while (hvalues.hasMoreElements()) { 117 String hvalue = (String ) hvalues.nextElement(); 118 log.info(" header=" + hname + "=" + hvalue); 119 } 120 } 121 log.info(" locale=" + request.getLocale()); 122 log.info(" method=" + request.getMethod()); 123 Enumeration pnames = request.getParameterNames(); 124 while (pnames.hasMoreElements()) { 125 String pname = (String ) pnames.nextElement(); 126 String pvalues[] = request.getParameterValues(pname); 127 StringBuffer result = new StringBuffer (pname); 128 result.append('='); 129 for (int i = 0; i < pvalues.length; i++) { 130 if (i > 0) 131 result.append(", "); 132 result.append(pvalues[i]); 133 } 134 log.info(" parameter=" + result.toString()); 135 } 136 log.info(" pathInfo=" + request.getPathInfo()); 137 log.info(" protocol=" + request.getProtocol()); 138 log.info(" queryString=" + request.getQueryString()); 139 log.info(" remoteAddr=" + request.getRemoteAddr()); 140 log.info(" remoteHost=" + request.getRemoteHost()); 141 log.info(" remoteUser=" + request.getRemoteUser()); 142 log.info("requestedSessionId=" + request.getRequestedSessionId()); 143 log.info(" scheme=" + request.getScheme()); 144 log.info(" serverName=" + request.getServerName()); 145 log.info(" serverPort=" + request.getServerPort()); 146 log.info(" servletPath=" + request.getServletPath()); 147 log.info(" isSecure=" + request.isSecure()); 148 log.info("---------------------------------------------------------------"); 149 150 getNext().invoke(request, response); 152 153 log.info("---------------------------------------------------------------"); 155 log.info(" authType=" + request.getAuthType()); 156 log.info(" contentLength=" + response.getContentLength()); 157 log.info(" contentType=" + response.getContentType()); 158 Cookie rcookies[] = response.getCookies(); 159 for (int i = 0; i < rcookies.length; i++) { 160 log.info(" cookie=" + rcookies[i].getName() + "=" + 161 rcookies[i].getValue() + "; domain=" + 162 rcookies[i].getDomain() + "; path=" + rcookies[i].getPath()); 163 } 164 String rhnames[] = response.getHeaderNames(); 165 for (int i = 0; i < rhnames.length; i++) { 166 String rhvalues[] = response.getHeaderValues(rhnames[i]); 167 for (int j = 0; j < rhvalues.length; j++) 168 log.info(" header=" + rhnames[i] + "=" + rhvalues[j]); 169 } 170 log.info(" message=" + response.getMessage()); 171 log.info(" remoteUser=" + request.getRemoteUser()); 172 log.info(" status=" + response.getStatus()); 173 log.info("==============================================================="); 174 175 } 176 177 178 181 public String toString() { 182 183 StringBuffer sb = new StringBuffer ("RequestDumperValve["); 184 if (container != null) 185 sb.append(container.getName()); 186 sb.append("]"); 187 return (sb.toString()); 188 189 } 190 191 192 } 193 | Popular Tags |