001/* 002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * arussel 016 */ 017package org.nuxeo.ecm.platform.web.common.exceptionhandling.service; 018 019import java.util.ArrayList; 020import java.util.Enumeration; 021import java.util.List; 022 023import javax.servlet.http.HttpServletRequest; 024 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027 028/** 029 * @author arussel 030 */ 031public class DefaultRequestDumper implements RequestDumper { 032 033 private static final Log log = LogFactory.getLog(DefaultRequestDumper.class); 034 035 protected List<String> attributes = new ArrayList<String>(); 036 037 public String getDump(HttpServletRequest request) { 038 StringBuilder builder = new StringBuilder(); 039 builder.append("\nRequest Attributes:\n\n"); 040 Enumeration<String> e = request.getAttributeNames(); 041 while (e.hasMoreElements()) { 042 String name = e.nextElement(); 043 if (attributes.contains(name)) { 044 continue; 045 } 046 builder.append(name); 047 builder.append(" : "); 048 try { 049 Object obj = request.getAttribute(name); 050 builder.append(obj.toString()); 051 } catch (RuntimeException exc) { 052 // avoid errors when printing the error dump 053 log.error("ERROR TRYING TO GET THIS REQUEST ATTRIBUTE VALUE: " + name); 054 builder.append("ERROR TRYING TO GET THIS REQUEST ATTRIBUTE VALUE"); 055 } 056 builder.append("\n"); 057 } 058 return builder.toString(); 059 } 060 061 public void setNotListedAttributes(List<String> attributes) { 062 this.attributes = attributes; 063 } 064 065}