Skip to content

Commit 0745907

Browse files
committed
Polishing
1 parent c11484b commit 0745907

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,7 +68,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
6868
* @param servletRequest the servlet request
6969
*/
7070
public ServletServerHttpRequest(HttpServletRequest servletRequest) {
71-
Assert.notNull(servletRequest, "'servletRequest' must not be null");
71+
Assert.notNull(servletRequest, "HttpServletRequest must not be null");
7272
this.servletRequest = servletRequest;
7373
}
7474

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public HierarchicalUriComponents encode(String encoding) throws UnsupportedEncod
180180
if (this.encoded) {
181181
return this;
182182
}
183-
String encodedScheme = encodeUriComponent(this.getScheme(), encoding, Type.SCHEME);
183+
String encodedScheme = encodeUriComponent(getScheme(), encoding, Type.SCHEME);
184184
String encodedUserInfo = encodeUriComponent(this.userInfo, encoding, Type.USER_INFO);
185185
String encodedHost = encodeUriComponent(this.host, encoding, getHostType());
186186

@@ -245,6 +245,7 @@ private Type getHostType() {
245245
return (this.host != null && this.host.startsWith("[")) ? Type.HOST_IPV6 : Type.HOST_IPV4;
246246
}
247247

248+
248249
// verifying
249250

250251
/**
@@ -257,8 +258,8 @@ private void verify() {
257258
return;
258259
}
259260
verifyUriComponent(getScheme(), Type.SCHEME);
260-
verifyUriComponent(userInfo, Type.USER_INFO);
261-
verifyUriComponent(host, getHostType());
261+
verifyUriComponent(this.userInfo, Type.USER_INFO);
262+
verifyUriComponent(this.host, getHostType());
262263
this.path.verify();
263264
for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
264265
verifyUriComponent(entry.getKey(), Type.QUERY_PARAM);
@@ -304,7 +305,7 @@ else if (!type.isAllowed(ch)) {
304305
@Override
305306
protected HierarchicalUriComponents expandInternal(UriTemplateVariables uriVariables) {
306307
Assert.state(!this.encoded, "Cannot expand an already encoded UriComponents object");
307-
String expandedScheme = expandUriComponent(this.getScheme(), uriVariables);
308+
String expandedScheme = expandUriComponent(getScheme(), uriVariables);
308309
String expandedUserInfo = expandUriComponent(this.userInfo, uriVariables);
309310
String expandedHost = expandUriComponent(this.host, uriVariables);
310311
PathComponent expandedPath = this.path.expand(uriVariables);

spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ public class DispatcherServlet extends FrameworkServlet {
272272
/** Detect all ViewResolvers or just expect "viewResolver" bean? */
273273
private boolean detectAllViewResolvers = true;
274274

275-
/** Perform cleanup of request attributes after include request? */
276-
private boolean cleanupAfterInclude = true;
277-
278275
/** Throw a NoHandlerFoundException if no Handler was found to process this request? **/
279276
private boolean throwExceptionIfNoHandlerFound = false;
280277

278+
/** Perform cleanup of request attributes after include request? */
279+
private boolean cleanupAfterInclude = true;
280+
281281
/** MultipartResolver used by this servlet */
282282
private MultipartResolver multipartResolver;
283283

@@ -413,12 +413,11 @@ public void setDetectAllViewResolvers(boolean detectAllViewResolvers) {
413413
* Set whether to throw a NoHandlerFoundException when no Handler was found for this request.
414414
* This exception can then be caught with a HandlerExceptionResolver or an
415415
* {@code @ExceptionHandler} controller method.
416-
* <p>Note that if
417-
* {@link org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler}
418-
* is used, then requests will always be forwarded to the default servlet and
419-
* a NoHandlerFoundException would never be thrown in that case.
420-
* <p>Default is "false", meaning the DispatcherServlet sends a NOT_FOUND error
421-
* through the Servlet response.
416+
* <p>Note that if {@link org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler}
417+
* is used, then requests will always be forwarded to the default servlet and a
418+
* NoHandlerFoundException would never be thrown in that case.
419+
* <p>Default is "false", meaning the DispatcherServlet sends a NOT_FOUND error through the
420+
* Servlet response.
422421
* @since 4.0
423422
*/
424423
public void setThrowExceptionIfNoHandlerFound(boolean throwExceptionIfNoHandlerFound) {
@@ -1111,10 +1110,10 @@ protected void noHandlerFound(HttpServletRequest request, HttpServletResponse re
11111110
pageNotFoundLogger.warn("No mapping found for HTTP request with URI [" + getRequestUri(request) +
11121111
"] in DispatcherServlet with name '" + getServletName() + "'");
11131112
}
1114-
if (throwExceptionIfNoHandlerFound) {
1115-
ServletServerHttpRequest req = new ServletServerHttpRequest(request);
1116-
throw new NoHandlerFoundException(req.getMethod().name(),
1117-
req.getServletRequest().getRequestURI(),req.getHeaders());
1113+
if (this.throwExceptionIfNoHandlerFound) {
1114+
ServletServerHttpRequest sshr = new ServletServerHttpRequest(request);
1115+
throw new NoHandlerFoundException(
1116+
sshr.getMethod().name(), sshr.getServletRequest().getRequestURI(), sshr.getHeaders());
11181117
}
11191118
else {
11201119
response.sendError(HttpServletResponse.SC_NOT_FOUND);

0 commit comments

Comments
 (0)