Polishing

This commit is contained in:
Juergen Hoeller 2014-03-25 00:54:02 +01:00
parent c11484b2e7
commit 074590730b
3 changed files with 19 additions and 19 deletions

View File

@ -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"); * 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.
@ -68,7 +68,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
* @param servletRequest the servlet request * @param servletRequest the servlet request
*/ */
public ServletServerHttpRequest(HttpServletRequest servletRequest) { public ServletServerHttpRequest(HttpServletRequest servletRequest) {
Assert.notNull(servletRequest, "'servletRequest' must not be null"); Assert.notNull(servletRequest, "HttpServletRequest must not be null");
this.servletRequest = servletRequest; this.servletRequest = servletRequest;
} }

View File

@ -180,7 +180,7 @@ final class HierarchicalUriComponents extends UriComponents {
if (this.encoded) { if (this.encoded) {
return this; 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 encodedUserInfo = encodeUriComponent(this.userInfo, encoding, Type.USER_INFO);
String encodedHost = encodeUriComponent(this.host, encoding, getHostType()); String encodedHost = encodeUriComponent(this.host, encoding, getHostType());
@ -245,6 +245,7 @@ final class HierarchicalUriComponents extends UriComponents {
return (this.host != null && this.host.startsWith("[")) ? Type.HOST_IPV6 : Type.HOST_IPV4; return (this.host != null && this.host.startsWith("[")) ? Type.HOST_IPV6 : Type.HOST_IPV4;
} }
// verifying // verifying
/** /**
@ -257,8 +258,8 @@ final class HierarchicalUriComponents extends UriComponents {
return; return;
} }
verifyUriComponent(getScheme(), Type.SCHEME); verifyUriComponent(getScheme(), Type.SCHEME);
verifyUriComponent(userInfo, Type.USER_INFO); verifyUriComponent(this.userInfo, Type.USER_INFO);
verifyUriComponent(host, getHostType()); verifyUriComponent(this.host, getHostType());
this.path.verify(); this.path.verify();
for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) { for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
verifyUriComponent(entry.getKey(), Type.QUERY_PARAM); verifyUriComponent(entry.getKey(), Type.QUERY_PARAM);
@ -304,7 +305,7 @@ final class HierarchicalUriComponents extends UriComponents {
@Override @Override
protected HierarchicalUriComponents expandInternal(UriTemplateVariables uriVariables) { protected HierarchicalUriComponents expandInternal(UriTemplateVariables uriVariables) {
Assert.state(!this.encoded, "Cannot expand an already encoded UriComponents object"); 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 expandedUserInfo = expandUriComponent(this.userInfo, uriVariables);
String expandedHost = expandUriComponent(this.host, uriVariables); String expandedHost = expandUriComponent(this.host, uriVariables);
PathComponent expandedPath = this.path.expand(uriVariables); PathComponent expandedPath = this.path.expand(uriVariables);

View File

@ -272,12 +272,12 @@ public class DispatcherServlet extends FrameworkServlet {
/** Detect all ViewResolvers or just expect "viewResolver" bean? */ /** Detect all ViewResolvers or just expect "viewResolver" bean? */
private boolean detectAllViewResolvers = true; private boolean detectAllViewResolvers = true;
/** Perform cleanup of request attributes after include request? */
private boolean cleanupAfterInclude = true;
/** Throw a NoHandlerFoundException if no Handler was found to process this request? **/ /** Throw a NoHandlerFoundException if no Handler was found to process this request? **/
private boolean throwExceptionIfNoHandlerFound = false; private boolean throwExceptionIfNoHandlerFound = false;
/** Perform cleanup of request attributes after include request? */
private boolean cleanupAfterInclude = true;
/** MultipartResolver used by this servlet */ /** MultipartResolver used by this servlet */
private MultipartResolver multipartResolver; private MultipartResolver multipartResolver;
@ -413,12 +413,11 @@ public class DispatcherServlet extends FrameworkServlet {
* Set whether to throw a NoHandlerFoundException when no Handler was found for this request. * Set whether to throw a NoHandlerFoundException when no Handler was found for this request.
* This exception can then be caught with a HandlerExceptionResolver or an * This exception can then be caught with a HandlerExceptionResolver or an
* {@code @ExceptionHandler} controller method. * {@code @ExceptionHandler} controller method.
* <p>Note that if * <p>Note that if {@link org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler}
* {@link org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler} * is used, then requests will always be forwarded to the default servlet and a
* is used, then requests will always be forwarded to the default servlet and * NoHandlerFoundException would never be thrown in that case.
* a NoHandlerFoundException would never be thrown in that case. * <p>Default is "false", meaning the DispatcherServlet sends a NOT_FOUND error through the
* <p>Default is "false", meaning the DispatcherServlet sends a NOT_FOUND error * Servlet response.
* through the Servlet response.
* @since 4.0 * @since 4.0
*/ */
public void setThrowExceptionIfNoHandlerFound(boolean throwExceptionIfNoHandlerFound) { public void setThrowExceptionIfNoHandlerFound(boolean throwExceptionIfNoHandlerFound) {
@ -1111,10 +1110,10 @@ public class DispatcherServlet extends FrameworkServlet {
pageNotFoundLogger.warn("No mapping found for HTTP request with URI [" + getRequestUri(request) + pageNotFoundLogger.warn("No mapping found for HTTP request with URI [" + getRequestUri(request) +
"] in DispatcherServlet with name '" + getServletName() + "'"); "] in DispatcherServlet with name '" + getServletName() + "'");
} }
if (throwExceptionIfNoHandlerFound) { if (this.throwExceptionIfNoHandlerFound) {
ServletServerHttpRequest req = new ServletServerHttpRequest(request); ServletServerHttpRequest sshr = new ServletServerHttpRequest(request);
throw new NoHandlerFoundException(req.getMethod().name(), throw new NoHandlerFoundException(
req.getServletRequest().getRequestURI(),req.getHeaders()); sshr.getMethod().name(), sshr.getServletRequest().getRequestURI(), sshr.getHeaders());
} }
else { else {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);