Skip to content

Commit a79c015

Browse files
committed
refined logging of handler objects in order to avoid early access to scoped proxies (SPR-7456)
1 parent 01b65cd commit a79c015

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -115,7 +115,18 @@ public HandlerInterceptor[] getInterceptors() {
115115
*/
116116
@Override
117117
public String toString() {
118-
return String.valueOf(this.handler);
118+
if (this.handler == null) {
119+
return "HandlerExecutionChain with no handler";
120+
}
121+
StringBuilder sb = new StringBuilder();
122+
sb.append("HandlerExecutionChain with handler [").append(this.handler).append("]");
123+
if (!CollectionUtils.isEmpty(this.interceptorList)) {
124+
sb.append(" and ").append(this.interceptorList.size()).append(" interceptor");
125+
if (this.interceptorList.size() > 1) {
126+
sb.append("s");
127+
}
128+
}
129+
return sb.toString();
119130
}
120131

121132
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ protected Object getHandlerInternal(HttpServletRequest request) throws Exception
218218
}
219219
}
220220
if (handler != null && logger.isDebugEnabled()) {
221-
logger.debug("Mapping [" + lookupPath + "] to handler '" + handler + "'");
221+
logger.debug("Mapping [" + lookupPath + "] to " + handler);
222222
}
223223
else if (handler == null && logger.isTraceEnabled()) {
224224
logger.trace("No handler mapping found for [" + lookupPath + "]");
@@ -388,32 +388,36 @@ protected void registerHandler(String urlPath, Object handler) throws BeansExcep
388388
if (mappedHandler != null) {
389389
if (mappedHandler != resolvedHandler) {
390390
throw new IllegalStateException(
391-
"Cannot map handler [" + handler + "] to URL path [" + urlPath +
392-
"]: There is already handler [" + resolvedHandler + "] mapped.");
391+
"Cannot map " + getHandlerDescription(handler) + " to URL path [" + urlPath +
392+
"]: There is already " + getHandlerDescription(mappedHandler) + " mapped.");
393393
}
394394
}
395395
else {
396396
if (urlPath.equals("/")) {
397397
if (logger.isInfoEnabled()) {
398-
logger.info("Root mapping to handler [" + resolvedHandler + "]");
398+
logger.info("Root mapping to " + getHandlerDescription(handler));
399399
}
400400
setRootHandler(resolvedHandler);
401401
}
402402
else if (urlPath.equals("/*")) {
403403
if (logger.isInfoEnabled()) {
404-
logger.info("Default mapping to handler [" + resolvedHandler + "]");
404+
logger.info("Default mapping to " + getHandlerDescription(handler));
405405
}
406406
setDefaultHandler(resolvedHandler);
407407
}
408408
else {
409409
this.handlerMap.put(urlPath, resolvedHandler);
410410
if (logger.isInfoEnabled()) {
411-
logger.info("Mapped URL path [" + urlPath + "] onto handler [" + resolvedHandler + "]");
411+
logger.info("Mapped URL path [" + urlPath + "] onto " + getHandlerDescription(handler));
412412
}
413413
}
414414
}
415415
}
416416

417+
private String getHandlerDescription(Object handler) {
418+
return "handler " + (handler instanceof String ? "'" + handler + "'" : "of type [" + handler.getClass() + "]");
419+
}
420+
417421

418422
/**
419423
* Return the registered handlers as an unmodifiable Map, with the registered path

0 commit comments

Comments
 (0)