refined logging of handler objects in order to avoid early access to scoped proxies (SPR-7456)

This commit is contained in:
Juergen Hoeller 2010-08-12 22:14:20 +00:00
parent 01b65cd201
commit a79c015297
2 changed files with 23 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -115,7 +115,18 @@ public class HandlerExecutionChain {
*/ */
@Override @Override
public String toString() { public String toString() {
return String.valueOf(this.handler); if (this.handler == null) {
return "HandlerExecutionChain with no handler";
}
StringBuilder sb = new StringBuilder();
sb.append("HandlerExecutionChain with handler [").append(this.handler).append("]");
if (!CollectionUtils.isEmpty(this.interceptorList)) {
sb.append(" and ").append(this.interceptorList.size()).append(" interceptor");
if (this.interceptorList.size() > 1) {
sb.append("s");
}
}
return sb.toString();
} }
} }

View File

@ -218,7 +218,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
} }
} }
if (handler != null && logger.isDebugEnabled()) { if (handler != null && logger.isDebugEnabled()) {
logger.debug("Mapping [" + lookupPath + "] to handler '" + handler + "'"); logger.debug("Mapping [" + lookupPath + "] to " + handler);
} }
else if (handler == null && logger.isTraceEnabled()) { else if (handler == null && logger.isTraceEnabled()) {
logger.trace("No handler mapping found for [" + lookupPath + "]"); logger.trace("No handler mapping found for [" + lookupPath + "]");
@ -388,32 +388,36 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
if (mappedHandler != null) { if (mappedHandler != null) {
if (mappedHandler != resolvedHandler) { if (mappedHandler != resolvedHandler) {
throw new IllegalStateException( throw new IllegalStateException(
"Cannot map handler [" + handler + "] to URL path [" + urlPath + "Cannot map " + getHandlerDescription(handler) + " to URL path [" + urlPath +
"]: There is already handler [" + resolvedHandler + "] mapped."); "]: There is already " + getHandlerDescription(mappedHandler) + " mapped.");
} }
} }
else { else {
if (urlPath.equals("/")) { if (urlPath.equals("/")) {
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info("Root mapping to handler [" + resolvedHandler + "]"); logger.info("Root mapping to " + getHandlerDescription(handler));
} }
setRootHandler(resolvedHandler); setRootHandler(resolvedHandler);
} }
else if (urlPath.equals("/*")) { else if (urlPath.equals("/*")) {
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info("Default mapping to handler [" + resolvedHandler + "]"); logger.info("Default mapping to " + getHandlerDescription(handler));
} }
setDefaultHandler(resolvedHandler); setDefaultHandler(resolvedHandler);
} }
else { else {
this.handlerMap.put(urlPath, resolvedHandler); this.handlerMap.put(urlPath, resolvedHandler);
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info("Mapped URL path [" + urlPath + "] onto handler [" + resolvedHandler + "]"); logger.info("Mapped URL path [" + urlPath + "] onto " + getHandlerDescription(handler));
} }
} }
} }
} }
private String getHandlerDescription(Object handler) {
return "handler " + (handler instanceof String ? "'" + handler + "'" : "of type [" + handler.getClass() + "]");
}
/** /**
* Return the registered handlers as an unmodifiable Map, with the registered path * Return the registered handlers as an unmodifiable Map, with the registered path