001/* 002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * arussel 018 */ 019package org.nuxeo.ecm.platform.web.common.exceptionhandling.service; 020 021import java.util.ArrayList; 022import java.util.Enumeration; 023import java.util.List; 024 025import javax.servlet.http.HttpServletRequest; 026 027import org.apache.commons.logging.Log; 028import org.apache.commons.logging.LogFactory; 029 030/** 031 * @author arussel 032 */ 033public class DefaultRequestDumper implements RequestDumper { 034 035 private static final Log log = LogFactory.getLog(DefaultRequestDumper.class); 036 037 protected List<String> attributes = new ArrayList<String>(); 038 039 public String getDump(HttpServletRequest request) { 040 StringBuilder builder = new StringBuilder(); 041 builder.append("\nRequest Attributes:\n\n"); 042 Enumeration<String> e = request.getAttributeNames(); 043 while (e.hasMoreElements()) { 044 String name = e.nextElement(); 045 if (attributes.contains(name)) { 046 continue; 047 } 048 builder.append(name); 049 builder.append(" : "); 050 try { 051 Object obj = request.getAttribute(name); 052 builder.append(obj.toString()); 053 } catch (RuntimeException exc) { 054 // avoid errors when printing the error dump 055 log.error("ERROR TRYING TO GET THIS REQUEST ATTRIBUTE VALUE: " + name); 056 builder.append("ERROR TRYING TO GET THIS REQUEST ATTRIBUTE VALUE"); 057 } 058 builder.append("\n"); 059 } 060 return builder.toString(); 061 } 062 063 public void setNotListedAttributes(List<String> attributes) { 064 this.attributes = attributes; 065 } 066 067}