001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.wsrp.servlet;
023:
024: import org.jboss.logging.Logger;
025: import org.jboss.portal.common.io.IOTools;
026:
027: import javax.servlet.Filter;
028: import javax.servlet.FilterChain;
029: import javax.servlet.FilterConfig;
030: import javax.servlet.ServletException;
031: import javax.servlet.ServletRequest;
032: import javax.servlet.ServletResponse;
033: import javax.servlet.http.HttpServletRequest;
034: import javax.servlet.http.HttpServletResponse;
035: import java.io.IOException;
036: import java.io.Reader;
037: import java.io.StringWriter;
038: import java.util.Map;
039:
040: /**
041: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
042: * @version $Revision: 9360 $
043: */
044: public class RequestDumperFilter implements Filter {
045:
046: /** . */
047: private static Logger log = Logger
048: .getLogger(RequestDumperFilter.class);
049:
050: public void init(FilterConfig cfg) throws ServletException {
051: }
052:
053: public void doFilter(ServletRequest req, ServletResponse resp,
054: FilterChain chain) throws IOException, ServletException {
055: doFilter((HttpServletRequest) req, (HttpServletResponse) resp,
056: chain);
057: }
058:
059: public void doFilter(HttpServletRequest req,
060: HttpServletResponse resp, FilterChain chain)
061: throws IOException, ServletException {
062: boolean trace = log.isTraceEnabled();
063: if (trace) {
064: StringBuffer tmp = new StringBuffer();
065:
066: //
067: tmp.append("characterEncoding=").append(
068: req.getCharacterEncoding()).append('\n');
069: tmp.append("contentLength=").append(req.getContentLength())
070: .append('\n');
071: tmp.append("contentType=").append(req.getContentType())
072: .append('\n');
073: tmp.append("method=").append(req.getMethod()).append('\n');
074: tmp.append("pathInfo=").append(req.getPathInfo()).append(
075: '\n');
076: tmp.append("queryString=").append(req.getQueryString())
077: .append('\n');
078: tmp.append("requestURI=").append(req.getRequestURI())
079: .append('\n');
080: tmp.append("servletPath=").append(req.getServletPath())
081: .append('\n');
082:
083: //
084: for (Object o : req.getParameterMap().entrySet()) {
085: Map.Entry entry = (Map.Entry) o;
086: String name = (String) entry.getKey();
087: String[] values = (String[]) entry.getValue();
088: tmp.append("param.").append(name).append('=');
089: for (int j = 0; j < values.length; j++) {
090: String value = values[j];
091: tmp.append(j == 0 ? "" : ",").append(value);
092: }
093: }
094:
095: //
096: Reader reader = req.getReader();
097: if (reader != null) {
098: StringWriter buffer = new StringWriter();
099: IOTools.copy(reader, buffer);
100: tmp.append("body=").append(buffer.toString());
101: }
102:
103: log.trace(tmp);
104: }
105: chain.doFilter(req, resp);
106: }
107:
108: public void destroy() {
109: }
110: }
|