public class GrailsExceptionResolver extends SimpleMappingExceptionResolver implements GrailsApplicationAware, ServletContextAware
Wraps any runtime exceptions with a GrailsWrappedException instance.
| Modifiers | Name | Description |
|---|---|---|
static java.lang.String |
EXCEPTION_ATTRIBUTE |
|
protected static java.lang.String |
LINE_SEPARATOR |
|
protected static org.slf4j.Logger |
LOG |
|
protected AuditorAwareLookup |
auditorAwareLookup |
|
protected GrailsApplication |
grailsApplication |
|
protected ServletContext |
servletContext |
|
protected StackTraceFilterer |
stackFilterer |
| Fields inherited from class | Fields |
|---|---|
class SimpleMappingExceptionResolver |
DEFAULT_EXCEPTION_ATTRIBUTE, HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected void |
appendRequestContext(java.lang.StringBuilder sb, HttpServletRequest request)Appends optional per-request context (remote address, current auditor) to the log headline as a single parenthesised clause — e.g. |
|
protected void |
applyLogFullStackTraceOnFilter()Propagates grails.exceptionresolver.logFullStackTraceOnFilter to the
filterer instance when it is a DefaultStackTraceFilterer (or subclass
thereof). |
|
protected void |
createStackFilterer() |
|
protected java.lang.String |
determineUri(HttpServletRequest request) |
|
public static int |
extractLineNumber(CompilationFailedException e) |
|
protected void |
filterStackTrace(java.lang.Exception e) |
|
protected java.lang.Exception |
findWrappedException(java.lang.Exception e)The exception an action threw, out of what Groovy and Grails wrap it in. |
|
protected void |
forwardRequest(UrlMappingInfo info, HttpServletRequest request, HttpServletResponse response, ModelAndView mv, java.lang.String uri) |
|
public static java.lang.RuntimeException |
getFirstRuntimeException(java.lang.Throwable e) |
|
public java.lang.String |
getRequestLogMessage(java.lang.Throwable e, HttpServletRequest request) |
|
public java.lang.String |
getRequestLogMessage(HttpServletRequest request) |
|
protected java.lang.String |
getRequestLogMessage(java.lang.String exceptionName, HttpServletRequest request, java.lang.String message) |
|
public static java.lang.Throwable |
getRootCause(java.lang.Throwable ex)Obtains the root cause of the given exception |
|
public static java.lang.Runnable |
holdFailureLeftOnRequest(HttpServletRequest request)Holds the exception this resolver leaves on the request until the dispatch has returned, because only then does the request read as the filter that observes it will read it. |
|
protected void |
includeRequest(UrlMappingInfo info, HttpServletRequest request, HttpServletResponse response, ModelAndView mv, java.lang.String uri)Answers an exception inside an include with its error handler, included where the failing action would have written, as Spring MVC includes a view rather than forwarding to it there. |
|
protected boolean |
isErrorHandlerForwardInProgress(HttpServletRequest request)Whether a forward to a status-code controller mapping is already running for this request. |
|
protected boolean |
isExcludedRequestParameter(java.lang.String parameterName, java.util.List<java.lang.String> excludedParameterNames) |
|
protected void |
logFullStackTraceIfEnabled(java.lang.Exception e)When the grails.exceptionresolver.logFullStackTrace property is enabled,
emits the unfiltered stack trace to the dedicated StackTrace logger.
|
|
protected void |
logStackTrace(java.lang.Exception e, HttpServletRequest request) |
|
protected UrlMappingsHolder |
lookupUrlMappings() |
|
protected UrlMappingInfo |
matchStatusCode(java.lang.Exception ex, UrlMappingsHolder urlMappings) |
|
public ModelAndView |
resolveException(HttpServletRequest request, HttpServletResponse response, java.lang.Object handler, java.lang.Exception ex) |
|
protected StackTraceFilterer |
resolvePromotedStackTraceFilterer()Looks up the StackTraceFilterer that GrailsBootstrapRegistryInitializer promoted to the ApplicationContext during
bootstrap, so this resolver reuses that instance instead of instantiating a second copy from
config. |
|
protected java.lang.String |
resolveRemoteAddr(HttpServletRequest request)Resolves the client address to include in the exception log headline. |
|
protected void |
resolveView(HttpServletRequest request, UrlMappingInfo info, ModelAndView mv) |
|
protected ModelAndView |
resolveViewOrForward(java.lang.Exception ex, UrlMappingsHolder urlMappings, HttpServletRequest request, HttpServletResponse response, ModelAndView mv) |
|
public void |
setGrailsApplication(GrailsApplication grailsApplication) |
|
public void |
setServletContext(ServletContext servletContext) |
|
protected void |
setStatus(HttpServletRequest request, HttpServletResponse response, ModelAndView mv, java.lang.Exception e) |
|
protected boolean |
shouldLogAuditor() |
|
protected boolean |
shouldLogFullStackTrace() |
|
protected boolean |
shouldLogRemoteAddr() |
| Methods inherited from class | Name |
|---|---|
class SimpleMappingExceptionResolver |
addMappedHandlerClass, addStatusCode, equals, getClass, getOrder, getStatusCodesAsMap, hashCode, notify, notifyAll, resolveException, setDefaultErrorView, setDefaultStatusCode, setExceptionAttribute, setExceptionMappings, setExcludedExceptions, setMappedHandlerClasses, setMappedHandlerPredicate, setMappedHandlers, setOrder, setPreventResponseCaching, setStatusCodes, setWarnLogCategory, toString, wait, wait, wait |
Appends optional per-request context (remote address, current auditor) to the log
headline as a single parenthesised clause — e.g. (ip: 1.2.3.4, user: alice).
Emits nothing when no tokens apply, so the baseline headline format is unchanged.
Propagates grails.exceptionresolver.logFullStackTraceOnFilter to the
filterer instance when it is a DefaultStackTraceFilterer (or subclass
thereof). Custom StackTraceFilterer implementations that do not extend
the default are responsible for their own logging policy.
The exception an action threw, out of what Groovy and Grails wrap it in. Only those come off: what that exception wraps itself is its own cause, and an exception mapping that names it has to find it. A mapping that names a cause finds it through matchStatusCode(Exception, UrlMappingsHolder).
Obtains the root cause of the given exception
ex - The exceptionHolds the exception this resolver leaves on the request until the dispatch has returned, because only then does the request read as the filter that observes it will read it. Inside a forward it does not yet: Tomcat and Jetty restore a request when a forward returns, and Undertow leaves it reading as the forward. GrailsDispatcherServlet calls this when a dispatch enters it, and runs what this returns when the dispatch returns.
request - the request of the dispatchAnswers an exception inside an include with its error handler, included where the failing action would have written, as Spring MVC includes a view rather than forwarding to it there. A forward ends the response it is given, which inside an include belongs to the page that included the action, so Tomcat answered that page with nothing.
Whether a forward to a status-code controller mapping is already running for this request.
The forward re-enters the DispatcherServlet and resolves the same status-code mapping again,
since WebUtils.ERROR_STATUS_CODE_ATTRIBUTE is set. An error handler failing for a reason that
belongs to the request rather than the moment - an unparseable multipart body, a missing collaborator
- therefore fails again inside that forward and resolves back into this method, recursing until
StackOverflowError.
So the handler is not forwarded to from inside itself; the exception goes back to the
DispatcherServlet, which reports it once through the container. The flag is cleared when the
forward returns, leaving a later error on the same request free to use the handler again.
request - The request When the grails.exceptionresolver.logFullStackTrace property is enabled,
emits the unfiltered stack trace to the dedicated StackTrace logger.
Must be invoked before filterStackTrace(Exception) — once the
filterer calls setStackTrace(clean), the original frames are gone and
this method can only log the already-trimmed trace.
Looks up the StackTraceFilterer that
GrailsBootstrapRegistryInitializer promoted to the ApplicationContext during
bootstrap, so this resolver reuses that instance instead of instantiating a second copy from
config. Returns null when the bean cannot be obtained — no such bean (e.g. a
GrailsApplication wired up outside the normal Spring Boot bootstrap sequence), or a
bean of an incompatible type registered under the same name — in which case
createStackFilterer() falls back to its own construction. A filterer
misconfiguration must never fail the context, so no BeansException escapes here.
Note that an application registering its own bean definition named
GrailsBootstrapRegistryInitializer.STACK_TRACE_FILTERER_BEAN_NAME replaces the
promoted singleton: this resolver then uses the application's bean, while the static filterer
already installed in GrailsUtil at bootstrap remains the config-resolved one. Replace
the bean only when that split is intended; otherwise configure
grails.logging.stackTraceFiltererClass so both consume the same instance.
Resolves the client address to include in the exception log headline. The default
returns HttpServletRequest.getRemoteAddr — the container's view of the
TCP peer, which reflects forwarded-header handling only when the servlet container
is configured to trust a proxy chain (for example Spring Boot's
server.forward-headers-strategy). Subclasses can override this to apply a
different resolution strategy; the returned value (null or empty to omit) is
appended verbatim as ip: <value>.