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 */ 017package org.apache.wicket.settings; 018 019import org.apache.wicket.util.lang.Args; 020import org.apache.wicket.util.lang.EnumeratedType; 021 022/** 023 * 024 * Settings class for configuring exception handling related settings. 025 * <p> 026 * <i>unexpectedExceptionDisplay </i> (defaults to SHOW_EXCEPTION_PAGE) - Determines how exceptions 027 * are displayed to the developer or user 028 * <p> 029 * <i>throwExceptionOnMissingResource </i> (defaults to true) - Set to true to throw a runtime 030 * exception if a required string resource is not found. Set to false to return the requested 031 * resource key surrounded by pairs of question mark characters (e.g. "??missingKey??") 032 * 033 * @author Jonathan Locke 034 * @author Chris Turner 035 * @author Eelco Hillenius 036 * @author Juergen Donnerstag 037 * @author Johan Compagner 038 * @author Igor Vaynberg (ivaynberg) 039 * @author Martijn Dashorst 040 * @author James Carman 041 */ 042public class ExceptionSettings 043{ 044 /** 045 * Enumerated type for different ways of displaying unexpected exceptions. 046 */ 047 public static final class UnexpectedExceptionDisplay extends EnumeratedType 048 { 049 private static final long serialVersionUID = 1L; 050 051 UnexpectedExceptionDisplay(final String name) 052 { 053 super(name); 054 } 055 } 056 057 /** 058 * Indicates that an exception page appropriate to development should be shown when an 059 * unexpected exception is thrown. 060 */ 061 public static final UnexpectedExceptionDisplay SHOW_EXCEPTION_PAGE = new UnexpectedExceptionDisplay( 062 "SHOW_EXCEPTION_PAGE"); 063 /** 064 * Indicates a generic internal error page should be shown when an unexpected exception is 065 * thrown. 066 */ 067 public static final UnexpectedExceptionDisplay SHOW_INTERNAL_ERROR_PAGE = new UnexpectedExceptionDisplay( 068 "SHOW_INTERNAL_ERROR_PAGE"); 069 070 /** 071 * Indicates that no exception page should be shown when an unexpected exception is thrown. 072 */ 073 public static final UnexpectedExceptionDisplay SHOW_NO_EXCEPTION_PAGE = new UnexpectedExceptionDisplay( 074 "SHOW_NO_EXCEPTION_PAGE"); 075 076 /** 077 * How to handle errors while processing an Ajax request 078 * 079 * @author igor 080 */ 081 public enum AjaxErrorStrategy { 082 /** redirect to error page, just like a normal requset */ 083 REDIRECT_TO_ERROR_PAGE, 084 /** invoke client side failure handler */ 085 INVOKE_FAILURE_HANDLER 086 } 087 088 /** 089 * Which threads' stacktrace to dump when a page lock timeout occurs 090 * 091 * @author papegaaij 092 */ 093 public enum ThreadDumpStrategy { 094 /** Do not dump any stacktraces */ 095 NO_THREADS, 096 /** Dump the stacktrace of the thread holding the lock */ 097 THREAD_HOLDING_LOCK, 098 /** Dump stacktraces of all threads of the application */ 099 ALL_THREADS 100 } 101 102 /** 103 * A strategy defining what to do when a component that will not render its 104 * markup tag (because of {@link org.apache.wicket.Component#setRenderBodyOnly(boolean) setRenderBodyOnly(true)} 105 * or used with <wicket:xyz>) is also asked to output a 106 * markup {@link org.apache.wicket.Component#setOutputMarkupId(boolean) id} or 107 * {@link org.apache.wicket.Component#setOutputMarkupPlaceholderTag(boolean) placeholder tag} 108 */ 109 public enum NotRenderableErrorStrategy { 110 /** 111 * Log a message with level {@link org.slf4j.Logger#warn(String) WARNING} 112 */ 113 LOG_WARNING, 114 /** 115 * Throw a runtime exception 116 */ 117 THROW_EXCEPTION 118 } 119 120 /** Type of handling for unexpected exceptions */ 121 private UnexpectedExceptionDisplay unexpectedExceptionDisplay = SHOW_EXCEPTION_PAGE; 122 123 private AjaxErrorStrategy errorHandlingStrategyDuringAjaxRequests = AjaxErrorStrategy.REDIRECT_TO_ERROR_PAGE; 124 125 /** 126 * Strategy to use for dumping stack traces of live threads in the JVM. 127 * <p> 128 * By default will dump the stacktrace of the thread that holds the lock on the page. 129 * </p> 130 */ 131 private ThreadDumpStrategy threadDumpStrategy = ThreadDumpStrategy.THREAD_HOLDING_LOCK; 132 133 private NotRenderableErrorStrategy notRenderableErrorStrategy = NotRenderableErrorStrategy.LOG_WARNING; 134 135 /** 136 * @return Returns the unexpectedExceptionDisplay. 137 */ 138 public UnexpectedExceptionDisplay getUnexpectedExceptionDisplay() 139 { 140 return unexpectedExceptionDisplay; 141 } 142 143 /** 144 * The exception display type determines how the framework displays exceptions to you as a 145 * developer or user. 146 * <p> 147 * The default value for exception display type is SHOW_EXCEPTION_PAGE. When this value is set 148 * and an unhandled runtime exception is thrown by a page, a redirect to a helpful exception 149 * display page will occur. 150 * <p> 151 * This is a developer feature, however, and you may want to instead show an internal error page 152 * without developer details that allows a user to start over at the application's home page. 153 * This can be accomplished by setting the exception display type to SHOW_INTERNAL_ERROR_PAGE. 154 * <p> 155 * Finally, if you are having trouble with the exception display pages themselves, you can 156 * disable exception displaying entirely with the value SHOW_NO_EXCEPTION_PAGE. This will cause 157 * the framework to re-throw any unhandled runtime exceptions after wrapping them in a 158 * ServletException wrapper. 159 * 160 * @param unexpectedExceptionDisplay 161 * The unexpectedExceptionDisplay to set. 162 * @return {@code this} object for chaining 163 */ 164 public ExceptionSettings setUnexpectedExceptionDisplay(UnexpectedExceptionDisplay unexpectedExceptionDisplay) 165 { 166 this.unexpectedExceptionDisplay = unexpectedExceptionDisplay; 167 return this; 168 } 169 170 /** 171 * @return strategy used to handle errors during Ajax request processing 172 */ 173 public AjaxErrorStrategy getAjaxErrorHandlingStrategy() 174 { 175 return errorHandlingStrategyDuringAjaxRequests; 176 } 177 178 /** 179 * Sets strategy used to handle errors during Ajax request processing 180 * 181 * @param errorHandlingStrategyDuringAjaxRequests 182 * @return {@code this} object for chaining 183 */ 184 public ExceptionSettings setAjaxErrorHandlingStrategy( 185 AjaxErrorStrategy errorHandlingStrategyDuringAjaxRequests) 186 { 187 this.errorHandlingStrategyDuringAjaxRequests = errorHandlingStrategyDuringAjaxRequests; 188 return this; 189 } 190 191 /** 192 * Sets the strategy to use for dumping stack traces of live threads in the JVM. 193 * 194 * @param strategy 195 * @return {@code this} object for chaining 196 */ 197 public ExceptionSettings setThreadDumpStrategy(ThreadDumpStrategy strategy) 198 { 199 threadDumpStrategy = Args.notNull(strategy, "strategy"); 200 return this; 201 } 202 203 /** 204 * @return strategy to use for dumping stack traces of live threads in the JVM. 205 */ 206 public ThreadDumpStrategy getThreadDumpStrategy() 207 { 208 return threadDumpStrategy; 209 } 210 211 public NotRenderableErrorStrategy getNotRenderableErrorStrategy() { 212 return notRenderableErrorStrategy; 213 } 214 215 public void setNotRenderableErrorStrategy(final NotRenderableErrorStrategy notRenderableErrorStrategy) { 216 this.notRenderableErrorStrategy = notRenderableErrorStrategy; 217 } 218}