Browse Source

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

pull/1234/head
Juergen Hoeller 15 years ago
parent
commit
a79c015297
  1. 15
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java
  2. 16
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java

15
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -115,7 +115,18 @@ public class HandlerExecutionChain { @@ -115,7 +115,18 @@ public class HandlerExecutionChain {
*/
@Override
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();
}
}

16
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java

@ -218,7 +218,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping { @@ -218,7 +218,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
}
}
if (handler != null && logger.isDebugEnabled()) {
logger.debug("Mapping [" + lookupPath + "] to handler '" + handler + "'");
logger.debug("Mapping [" + lookupPath + "] to " + handler);
}
else if (handler == null && logger.isTraceEnabled()) {
logger.trace("No handler mapping found for [" + lookupPath + "]");
@ -388,32 +388,36 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping { @@ -388,32 +388,36 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
if (mappedHandler != null) {
if (mappedHandler != resolvedHandler) {
throw new IllegalStateException(
"Cannot map handler [" + handler + "] to URL path [" + urlPath +
"]: There is already handler [" + resolvedHandler + "] mapped.");
"Cannot map " + getHandlerDescription(handler) + " to URL path [" + urlPath +
"]: There is already " + getHandlerDescription(mappedHandler) + " mapped.");
}
}
else {
if (urlPath.equals("/")) {
if (logger.isInfoEnabled()) {
logger.info("Root mapping to handler [" + resolvedHandler + "]");
logger.info("Root mapping to " + getHandlerDescription(handler));
}
setRootHandler(resolvedHandler);
}
else if (urlPath.equals("/*")) {
if (logger.isInfoEnabled()) {
logger.info("Default mapping to handler [" + resolvedHandler + "]");
logger.info("Default mapping to " + getHandlerDescription(handler));
}
setDefaultHandler(resolvedHandler);
}
else {
this.handlerMap.put(urlPath, resolvedHandler);
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

Loading…
Cancel
Save