Browse Source

Polishing

pull/510/head
Juergen Hoeller 12 years ago
parent
commit
623b1fc0d5
  1. 9
      spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java
  2. 19
      spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java
  3. 102
      spring-web/src/main/java/org/springframework/web/util/UriUtils.java
  4. 7
      spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java
  5. 82
      spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java
  6. 4
      spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/TilesConfigurer.java
  7. 25
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterTests.java

9
spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@ -90,7 +90,7 @@ public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean<O @@ -90,7 +90,7 @@ public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean<O
pf.copyFrom(this);
pf.setTargetSource(this.scopedTargetSource);
Class beanType = beanFactory.getType(this.targetBeanName);
Class<?> beanType = beanFactory.getType(this.targetBeanName);
if (beanType == null) {
throw new IllegalStateException("Cannot create scoped proxy for bean '" + this.targetBeanName +
"': Target type could not be determined at the time of proxy creation.");
@ -122,10 +122,7 @@ public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean<O @@ -122,10 +122,7 @@ public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean<O
if (this.proxy != null) {
return this.proxy.getClass();
}
if (this.scopedTargetSource != null) {
return this.scopedTargetSource.getTargetClass();
}
return null;
return this.scopedTargetSource.getTargetClass();
}
public boolean isSingleton() {

19
spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -176,13 +176,14 @@ final class HierarchicalUriComponents extends UriComponents { @@ -176,13 +176,14 @@ final class HierarchicalUriComponents extends UriComponents {
*/
@Override
public HierarchicalUriComponents encode(String encoding) throws UnsupportedEncodingException {
Assert.hasLength(encoding, "'encoding' must not be empty");
Assert.hasLength(encoding, "Encoding must not be empty");
if (this.encoded) {
return this;
}
String encodedScheme = encodeUriComponent(this.getScheme(), encoding, Type.SCHEME);
String encodedScheme = encodeUriComponent(getScheme(), encoding, Type.SCHEME);
String encodedUserInfo = encodeUriComponent(this.userInfo, encoding, Type.USER_INFO);
String encodedHost = encodeUriComponent(this.host, encoding, Type.HOST);
PathComponent encodedPath = this.path.encode(encoding);
MultiValueMap<String, String> encodedQueryParams =
new LinkedMultiValueMap<String, String>(this.queryParams.size());
@ -213,14 +214,14 @@ final class HierarchicalUriComponents extends UriComponents { @@ -213,14 +214,14 @@ final class HierarchicalUriComponents extends UriComponents {
if (source == null) {
return null;
}
Assert.hasLength(encoding, "'encoding' must not be empty");
Assert.hasLength(encoding, "Encoding must not be empty");
byte[] bytes = encodeBytes(source.getBytes(encoding), type);
return new String(bytes, "US-ASCII");
}
private static byte[] encodeBytes(byte[] source, Type type) {
Assert.notNull(source, "'source' must not be null");
Assert.notNull(type, "'type' must not be null");
Assert.notNull(source, "Source must not be null");
Assert.notNull(type, "Type must not be null");
ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length);
for (byte b : source) {
if (b < 0) {
@ -253,8 +254,8 @@ final class HierarchicalUriComponents extends UriComponents { @@ -253,8 +254,8 @@ final class HierarchicalUriComponents extends UriComponents {
return;
}
verifyUriComponent(getScheme(), Type.SCHEME);
verifyUriComponent(userInfo, Type.USER_INFO);
verifyUriComponent(host, Type.HOST);
verifyUriComponent(this.userInfo, Type.USER_INFO);
verifyUriComponent(this.host, Type.HOST);
this.path.verify();
for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
verifyUriComponent(entry.getKey(), Type.QUERY_PARAM);
@ -300,7 +301,7 @@ final class HierarchicalUriComponents extends UriComponents { @@ -300,7 +301,7 @@ final class HierarchicalUriComponents extends UriComponents {
@Override
protected HierarchicalUriComponents expandInternal(UriTemplateVariables uriVariables) {
Assert.state(!this.encoded, "Cannot expand an already encoded UriComponents object");
String expandedScheme = expandUriComponent(this.getScheme(), uriVariables);
String expandedScheme = expandUriComponent(getScheme(), uriVariables);
String expandedUserInfo = expandUriComponent(this.userInfo, uriVariables);
String expandedHost = expandUriComponent(this.host, uriVariables);
PathComponent expandedPath = this.path.expand(uriVariables);

102
spring-web/src/main/java/org/springframework/web/util/UriUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@ -24,14 +24,15 @@ import java.util.regex.Pattern; @@ -24,14 +24,15 @@ import java.util.regex.Pattern;
import org.springframework.util.Assert;
/**
* Utility class for URI encoding and decoding based on RFC 3986. Offers encoding methods for the various URI
* components.
* Utility class for URI encoding and decoding based on RFC 3986.
* Offers encoding methods for the various URI components.
*
* <p>All {@code encode*(String, String} methods in this class operate in a similar way:
* <ul>
* <li>Valid characters for the specific URI component as defined in RFC 3986 stay the same.</li>
* <li>All other characters are converted into one or more bytes in the given encoding scheme. Each of the
* resulting bytes is written as a hexadecimal string in the "{@code %<i>xy</i>}" format.</li>
* <li>All other characters are converted into one or more bytes in the given encoding scheme.
* Each of the resulting bytes is written as a hexadecimal string in the "{@code %<i>xy</i>}"
* format.</li>
* </ul>
*
* @author Arjen Poutsma
@ -65,6 +66,7 @@ public abstract class UriUtils { @@ -65,6 +66,7 @@ public abstract class UriUtils {
"^" + HTTP_PATTERN + "(//(" + USERINFO_PATTERN + "@)?" + HOST_PATTERN + "(:" + PORT_PATTERN + ")?" + ")?" +
PATH_PATTERN + "(\\?" + LAST_PATTERN + ")?");
// encoding
/**
@ -73,7 +75,7 @@ public abstract class UriUtils { @@ -73,7 +75,7 @@ public abstract class UriUtils {
* <p><strong>Note</strong> that this method does not attempt to encode "=" and "&"
* characters in query parameter names and query parameter values because they cannot
* be parsed in a reliable way. Instead use:
* <pre>
* <pre class="code">
* UriComponents uriComponents = UriComponentsBuilder.fromUri("/path?name={value}").buildAndExpand("a=b");
* String encodedUri = uriComponents.encode().toUriString();
* </pre>
@ -86,19 +88,18 @@ public abstract class UriUtils { @@ -86,19 +88,18 @@ public abstract class UriUtils {
*/
@Deprecated
public static String encodeUri(String uri, String encoding) throws UnsupportedEncodingException {
Assert.notNull(uri, "'uri' must not be null");
Assert.hasLength(encoding, "'encoding' must not be empty");
Matcher m = URI_PATTERN.matcher(uri);
if (m.matches()) {
String scheme = m.group(2);
String authority = m.group(3);
String userinfo = m.group(5);
String host = m.group(6);
String port = m.group(8);
String path = m.group(9);
String query = m.group(11);
String fragment = m.group(13);
Assert.notNull(uri, "URI must not be null");
Assert.hasLength(encoding, "Encoding must not be empty");
Matcher matcher = URI_PATTERN.matcher(uri);
if (matcher.matches()) {
String scheme = matcher.group(2);
String authority = matcher.group(3);
String userinfo = matcher.group(5);
String host = matcher.group(6);
String port = matcher.group(8);
String path = matcher.group(9);
String query = matcher.group(11);
String fragment = matcher.group(13);
return encodeUriComponents(scheme, authority, userinfo, host, port, path, query, fragment, encoding);
}
else {
@ -114,7 +115,7 @@ public abstract class UriUtils { @@ -114,7 +115,7 @@ public abstract class UriUtils {
* <p><strong>Note</strong> that this method does not attempt to encode "=" and "&"
* characters in query parameter names and query parameter values because they cannot
* be parsed in a reliable way. Instead use:
* <pre>
* <pre class="code">
* UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl("/path?name={value}").buildAndExpand("a=b");
* String encodedUri = uriComponents.encode().toUriString();
* </pre>
@ -127,18 +128,17 @@ public abstract class UriUtils { @@ -127,18 +128,17 @@ public abstract class UriUtils {
*/
@Deprecated
public static String encodeHttpUrl(String httpUrl, String encoding) throws UnsupportedEncodingException {
Assert.notNull(httpUrl, "'httpUrl' must not be null");
Assert.hasLength(encoding, "'encoding' must not be empty");
Matcher m = HTTP_URL_PATTERN.matcher(httpUrl);
if (m.matches()) {
String scheme = m.group(1);
String authority = m.group(2);
String userinfo = m.group(4);
String host = m.group(5);
String portString = m.group(7);
String path = m.group(8);
String query = m.group(10);
Assert.notNull(httpUrl, "HTTP URL must not be null");
Assert.hasLength(encoding, "Encoding must not be empty");
Matcher matcher = HTTP_URL_PATTERN.matcher(httpUrl);
if (matcher.matches()) {
String scheme = matcher.group(1);
String authority = matcher.group(2);
String userinfo = matcher.group(4);
String host = matcher.group(5);
String portString = matcher.group(7);
String path = matcher.group(8);
String query = matcher.group(10);
return encodeUriComponents(scheme, authority, userinfo, host, portString, path, query, null, encoding);
}
else {
@ -168,7 +168,7 @@ public abstract class UriUtils { @@ -168,7 +168,7 @@ public abstract class UriUtils {
String host, String port, String path, String query, String fragment, String encoding)
throws UnsupportedEncodingException {
Assert.hasLength(encoding, "'encoding' must not be empty");
Assert.hasLength(encoding, "Encoding must not be empty");
StringBuilder sb = new StringBuilder();
if (scheme != null) {
@ -217,8 +217,7 @@ public abstract class UriUtils { @@ -217,8 +217,7 @@ public abstract class UriUtils {
* @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/
public static String encodeScheme(String scheme, String encoding) throws UnsupportedEncodingException {
return HierarchicalUriComponents.encodeUriComponent(scheme, encoding,
HierarchicalUriComponents.Type.SCHEME);
return HierarchicalUriComponents.encodeUriComponent(scheme, encoding, HierarchicalUriComponents.Type.SCHEME);
}
/**
@ -229,8 +228,7 @@ public abstract class UriUtils { @@ -229,8 +228,7 @@ public abstract class UriUtils {
* @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/
public static String encodeAuthority(String authority, String encoding) throws UnsupportedEncodingException {
return HierarchicalUriComponents.encodeUriComponent(authority, encoding,
HierarchicalUriComponents.Type.AUTHORITY);
return HierarchicalUriComponents.encodeUriComponent(authority, encoding, HierarchicalUriComponents.Type.AUTHORITY);
}
/**
@ -241,8 +239,7 @@ public abstract class UriUtils { @@ -241,8 +239,7 @@ public abstract class UriUtils {
* @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/
public static String encodeUserInfo(String userInfo, String encoding) throws UnsupportedEncodingException {
return HierarchicalUriComponents.encodeUriComponent(userInfo, encoding,
HierarchicalUriComponents.Type.USER_INFO);
return HierarchicalUriComponents.encodeUriComponent(userInfo, encoding, HierarchicalUriComponents.Type.USER_INFO);
}
/**
@ -253,8 +250,7 @@ public abstract class UriUtils { @@ -253,8 +250,7 @@ public abstract class UriUtils {
* @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/
public static String encodeHost(String host, String encoding) throws UnsupportedEncodingException {
return HierarchicalUriComponents
.encodeUriComponent(host, encoding, HierarchicalUriComponents.Type.HOST);
return HierarchicalUriComponents.encodeUriComponent(host, encoding, HierarchicalUriComponents.Type.HOST);
}
/**
@ -265,8 +261,7 @@ public abstract class UriUtils { @@ -265,8 +261,7 @@ public abstract class UriUtils {
* @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/
public static String encodePort(String port, String encoding) throws UnsupportedEncodingException {
return HierarchicalUriComponents
.encodeUriComponent(port, encoding, HierarchicalUriComponents.Type.PORT);
return HierarchicalUriComponents.encodeUriComponent(port, encoding, HierarchicalUriComponents.Type.PORT);
}
/**
@ -277,8 +272,7 @@ public abstract class UriUtils { @@ -277,8 +272,7 @@ public abstract class UriUtils {
* @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/
public static String encodePath(String path, String encoding) throws UnsupportedEncodingException {
return HierarchicalUriComponents
.encodeUriComponent(path, encoding, HierarchicalUriComponents.Type.PATH);
return HierarchicalUriComponents.encodeUriComponent(path, encoding, HierarchicalUriComponents.Type.PATH);
}
/**
@ -289,8 +283,7 @@ public abstract class UriUtils { @@ -289,8 +283,7 @@ public abstract class UriUtils {
* @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/
public static String encodePathSegment(String segment, String encoding) throws UnsupportedEncodingException {
return HierarchicalUriComponents.encodeUriComponent(segment, encoding,
HierarchicalUriComponents.Type.PATH_SEGMENT);
return HierarchicalUriComponents.encodeUriComponent(segment, encoding, HierarchicalUriComponents.Type.PATH_SEGMENT);
}
/**
@ -301,8 +294,7 @@ public abstract class UriUtils { @@ -301,8 +294,7 @@ public abstract class UriUtils {
* @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/
public static String encodeQuery(String query, String encoding) throws UnsupportedEncodingException {
return HierarchicalUriComponents
.encodeUriComponent(query, encoding, HierarchicalUriComponents.Type.QUERY);
return HierarchicalUriComponents.encodeUriComponent(query, encoding, HierarchicalUriComponents.Type.QUERY);
}
/**
@ -313,8 +305,7 @@ public abstract class UriUtils { @@ -313,8 +305,7 @@ public abstract class UriUtils {
* @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/
public static String encodeQueryParam(String queryParam, String encoding) throws UnsupportedEncodingException {
return HierarchicalUriComponents.encodeUriComponent(queryParam, encoding,
HierarchicalUriComponents.Type.QUERY_PARAM);
return HierarchicalUriComponents.encodeUriComponent(queryParam, encoding, HierarchicalUriComponents.Type.QUERY_PARAM);
}
/**
@ -325,8 +316,7 @@ public abstract class UriUtils { @@ -325,8 +316,7 @@ public abstract class UriUtils {
* @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/
public static String encodeFragment(String fragment, String encoding) throws UnsupportedEncodingException {
return HierarchicalUriComponents.encodeUriComponent(fragment, encoding,
HierarchicalUriComponents.Type.FRAGMENT);
return HierarchicalUriComponents.encodeUriComponent(fragment, encoding, HierarchicalUriComponents.Type.FRAGMENT);
}
@ -348,8 +338,8 @@ public abstract class UriUtils { @@ -348,8 +338,8 @@ public abstract class UriUtils {
* @see java.net.URLDecoder#decode(String, String)
*/
public static String decode(String source, String encoding) throws UnsupportedEncodingException {
Assert.notNull(source, "'source' must not be null");
Assert.hasLength(encoding, "'encoding' must not be empty");
Assert.notNull(source, "Source must not be null");
Assert.hasLength(encoding, "Encoding must not be empty");
int length = source.length();
ByteArrayOutputStream bos = new ByteArrayOutputStream(length);
boolean changed = false;
@ -376,7 +366,7 @@ public abstract class UriUtils { @@ -376,7 +366,7 @@ public abstract class UriUtils {
bos.write(ch);
}
}
return changed ? new String(bos.toByteArray(), encoding) : source;
return (changed ? new String(bos.toByteArray(), encoding) : source);
}
}

7
spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -299,7 +299,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D @@ -299,7 +299,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
LocaleResolver resolver) {
BaseLocaleUrlDefinitionDAO dao = super.instantiateLocaleDefinitionDao(applicationContext, resolver);
if (checkRefresh && dao instanceof CachingLocaleUrlDefinitionDAO) {
((CachingLocaleUrlDefinitionDAO) dao).setCheckRefresh(checkRefresh);
((CachingLocaleUrlDefinitionDAO) dao).setCheckRefresh(true);
}
return dao;
}
@ -338,7 +338,8 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D @@ -338,7 +338,8 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
protected PreparerFactory createPreparerFactory(ApplicationContext context) {
if (preparerFactoryClass != null) {
return BeanUtils.instantiate(preparerFactoryClass);
} else {
}
else {
return super.createPreparerFactory(context);
}
}

82
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@ -19,7 +19,6 @@ package org.springframework.web.servlet.handler; @@ -19,7 +19,6 @@ package org.springframework.web.servlet.handler;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.BeansException;
@ -203,29 +202,28 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport @@ -203,29 +202,28 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
* <p>Will be invoked before {@link #initInterceptors()} adapts the specified
* interceptors into {@link HandlerInterceptor} instances.
* <p>The default implementation is empty.
* @param interceptors the configured interceptor List (never {@code null}),
* allowing to add further interceptors before as well as after the existing
* interceptors
* @param interceptors the configured interceptor List (never {@code null}), allowing
* to add further interceptors before as well as after the existing interceptors
*/
protected void extendInterceptors(List<Object> interceptors) {
}
/**
* Detects beans of type {@link MappedInterceptor} and adds them to the list of mapped interceptors.
* This is done in addition to any {@link MappedInterceptor}s that may have been provided via
* {@link #setInterceptors(Object[])}. Subclasses can override this method to change that.
*
* @param mappedInterceptors an empty list to add MappedInterceptor types to
* Detect beans of type {@link MappedInterceptor} and add them to the list of mapped interceptors.
* <p>This is called in addition to any {@link MappedInterceptor}s that may have been provided
* via {@link #setInterceptors}, by default adding all beans of type {@link MappedInterceptor}
* from the current context and its ancestors. Subclasses can override and refine this policy.
* @param mappedInterceptors an empty list to add {@link MappedInterceptor} instances to
*/
protected void detectMappedInterceptors(List<MappedInterceptor> mappedInterceptors) {
mappedInterceptors.addAll(
BeanFactoryUtils.beansOfTypeIncludingAncestors(
getApplicationContext(),MappedInterceptor.class, true, false).values());
getApplicationContext(), MappedInterceptor.class, true, false).values());
}
/**
* Initialize the specified interceptors, checking for {@link MappedInterceptor}s and adapting
* HandlerInterceptors where necessary.
* Initialize the specified interceptors, checking for {@link MappedInterceptor}s and
* adapting {@link HandlerInterceptor}s and {@link WebRequestInterceptor}s if necessary.
* @see #setInterceptors
* @see #adaptInterceptor
*/
@ -237,19 +235,20 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport @@ -237,19 +235,20 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
throw new IllegalArgumentException("Entry number " + i + " in interceptors array is null");
}
if (interceptor instanceof MappedInterceptor) {
mappedInterceptors.add((MappedInterceptor) interceptor);
this.mappedInterceptors.add((MappedInterceptor) interceptor);
}
else {
adaptedInterceptors.add(adaptInterceptor(interceptor));
this.adaptedInterceptors.add(adaptInterceptor(interceptor));
}
}
}
}
/**
* Adapt the given interceptor object to the HandlerInterceptor interface.
* <p>Supported interceptor types are HandlerInterceptor and WebRequestInterceptor.
* Each given WebRequestInterceptor will be wrapped in a WebRequestHandlerInterceptorAdapter.
* Adapt the given interceptor object to the {@link HandlerInterceptor} interface.
* <p>By default, the supported interceptor types are {@link HandlerInterceptor}
* and {@link WebRequestInterceptor}. Each given {@link WebRequestInterceptor}
* will be wrapped in a {@link WebRequestHandlerInterceptorAdapter}.
* Can be overridden in subclasses.
* @param interceptor the specified interceptor object
* @return the interceptor wrapped as HandlerInterceptor
@ -270,12 +269,12 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport @@ -270,12 +269,12 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
}
/**
* Return the adapted interceptors as HandlerInterceptor array.
* @return the array of HandlerInterceptors, or {@code null} if none
* Return the adapted interceptors as {@link HandlerInterceptor} array.
* @return the array of {@link HandlerInterceptor}s, or {@code null} if none
*/
protected final HandlerInterceptor[] getAdaptedInterceptors() {
int count = adaptedInterceptors.size();
return (count > 0) ? adaptedInterceptors.toArray(new HandlerInterceptor[count]) : null;
int count = this.adaptedInterceptors.size();
return (count > 0 ? this.adaptedInterceptors.toArray(new HandlerInterceptor[count]) : null);
}
/**
@ -283,8 +282,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport @@ -283,8 +282,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
* @return the array of {@link MappedInterceptor}s, or {@code null} if none
*/
protected final MappedInterceptor[] getMappedInterceptors() {
int count = mappedInterceptors.size();
return (count > 0) ? mappedInterceptors.toArray(new MappedInterceptor[count]) : null;
int count = this.mappedInterceptors.size();
return (count > 0 ? this.mappedInterceptors.toArray(new MappedInterceptor[count]) : null);
}
/**
@ -324,31 +323,32 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport @@ -324,31 +323,32 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
protected abstract Object getHandlerInternal(HttpServletRequest request) throws Exception;
/**
* Build a HandlerExecutionChain for the given handler, including applicable interceptors.
* <p>The default implementation simply builds a standard HandlerExecutionChain with
* the given handler, the handler mapping's common interceptors, and any {@link MappedInterceptor}s
* matching to the current request URL. Subclasses may
* override this in order to extend/rearrange the list of interceptors.
* <p><b>NOTE:</b> The passed-in handler object may be a raw handler or a pre-built
* HandlerExecutionChain. This method should handle those two cases explicitly,
* either building a new HandlerExecutionChain or extending the existing chain.
* <p>For simply adding an interceptor, consider calling {@code super.getHandlerExecutionChain}
* and invoking {@link HandlerExecutionChain#addInterceptor} on the returned chain object.
* Build a {@link HandlerExecutionChain} for the given handler, including
* applicable interceptors.
* <p>The default implementation builds a standard {@link HandlerExecutionChain}
* with the given handler, the handler mapping's common interceptors, and any
* {@link MappedInterceptor}s matching to the current request URL. Subclasses
* may override this in order to extend/rearrange the list of interceptors.
* <p><b>NOTE:</b> The passed-in handler object may be a raw handler or a
* pre-built {@link HandlerExecutionChain}. This method should handle those
* two cases explicitly, either building a new {@link HandlerExecutionChain}
* or extending the existing chain.
* <p>For simply adding an interceptor in a custom subclass, consider calling
* {@code super.getHandlerExecutionChain(handler, request)} and invoking
* {@link HandlerExecutionChain#addInterceptor} on the returned chain object.
* @param handler the resolved handler instance (never {@code null})
* @param request current HTTP request
* @return the HandlerExecutionChain (never {@code null})
* @see #getAdaptedInterceptors()
*/
protected HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request) {
HandlerExecutionChain chain =
(handler instanceof HandlerExecutionChain) ?
(HandlerExecutionChain) handler : new HandlerExecutionChain(handler);
HandlerExecutionChain chain = (handler instanceof HandlerExecutionChain ?
(HandlerExecutionChain) handler : new HandlerExecutionChain(handler));
chain.addInterceptors(getAdaptedInterceptors());
String lookupPath = urlPathHelper.getLookupPathForRequest(request);
for (MappedInterceptor mappedInterceptor : mappedInterceptors) {
if (mappedInterceptor.matches(lookupPath, pathMatcher)) {
String lookupPath = this.urlPathHelper.getLookupPathForRequest(request);
for (MappedInterceptor mappedInterceptor : this.mappedInterceptors) {
if (mappedInterceptor.matches(lookupPath, this.pathMatcher)) {
chain.addInterceptor(mappedInterceptor.getInterceptor());
}
}

4
spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/TilesConfigurer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@ -439,7 +439,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D @@ -439,7 +439,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
BaseLocaleUrlDefinitionDAO dao = super.instantiateLocaleDefinitionDao(
applicationContext, contextFactory, resolver);
if (checkRefresh && dao instanceof CachingLocaleUrlDefinitionDAO) {
((CachingLocaleUrlDefinitionDAO) dao).setCheckRefresh(checkRefresh);
((CachingLocaleUrlDefinitionDAO) dao).setCheckRefresh(true);
}
return dao;
}

25
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@ -16,15 +16,13 @@ @@ -16,15 +16,13 @@
package org.springframework.web.servlet.mvc.method.annotation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.ui.Model;
@ -41,6 +39,8 @@ import org.springframework.web.servlet.DispatcherServlet; @@ -41,6 +39,8 @@ import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.FlashMap;
import org.springframework.web.servlet.ModelAndView;
import static org.junit.Assert.*;
/**
* Unit tests for {@link RequestMappingHandlerAdapter}.
*
@ -66,6 +66,7 @@ public class RequestMappingHandlerAdapterTests { @@ -66,6 +66,7 @@ public class RequestMappingHandlerAdapterTests {
private StaticWebApplicationContext webAppContext;
@BeforeClass
public static void setupOnce() {
RequestMappingHandlerAdapter adapter = new RequestMappingHandlerAdapter();
@ -86,23 +87,24 @@ public class RequestMappingHandlerAdapterTests { @@ -86,23 +87,24 @@ public class RequestMappingHandlerAdapterTests {
this.response = new MockHttpServletResponse();
}
@Test
public void cacheControlWithoutSessionAttributes() throws Exception {
HandlerMethod handlerMethod = handlerMethod(new SimpleController(), "handle");
this.handlerAdapter.afterPropertiesSet();
this.handlerAdapter.setCacheSeconds(100);
this.handlerAdapter.handle(this.request, this.response, handlerMethod);
this.handlerAdapter.afterPropertiesSet();
assertTrue(response.getHeader("Cache-Control").toString().contains("max-age"));
this.handlerAdapter.handle(this.request, this.response, handlerMethod);
assertTrue(response.getHeader("Cache-Control").contains("max-age"));
}
@Test
public void cacheControlWithSessionAttributes() throws Exception {
SessionAttributeController handler = new SessionAttributeController();
this.handlerAdapter.afterPropertiesSet();
this.handlerAdapter.setCacheSeconds(100);
this.handlerAdapter.handle(this.request, this.response, handlerMethod(handler, "handle"));
this.handlerAdapter.afterPropertiesSet();
this.handlerAdapter.handle(this.request, this.response, handlerMethod(handler, "handle"));
assertEquals("no-cache", this.response.getHeader("Cache-Control"));
}
@ -211,6 +213,7 @@ public class RequestMappingHandlerAdapterTests { @@ -211,6 +213,7 @@ public class RequestMappingHandlerAdapterTests {
}
}
@SessionAttributes("attr1")
private static class SessionAttributeController {
@ -219,6 +222,7 @@ public class RequestMappingHandlerAdapterTests { @@ -219,6 +222,7 @@ public class RequestMappingHandlerAdapterTests {
}
}
@SuppressWarnings("unused")
private static class RedirectAttributeController {
@ -228,6 +232,7 @@ public class RequestMappingHandlerAdapterTests { @@ -228,6 +232,7 @@ public class RequestMappingHandlerAdapterTests {
}
}
@ControllerAdvice
private static class ModelAttributeAdvice {
@ -238,4 +243,4 @@ public class RequestMappingHandlerAdapterTests { @@ -238,4 +243,4 @@ public class RequestMappingHandlerAdapterTests {
}
}
}
}

Loading…
Cancel
Save