From f32e1bcbe3b558cb93ff56b59ebe6c4ee9bc899e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 26 Oct 2018 11:07:29 +0200 Subject: [PATCH] Polishing --- .../AnnotationBeanWiringInfoResolver.java | 19 ++++++++--------- .../resource/ResourceUrlEncodingFilter.java | 21 ++++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java index 78a690b475f..5171f007e5f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2018 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. @@ -46,24 +46,23 @@ public class AnnotationBeanWiringInfoResolver implements BeanWiringInfoResolver } /** - * Build the BeanWiringInfo for the given Configurable annotation. + * Build the {@link BeanWiringInfo} for the given {@link Configurable} annotation. * @param beanInstance the bean instance * @param annotation the Configurable annotation found on the bean class * @return the resolved BeanWiringInfo */ protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) { if (!Autowire.NO.equals(annotation.autowire())) { + // Autowiring by name or by type return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck()); } + else if (!"".equals(annotation.value())) { + // Explicitly specified bean name for bean definition to take property values from + return new BeanWiringInfo(annotation.value(), false); + } else { - if (!"".equals(annotation.value())) { - // explicitly specified bean name - return new BeanWiringInfo(annotation.value(), false); - } - else { - // default bean name - return new BeanWiringInfo(getDefaultBeanName(beanInstance), true); - } + // Default bean name for bean definition to take property values from + return new BeanWiringInfo(getDefaultBeanName(beanInstance), true); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java index 85ee64a3f1c..e50a48e8120 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java @@ -36,8 +36,7 @@ import org.springframework.web.util.UrlPathHelper; /** * A filter that wraps the {@link HttpServletResponse} and overrides its * {@link HttpServletResponse#encodeURL(String) encodeURL} method in order to - * translate internal resource request URLs into public URL paths for external - * use. + * translate internal resource request URLs into public URL paths for external use. * * @author Jeremy Grelle * @author Rossen Stoyanchev @@ -52,7 +51,8 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) - throws IOException, ServletException { + throws ServletException, IOException { + if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) { throw new ServletException("ResourceUrlEncodingFilter only supports HTTP requests"); } @@ -63,6 +63,7 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { filterChain.doFilter(wrappedRequest, wrappedResponse); } + private static class ResourceUrlEncodingRequestWrapper extends HttpServletRequestWrapper { @Nullable @@ -78,11 +79,11 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { } @Override - public void setAttribute(String name, Object o) { - super.setAttribute(name, o); + public void setAttribute(String name, Object value) { + super.setAttribute(name, value); if (ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR.equals(name)) { - if(o instanceof ResourceUrlProvider) { - initLookupPath((ResourceUrlProvider) o); + if (value instanceof ResourceUrlProvider) { + initLookupPath((ResourceUrlProvider) value); } } @@ -109,11 +110,11 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { @Nullable public String resolveUrlPath(String url) { if (this.resourceUrlProvider == null) { - logger.trace("ResourceUrlProvider not available via " + - "request attribute ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR"); + logger.trace("ResourceUrlProvider not available via request attribute " + + "ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR"); return null; } - if (url.startsWith(this.prefixLookupPath)) { + if (this.indexLookupPath != null && url.startsWith(this.prefixLookupPath)) { int suffixIndex = getQueryParamsIndex(url); String suffix = url.substring(suffixIndex); String lookupPath = url.substring(this.indexLookupPath, suffixIndex);