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.
56
56
import org .springframework .web .multipart .MultipartHttpServletRequest ;
57
57
import org .springframework .web .multipart .MultipartResolver ;
58
58
import org .springframework .web .util .NestedServletException ;
59
- import org .springframework .web .util .UrlPathHelper ;
60
59
import org .springframework .web .util .WebUtils ;
61
60
62
61
/**
@@ -245,8 +244,6 @@ public class DispatcherServlet extends FrameworkServlet {
245
244
/** Additional logger to use when no mapped handler is found for a request. */
246
245
protected static final Log pageNotFoundLogger = LogFactory .getLog (PAGE_NOT_FOUND_LOG_CATEGORY );
247
246
248
- private static final UrlPathHelper urlPathHelper = new UrlPathHelper ();
249
-
250
247
private static final Properties defaultStrategies ;
251
248
252
249
static {
@@ -818,17 +815,15 @@ protected Object createDefaultStrategy(ApplicationContext context, Class<?> claz
818
815
@ Override
819
816
protected void doService (HttpServletRequest request , HttpServletResponse response ) throws Exception {
820
817
if (logger .isDebugEnabled ()) {
821
- String requestUri = urlPathHelper .getRequestUri (request );
822
818
String resumed = WebAsyncUtils .getAsyncManager (request ).hasConcurrentResult () ? " resumed" : "" ;
823
819
logger .debug ("DispatcherServlet with name '" + getServletName () + "'" + resumed +
824
- " processing " + request .getMethod () + " request for [" + requestUri + "]" );
820
+ " processing " + request .getMethod () + " request for [" + getRequestUri ( request ) + "]" );
825
821
}
826
822
827
823
// Keep a snapshot of the request attributes in case of an include,
828
824
// to be able to restore the original attributes after the include.
829
825
Map <String , Object > attributesSnapshot = null ;
830
826
if (WebUtils .isIncludeRequest (request )) {
831
- logger .debug ("Taking snapshot of request attributes before include" );
832
827
attributesSnapshot = new HashMap <String , Object >();
833
828
Enumeration <?> attrNames = request .getAttributeNames ();
834
829
while (attrNames .hasMoreElements ()) {
@@ -908,8 +903,7 @@ protected void doDispatch(HttpServletRequest request, HttpServletResponse respon
908
903
if (isGet || "HEAD" .equals (method )) {
909
904
long lastModified = ha .getLastModified (request , mappedHandler .getHandler ());
910
905
if (logger .isDebugEnabled ()) {
911
- String requestUri = urlPathHelper .getRequestUri (request );
912
- logger .debug ("Last-Modified value for [" + requestUri + "] is: " + lastModified );
906
+ logger .debug ("Last-Modified value for [" + getRequestUri (request ) + "] is: " + lastModified );
913
907
}
914
908
if (new ServletWebRequest (request , response ).checkNotModified (lastModified ) && isGet ) {
915
909
return ;
@@ -1104,8 +1098,7 @@ protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Ex
1104
1098
*/
1105
1099
protected void noHandlerFound (HttpServletRequest request , HttpServletResponse response ) throws Exception {
1106
1100
if (pageNotFoundLogger .isWarnEnabled ()) {
1107
- String requestUri = urlPathHelper .getRequestUri (request );
1108
- pageNotFoundLogger .warn ("No mapping found for HTTP request with URI [" + requestUri +
1101
+ pageNotFoundLogger .warn ("No mapping found for HTTP request with URI [" + getRequestUri (request ) +
1109
1102
"] in DispatcherServlet with name '" + getServletName () + "'" );
1110
1103
}
1111
1104
response .sendError (HttpServletResponse .SC_NOT_FOUND );
@@ -1187,9 +1180,8 @@ protected void render(ModelAndView mv, HttpServletRequest request, HttpServletRe
1187
1180
// We need to resolve the view name.
1188
1181
view = resolveViewName (mv .getViewName (), mv .getModelInternal (), locale , request );
1189
1182
if (view == null ) {
1190
- throw new ServletException (
1191
- "Could not resolve view with name '" + mv .getViewName () + "' in servlet with name '" +
1192
- getServletName () + "'" );
1183
+ throw new ServletException ("Could not resolve view with name '" + mv .getViewName () +
1184
+ "' in servlet with name '" + getServletName () + "'" );
1193
1185
}
1194
1186
}
1195
1187
else {
@@ -1205,7 +1197,16 @@ protected void render(ModelAndView mv, HttpServletRequest request, HttpServletRe
1205
1197
if (logger .isDebugEnabled ()) {
1206
1198
logger .debug ("Rendering view [" + view + "] in DispatcherServlet with name '" + getServletName () + "'" );
1207
1199
}
1208
- view .render (mv .getModelInternal (), request , response );
1200
+ try {
1201
+ view .render (mv .getModelInternal (), request , response );
1202
+ }
1203
+ catch (Exception ex ) {
1204
+ if (logger .isDebugEnabled ()) {
1205
+ logger .debug ("Error rendering view [" + view + "] in DispatcherServlet with name '" +
1206
+ getServletName () + "'" , ex );
1207
+ }
1208
+ throw ex ;
1209
+ }
1209
1210
}
1210
1211
1211
1212
/**
@@ -1270,8 +1271,6 @@ private void triggerAfterCompletionWithError(HttpServletRequest request, HttpSer
1270
1271
*/
1271
1272
@ SuppressWarnings ("unchecked" )
1272
1273
private void restoreAttributesAfterInclude (HttpServletRequest request , Map <?,?> attributesSnapshot ) {
1273
- logger .debug ("Restoring snapshot of request attributes after include" );
1274
-
1275
1274
// Need to copy into separate Collection here, to avoid side effects
1276
1275
// on the Enumeration when removing attributes.
1277
1276
Set <String > attrsToCheck = new HashSet <String >();
@@ -1291,18 +1290,20 @@ private void restoreAttributesAfterInclude(HttpServletRequest request, Map<?,?>
1291
1290
for (String attrName : attrsToCheck ) {
1292
1291
Object attrValue = attributesSnapshot .get (attrName );
1293
1292
if (attrValue == null ){
1294
- if (logger .isDebugEnabled ()) {
1295
- logger .debug ("Removing attribute [" + attrName + "] after include" );
1296
- }
1297
1293
request .removeAttribute (attrName );
1298
1294
}
1299
1295
else if (attrValue != request .getAttribute (attrName )) {
1300
- if (logger .isDebugEnabled ()) {
1301
- logger .debug ("Restoring original value of attribute [" + attrName + "] after include" );
1302
- }
1303
1296
request .setAttribute (attrName , attrValue );
1304
1297
}
1305
1298
}
1306
1299
}
1307
1300
1301
+ private static String getRequestUri (HttpServletRequest request ) {
1302
+ String uri = (String ) request .getAttribute (WebUtils .INCLUDE_REQUEST_URI_ATTRIBUTE );
1303
+ if (uri == null ) {
1304
+ uri = request .getRequestURI ();
1305
+ }
1306
+ return uri ;
1307
+ }
1308
+
1308
1309
}
0 commit comments