1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
57
57
import org .springframework .web .multipart .MultipartHttpServletRequest ;
58
58
import org .springframework .web .multipart .MultipartResolver ;
59
59
import org .springframework .web .util .NestedServletException ;
60
- import org .springframework .web .util .UrlPathHelper ;
61
60
import org .springframework .web .util .WebUtils ;
62
61
63
62
/**
@@ -246,8 +245,6 @@ public class DispatcherServlet extends FrameworkServlet {
246
245
/** Additional logger to use when no mapped handler is found for a request. */
247
246
protected static final Log pageNotFoundLogger = LogFactory .getLog (PAGE_NOT_FOUND_LOG_CATEGORY );
248
247
249
- private static final UrlPathHelper urlPathHelper = new UrlPathHelper ();
250
-
251
248
private static final Properties defaultStrategies ;
252
249
253
250
static {
@@ -838,17 +835,15 @@ protected Object createDefaultStrategy(ApplicationContext context, Class<?> claz
838
835
@ Override
839
836
protected void doService (HttpServletRequest request , HttpServletResponse response ) throws Exception {
840
837
if (logger .isDebugEnabled ()) {
841
- String requestUri = urlPathHelper .getRequestUri (request );
842
838
String resumed = WebAsyncUtils .getAsyncManager (request ).hasConcurrentResult () ? " resumed" : "" ;
843
839
logger .debug ("DispatcherServlet with name '" + getServletName () + "'" + resumed +
844
- " processing " + request .getMethod () + " request for [" + requestUri + "]" );
840
+ " processing " + request .getMethod () + " request for [" + getRequestUri ( request ) + "]" );
845
841
}
846
842
847
843
// Keep a snapshot of the request attributes in case of an include,
848
844
// to be able to restore the original attributes after the include.
849
845
Map <String , Object > attributesSnapshot = null ;
850
846
if (WebUtils .isIncludeRequest (request )) {
851
- logger .debug ("Taking snapshot of request attributes before include" );
852
847
attributesSnapshot = new HashMap <String , Object >();
853
848
Enumeration <?> attrNames = request .getAttributeNames ();
854
849
while (attrNames .hasMoreElements ()) {
@@ -928,8 +923,7 @@ protected void doDispatch(HttpServletRequest request, HttpServletResponse respon
928
923
if (isGet || "HEAD" .equals (method )) {
929
924
long lastModified = ha .getLastModified (request , mappedHandler .getHandler ());
930
925
if (logger .isDebugEnabled ()) {
931
- String requestUri = urlPathHelper .getRequestUri (request );
932
- logger .debug ("Last-Modified value for [" + requestUri + "] is: " + lastModified );
926
+ logger .debug ("Last-Modified value for [" + getRequestUri (request ) + "] is: " + lastModified );
933
927
}
934
928
if (new ServletWebRequest (request , response ).checkNotModified (lastModified ) && isGet ) {
935
929
return ;
@@ -1114,15 +1108,15 @@ protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Ex
1114
1108
*/
1115
1109
protected void noHandlerFound (HttpServletRequest request , HttpServletResponse response ) throws Exception {
1116
1110
if (pageNotFoundLogger .isWarnEnabled ()) {
1117
- String requestUri = urlPathHelper .getRequestUri (request );
1118
- pageNotFoundLogger .warn ("No mapping found for HTTP request with URI [" + requestUri +
1111
+ pageNotFoundLogger .warn ("No mapping found for HTTP request with URI [" + getRequestUri (request ) +
1119
1112
"] in DispatcherServlet with name '" + getServletName () + "'" );
1120
1113
}
1121
- if (throwExceptionIfNoHandlerFound ) {
1114
+ if (throwExceptionIfNoHandlerFound ) {
1122
1115
ServletServerHttpRequest req = new ServletServerHttpRequest (request );
1123
1116
throw new NoHandlerFoundException (req .getMethod ().name (),
1124
1117
req .getServletRequest ().getRequestURI (),req .getHeaders ());
1125
- } else {
1118
+ }
1119
+ else {
1126
1120
response .sendError (HttpServletResponse .SC_NOT_FOUND );
1127
1121
}
1128
1122
}
@@ -1203,9 +1197,8 @@ protected void render(ModelAndView mv, HttpServletRequest request, HttpServletRe
1203
1197
// We need to resolve the view name.
1204
1198
view = resolveViewName (mv .getViewName (), mv .getModelInternal (), locale , request );
1205
1199
if (view == null ) {
1206
- throw new ServletException (
1207
- "Could not resolve view with name '" + mv .getViewName () + "' in servlet with name '" +
1208
- getServletName () + "'" );
1200
+ throw new ServletException ("Could not resolve view with name '" + mv .getViewName () +
1201
+ "' in servlet with name '" + getServletName () + "'" );
1209
1202
}
1210
1203
}
1211
1204
else {
@@ -1226,8 +1219,8 @@ protected void render(ModelAndView mv, HttpServletRequest request, HttpServletRe
1226
1219
}
1227
1220
catch (Exception ex ) {
1228
1221
if (logger .isDebugEnabled ()) {
1229
- logger .debug ("Error rendering view [" + view + "] in DispatcherServlet with name '"
1230
- + getServletName () + "'" , ex );
1222
+ logger .debug ("Error rendering view [" + view + "] in DispatcherServlet with name '" +
1223
+ getServletName () + "'" , ex );
1231
1224
}
1232
1225
throw ex ;
1233
1226
}
@@ -1295,8 +1288,6 @@ private void triggerAfterCompletionWithError(HttpServletRequest request, HttpSer
1295
1288
*/
1296
1289
@ SuppressWarnings ("unchecked" )
1297
1290
private void restoreAttributesAfterInclude (HttpServletRequest request , Map <?,?> attributesSnapshot ) {
1298
- logger .debug ("Restoring snapshot of request attributes after include" );
1299
-
1300
1291
// Need to copy into separate Collection here, to avoid side effects
1301
1292
// on the Enumeration when removing attributes.
1302
1293
Set <String > attrsToCheck = new HashSet <String >();
@@ -1316,18 +1307,20 @@ private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?,?>
1316
1307
for (String attrName : attrsToCheck ) {
1317
1308
Object attrValue = attributesSnapshot .get (attrName );
1318
1309
if (attrValue == null ){
1319
- if (logger .isDebugEnabled ()) {
1320
- logger .debug ("Removing attribute [" + attrName + "] after include" );
1321
- }
1322
1310
request .removeAttribute (attrName );
1323
1311
}
1324
1312
else if (attrValue != request .getAttribute (attrName )) {
1325
- if (logger .isDebugEnabled ()) {
1326
- logger .debug ("Restoring original value of attribute [" + attrName + "] after include" );
1327
- }
1328
1313
request .setAttribute (attrName , attrValue );
1329
1314
}
1330
1315
}
1331
1316
}
1332
1317
1318
+ private static String getRequestUri (HttpServletRequest request ) {
1319
+ String uri = (String ) request .getAttribute (WebUtils .INCLUDE_REQUEST_URI_ATTRIBUTE );
1320
+ if (uri == null ) {
1321
+ uri = request .getRequestURI ();
1322
+ }
1323
+ return uri ;
1324
+ }
1325
+
1333
1326
}
0 commit comments