From e522fec611a85e689cde9f53b0079d1a0d89ef45 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 7 May 2017 21:05:16 +0200 Subject: [PATCH] HandlerExecutionChain.toString() includes reliable interceptor number Issue: SPR-15525 (cherry picked from commit 92f18a4) --- .../web/portlet/HandlerExecutionChain.java | 24 ++++++++++++++----- .../web/servlet/HandlerExecutionChain.java | 21 ++++++++-------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/HandlerExecutionChain.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/HandlerExecutionChain.java index e09a0198684..615b83a1752 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/HandlerExecutionChain.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/HandlerExecutionChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 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. @@ -17,7 +17,6 @@ package org.springframework.web.portlet; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.springframework.util.CollectionUtils; @@ -72,7 +71,7 @@ public class HandlerExecutionChain { /** * Return the handler object to execute. - * @return the handler object + * @return the handler object (may be {@code null}) */ public Object getHandler() { return this.handler; @@ -84,7 +83,7 @@ public class HandlerExecutionChain { public void addInterceptors(HandlerInterceptor... interceptors) { if (!ObjectUtils.isEmpty(interceptors)) { - initInterceptorList().addAll(Arrays.asList(interceptors)); + CollectionUtils.mergeArrayIntoCollection(interceptors, initInterceptorList()); } } @@ -93,7 +92,7 @@ public class HandlerExecutionChain { this.interceptorList = new ArrayList(); if (this.interceptors != null) { // An interceptor array specified through the constructor - this.interceptorList.addAll(Arrays.asList(this.interceptors)); + CollectionUtils.mergeArrayIntoCollection(this.interceptors, this.interceptorList); } } this.interceptors = null; @@ -117,7 +116,20 @@ public class HandlerExecutionChain { */ @Override public String toString() { - return String.valueOf(this.handler); + Object handler = getHandler(); + if (handler == null) { + return "HandlerExecutionChain with no handler"; + } + StringBuilder sb = new StringBuilder(); + sb.append("HandlerExecutionChain with handler [").append(handler).append("]"); + HandlerInterceptor[] interceptors = getInterceptors(); + if (!ObjectUtils.isEmpty(interceptors)) { + sb.append(" and ").append(interceptors.length).append(" interceptor"); + if (interceptors.length > 1) { + sb.append("s"); + } + } + return sb.toString(); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java index 6fab48f2027..00184e44d5e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 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. @@ -17,7 +17,6 @@ package org.springframework.web.servlet; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -80,7 +79,7 @@ public class HandlerExecutionChain { /** * Return the handler object to execute. - * @return the handler object + * @return the handler object (may be {@code null}) */ public Object getHandler() { return this.handler; @@ -92,7 +91,7 @@ public class HandlerExecutionChain { public void addInterceptors(HandlerInterceptor... interceptors) { if (!ObjectUtils.isEmpty(interceptors)) { - initInterceptorList().addAll(Arrays.asList(interceptors)); + CollectionUtils.mergeArrayIntoCollection(interceptors, initInterceptorList()); } } @@ -101,7 +100,7 @@ public class HandlerExecutionChain { this.interceptorList = new ArrayList(); if (this.interceptors != null) { // An interceptor array specified through the constructor - this.interceptorList.addAll(Arrays.asList(this.interceptors)); + CollectionUtils.mergeArrayIntoCollection(this.interceptors, this.interceptorList); } } this.interceptors = null; @@ -202,14 +201,16 @@ public class HandlerExecutionChain { */ @Override public String toString() { - if (this.handler == null) { + Object handler = getHandler(); + if (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("HandlerExecutionChain with handler [").append(handler).append("]"); + HandlerInterceptor[] interceptors = getInterceptors(); + if (!ObjectUtils.isEmpty(interceptors)) { + sb.append(" and ").append(interceptors.length).append(" interceptor"); + if (interceptors.length > 1) { sb.append("s"); } }