Polishing
This commit is contained in:
parent
6f58491b9c
commit
0ec99fdef7
|
@ -30,13 +30,13 @@ import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates information about a bean method consisting of a {@link #getMethod() method}
|
* Encapsulates information about a handler method consisting of a {@linkplain #getMethod() method}
|
||||||
* and a {@link #getBean() bean}. Provides convenient access to method parameters,
|
* and a {@linkplain #getBean() bean}. Provides convenient access to method parameters,
|
||||||
* method return value, method annotations.
|
* method return value, method annotations.
|
||||||
*
|
*
|
||||||
* <p>The class may be created with a bean instance or with a bean name (e.g. lazy bean,
|
* <p>The class may be created with a bean instance or with a bean name (e.g. lazy-init bean,
|
||||||
* prototype bean). Use {@link #createWithResolvedBean()} to obtain an {@link HandlerMethod}
|
* prototype bean). Use {@link #createWithResolvedBean()} to obtain a {@link HandlerMethod}
|
||||||
* instance with a bean instance initialized through the bean factory.
|
* instance with a bean instance resolved through the associated {@link BeanFactory}.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
|
@ -228,7 +228,7 @@ public class HandlerMethod {
|
||||||
}
|
}
|
||||||
if (obj != null && obj instanceof HandlerMethod) {
|
if (obj != null && obj instanceof HandlerMethod) {
|
||||||
HandlerMethod other = (HandlerMethod) obj;
|
HandlerMethod other = (HandlerMethod) obj;
|
||||||
return this.bean.equals(other.bean) && this.method.equals(other.method);
|
return (this.bean.equals(other.bean) && this.method.equals(other.method));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,11 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
@ -187,17 +187,17 @@ public class UrlPathHelper {
|
||||||
// e.g. with index page: URI="/", servletPath="/index.html"
|
// e.g. with index page: URI="/", servletPath="/index.html"
|
||||||
return pathInfo;
|
return pathInfo;
|
||||||
}
|
}
|
||||||
if (this.urlDecode == false) {
|
if (!this.urlDecode) {
|
||||||
// No path info... (not mapped by prefix, nor by extension, nor "/*")
|
// No path info... (not mapped by prefix, nor by extension, nor "/*")
|
||||||
// For the default servlet mapping (i.e. "/"), urlDecode=false can
|
// For the default servlet mapping (i.e. "/"), urlDecode=false can
|
||||||
// cause issues since getServletPath() returns a decoded path.
|
// cause issues since getServletPath() returns a decoded path.
|
||||||
// If decoding pathWithinApp yields a match just use pathWithinApp
|
// If decoding pathWithinApp yields a match just use pathWithinApp.
|
||||||
path = getRemainingPath(decodeInternal(request, pathWithinApp), servletPath, false);
|
path = getRemainingPath(decodeInternal(request, pathWithinApp), servletPath, false);
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
return pathWithinApp;
|
return pathWithinApp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, use the full servlet path
|
// Otherwise, use the full servlet path.
|
||||||
return servletPath;
|
return servletPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ public class UrlPathHelper {
|
||||||
else if (requestUri.charAt(index1) == ';') {
|
else if (requestUri.charAt(index1) == ';') {
|
||||||
index1 = requestUri.indexOf('/', index1);
|
index1 = requestUri.indexOf('/', index1);
|
||||||
}
|
}
|
||||||
return (index1 != -1) ? requestUri.substring(index1) : "";
|
return (index1 != -1 ? requestUri.substring(index1) : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -312,8 +312,7 @@ public class UrlPathHelper {
|
||||||
if (servletPath == null) {
|
if (servletPath == null) {
|
||||||
servletPath = request.getServletPath();
|
servletPath = request.getServletPath();
|
||||||
}
|
}
|
||||||
if (servletPath.length() > 1 && servletPath.endsWith("/") &&
|
if (servletPath.length() > 1 && servletPath.endsWith("/") && shouldRemoveTrailingServletPathSlash(request)) {
|
||||||
shouldRemoveTrailingServletPathSlash(request)) {
|
|
||||||
// On WebSphere, in non-compliant mode, for a "/foo/" case that would be "/foo"
|
// On WebSphere, in non-compliant mode, for a "/foo/" case that would be "/foo"
|
||||||
// on all other servlet containers: removing trailing slash, proceeding with
|
// on all other servlet containers: removing trailing slash, proceeding with
|
||||||
// that remaining slash as final lookup path...
|
// that remaining slash as final lookup path...
|
||||||
|
@ -449,7 +448,6 @@ public class UrlPathHelper {
|
||||||
* Remove ";" (semicolon) content from the given request URI if the
|
* Remove ";" (semicolon) content from the given request URI if the
|
||||||
* {@linkplain #setRemoveSemicolonContent(boolean) removeSemicolonContent}
|
* {@linkplain #setRemoveSemicolonContent(boolean) removeSemicolonContent}
|
||||||
* property is set to "true". Note that "jssessionid" is always removed.
|
* property is set to "true". Note that "jssessionid" is always removed.
|
||||||
*
|
|
||||||
* @param requestUri the request URI string to remove ";" content from
|
* @param requestUri the request URI string to remove ";" content from
|
||||||
* @return the updated URI string
|
* @return the updated URI string
|
||||||
*/
|
*/
|
||||||
|
@ -486,7 +484,6 @@ public class UrlPathHelper {
|
||||||
* assumed the URL path from which the variables were extracted is already
|
* assumed the URL path from which the variables were extracted is already
|
||||||
* decoded through a call to
|
* decoded through a call to
|
||||||
* {@link #getLookupPathForRequest(HttpServletRequest)}.
|
* {@link #getLookupPathForRequest(HttpServletRequest)}.
|
||||||
*
|
|
||||||
* @param request current HTTP request
|
* @param request current HTTP request
|
||||||
* @param vars URI variables extracted from the URL path
|
* @param vars URI variables extracted from the URL path
|
||||||
* @return the same Map or a new Map instance
|
* @return the same Map or a new Map instance
|
||||||
|
@ -511,7 +508,6 @@ public class UrlPathHelper {
|
||||||
* assumed the URL path from which the variables were extracted is already
|
* assumed the URL path from which the variables were extracted is already
|
||||||
* decoded through a call to
|
* decoded through a call to
|
||||||
* {@link #getLookupPathForRequest(HttpServletRequest)}.
|
* {@link #getLookupPathForRequest(HttpServletRequest)}.
|
||||||
*
|
|
||||||
* @param request current HTTP request
|
* @param request current HTTP request
|
||||||
* @param vars URI variables extracted from the URL path
|
* @param vars URI variables extracted from the URL path
|
||||||
* @return the same Map or a new Map instance
|
* @return the same Map or a new Map instance
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class InvocableHandlerMethodTests {
|
||||||
|
|
||||||
private NativeWebRequest webRequest;
|
private NativeWebRequest webRequest;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
Method method = Handler.class.getDeclaredMethod("handle", Integer.class, String.class);
|
Method method = Handler.class.getDeclaredMethod("handle", Integer.class, String.class);
|
||||||
|
@ -52,6 +53,7 @@ public class InvocableHandlerMethodTests {
|
||||||
this.webRequest = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse());
|
this.webRequest = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveArg() throws Exception {
|
public void resolveArg() throws Exception {
|
||||||
StubArgumentResolver intResolver = new StubArgumentResolver(Integer.class, 99);
|
StubArgumentResolver intResolver = new StubArgumentResolver(Integer.class, 99);
|
||||||
|
@ -63,11 +65,9 @@ public class InvocableHandlerMethodTests {
|
||||||
handlerMethod.setHandlerMethodArgumentResolvers(composite);
|
handlerMethod.setHandlerMethodArgumentResolvers(composite);
|
||||||
|
|
||||||
Object returnValue = handlerMethod.invokeForRequest(webRequest, null);
|
Object returnValue = handlerMethod.invokeForRequest(webRequest, null);
|
||||||
|
|
||||||
assertEquals(1, intResolver.getResolvedParameters().size());
|
assertEquals(1, intResolver.getResolvedParameters().size());
|
||||||
assertEquals(1, stringResolver.getResolvedParameters().size());
|
assertEquals(1, stringResolver.getResolvedParameters().size());
|
||||||
assertEquals("99-value", returnValue);
|
assertEquals("99-value", returnValue);
|
||||||
|
|
||||||
assertEquals("intArg", intResolver.getResolvedParameters().get(0).getParameterName());
|
assertEquals("intArg", intResolver.getResolvedParameters().get(0).getParameterName());
|
||||||
assertEquals("stringArg", stringResolver.getResolvedParameters().get(0).getParameterName());
|
assertEquals("stringArg", stringResolver.getResolvedParameters().get(0).getParameterName());
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,6 @@ public class InvocableHandlerMethodTests {
|
||||||
handlerMethod.setHandlerMethodArgumentResolvers(composite);
|
handlerMethod.setHandlerMethodArgumentResolvers(composite);
|
||||||
|
|
||||||
Object returnValue = handlerMethod.invokeForRequest(webRequest, null);
|
Object returnValue = handlerMethod.invokeForRequest(webRequest, null);
|
||||||
|
|
||||||
assertEquals(1, intResolver.getResolvedParameters().size());
|
assertEquals(1, intResolver.getResolvedParameters().size());
|
||||||
assertEquals(1, stringResolver.getResolvedParameters().size());
|
assertEquals(1, stringResolver.getResolvedParameters().size());
|
||||||
assertEquals("null-null", returnValue);
|
assertEquals("null-null", returnValue);
|
||||||
|
@ -119,7 +118,6 @@ public class InvocableHandlerMethodTests {
|
||||||
handlerMethod.setHandlerMethodArgumentResolvers(composite);
|
handlerMethod.setHandlerMethodArgumentResolvers(composite);
|
||||||
|
|
||||||
Object returnValue = handlerMethod.invokeForRequest(webRequest, null, 2, "value2");
|
Object returnValue = handlerMethod.invokeForRequest(webRequest, null, 2, "value2");
|
||||||
|
|
||||||
assertEquals("2-value2", returnValue);
|
assertEquals("2-value2", returnValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,8 +132,7 @@ public class InvocableHandlerMethodTests {
|
||||||
fail("Expected exception");
|
fail("Expected exception");
|
||||||
}
|
}
|
||||||
catch (HttpMessageNotReadableException ex) {
|
catch (HttpMessageNotReadableException ex) {
|
||||||
// Expected..
|
// expected - allow HandlerMethodArgumentResolver exceptions to propagate
|
||||||
// Allow HandlerMethodArgumentResolver exceptions to propagate..
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +205,7 @@ public class InvocableHandlerMethodTests {
|
||||||
fail("Expected exception");
|
fail("Expected exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static class Handler {
|
private static class Handler {
|
||||||
|
|
||||||
|
@ -216,6 +214,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static class ExceptionRaisingHandler {
|
private static class ExceptionRaisingHandler {
|
||||||
|
|
||||||
|
@ -228,9 +227,9 @@ public class InvocableHandlerMethodTests {
|
||||||
public void raiseException() throws Throwable {
|
public void raiseException() throws Throwable {
|
||||||
throw t;
|
throw t;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class ExceptionRaisingArgumentResolver implements HandlerMethodArgumentResolver {
|
private static class ExceptionRaisingArgumentResolver implements HandlerMethodArgumentResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -74,6 +74,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
|
||||||
/** Whether or not the view should add path variables in the model */
|
/** Whether or not the view should add path variables in the model */
|
||||||
private boolean exposePathVariables = true;
|
private boolean exposePathVariables = true;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the view's name. Helpful for traceability.
|
* Set the view's name. Helpful for traceability.
|
||||||
* <p>Framework code must call this when constructing views.
|
* <p>Framework code must call this when constructing views.
|
||||||
|
@ -244,9 +245,10 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
|
||||||
* Returns the value of the flag indicating whether path variables should be added to the model or not.
|
* Returns the value of the flag indicating whether path variables should be added to the model or not.
|
||||||
*/
|
*/
|
||||||
public boolean isExposePathVariables() {
|
public boolean isExposePathVariables() {
|
||||||
return exposePathVariables;
|
return this.exposePathVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the view given the specified model, merging it with static
|
* Prepares the view given the specified model, merging it with static
|
||||||
* attributes and a RequestContext attribute, if necessary.
|
* attributes and a RequestContext attribute, if necessary.
|
||||||
|
@ -261,7 +263,6 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> mergedModel = createMergedOutputModel(model, request, response);
|
Map<String, Object> mergedModel = createMergedOutputModel(model, request, response);
|
||||||
|
|
||||||
prepareResponse(request, response);
|
prepareResponse(request, response);
|
||||||
renderMergedOutputModel(mergedModel, request, response);
|
renderMergedOutputModel(mergedModel, request, response);
|
||||||
}
|
}
|
||||||
|
@ -271,11 +272,11 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
|
||||||
* Dynamic values take precedence over static attributes.
|
* Dynamic values take precedence over static attributes.
|
||||||
*/
|
*/
|
||||||
protected Map<String, Object> createMergedOutputModel(Map<String, ?> model, HttpServletRequest request,
|
protected Map<String, Object> createMergedOutputModel(Map<String, ?> model, HttpServletRequest request,
|
||||||
|
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> pathVars = this.exposePathVariables ?
|
Map<String, Object> pathVars = (this.exposePathVariables ?
|
||||||
(Map<String, Object>) request.getAttribute(View.PATH_VARIABLES) : null;
|
(Map<String, Object>) request.getAttribute(View.PATH_VARIABLES) : null);
|
||||||
|
|
||||||
// Consolidate static and dynamic model attributes.
|
// Consolidate static and dynamic model attributes.
|
||||||
int size = this.staticAttributes.size();
|
int size = this.staticAttributes.size();
|
||||||
|
|
Loading…
Reference in New Issue