diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResourcePatternResolver.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResourcePatternResolver.java index 378bd8e6e5..e33a0928a7 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResourcePatternResolver.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResourcePatternResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,8 @@ import org.springframework.util.StringUtils; /** * ServletContext-aware subclass of {@link PathMatchingResourcePatternResolver}, * able to find matching resources below the web application root directory - * via Servlet 2.3's {@code ServletContext.getResourcePaths}. - * Falls back to the superclass' file system checking for other resources. + * via {@link ServletContext#getResourcePaths}. Falls back to the superclass' + * file system checking for other resources. * * @author Juergen Hoeller * @since 1.1.2 @@ -160,15 +160,20 @@ public class ServletContextResourcePatternResolver extends PathMatchingResourceP } try { JarFile jarFile = new JarFile(jarFilePath); - for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) { - JarEntry entry = entries.nextElement(); - String entryPath = entry.getName(); - if (getPathMatcher().match(entryPattern, entryPath)) { - result.add(new UrlResource( - ResourceUtils.URL_PROTOCOL_JAR, - ResourceUtils.FILE_URL_PREFIX + jarFilePath + ResourceUtils.JAR_URL_SEPARATOR + entryPath)); + try { + for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) { + JarEntry entry = entries.nextElement(); + String entryPath = entry.getName(); + if (getPathMatcher().match(entryPattern, entryPath)) { + result.add(new UrlResource( + ResourceUtils.URL_PROTOCOL_JAR, + ResourceUtils.FILE_URL_PREFIX + jarFilePath + ResourceUtils.JAR_URL_SEPARATOR + entryPath)); + } } } + finally { + jarFile.close(); + } } catch (IOException ex) { if (logger.isWarnEnabled()) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index 62df58a0ea..cae3fabaae 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,73 +59,89 @@ import org.springframework.web.util.NestedServletException; import org.springframework.web.util.WebUtils; /** - * Central dispatcher for HTTP request handlers/controllers, e.g. for web UI controllers or HTTP-based remote service - * exporters. Dispatches to registered handlers for processing a web request, providing convenient mapping and exception - * handling facilities. + * Central dispatcher for HTTP request handlers/controllers, e.g. for web UI controllers + * or HTTP-based remote service exporters. Dispatches to registered handlers for processing + * a web request, providing convenient mapping and exception handling facilities. * - *

This servlet is very flexible: It can be used with just about any workflow, with the installation of the - * appropriate adapter classes. It offers the following functionality that distinguishes it from other request-driven - * web MVC frameworks: + *

This servlet is very flexible: It can be used with just about any workflow, with the + * installation of the appropriate adapter classes. It offers the following functionality + * that distinguishes it from other request-driven web MVC frameworks: * - *

* - *

NOTE: The {@code @RequestMapping} annotation will only be processed if a corresponding - * {@code HandlerMapping} (for type level annotations) and/or {@code HandlerAdapter} (for method level - * annotations) is present in the dispatcher. This is the case by default. However, if you are defining custom - * {@code HandlerMappings} or {@code HandlerAdapters}, then you need to make sure that a corresponding custom - * {@code DefaultAnnotationHandlerMapping} and/or {@code AnnotationMethodHandlerAdapter} is defined as well - - * provided that you intend to use {@code @RequestMapping}. + *

NOTE: The {@code @RequestMapping} annotation will only be processed if a + * corresponding {@code HandlerMapping} (for type-level annotations) and/or + * {@code HandlerAdapter} (for method-level annotations) is present in the dispatcher. + * This is the case by default. However, if you are defining custom {@code HandlerMappings} + * or {@code HandlerAdapters}, then you need to make sure that a corresponding custom + * {@code DefaultAnnotationHandlerMapping} and/or {@code AnnotationMethodHandlerAdapter} + * is defined as well - provided that you intend to use {@code @RequestMapping}. * - *

A web application can define any number of DispatcherServlets. Each servlet will operate in its own - * namespace, loading its own application context with mappings, handlers, etc. Only the root application context as - * loaded by {@link org.springframework.web.context.ContextLoaderListener}, if any, will be shared. + *

A web application can define any number of DispatcherServlets. + * Each servlet will operate in its own namespace, loading its own application context + * with mappings, handlers, etc. Only the root application context as loaded by + * {@link org.springframework.web.context.ContextLoaderListener}, if any, will be shared. * *

As of Spring 3.1, {@code DispatcherServlet} may now be injected with a web * application context, rather than creating its own internally. This is useful in Servlet - * 3.0+ environments, which support programmatic registration of servlet instances. See - * {@link #DispatcherServlet(WebApplicationContext)} Javadoc for details. + * 3.0+ environments, which support programmatic registration of servlet instances. + * See the {@link #DispatcherServlet(WebApplicationContext)} javadoc for details. * * @author Rod Johnson * @author Juergen Hoeller @@ -851,12 +867,11 @@ public class DispatcherServlet extends FrameworkServlet { doDispatch(request, response); } finally { - if (WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) { - return; - } - // Restore the original attribute snapshot, in case of an include. - if (attributesSnapshot != null) { - restoreAttributesAfterInclude(request, attributesSnapshot); + if (!WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) { + // Restore the original attribute snapshot, in case of an include. + if (attributesSnapshot != null) { + restoreAttributesAfterInclude(request, attributesSnapshot); + } } } } @@ -885,7 +900,7 @@ public class DispatcherServlet extends FrameworkServlet { try { processedRequest = checkMultipart(request); - multipartRequestParsed = processedRequest != request; + multipartRequestParsed = (processedRequest != request); // Determine handler for the current request. mappedHandler = getHandler(processedRequest, false); @@ -914,14 +929,11 @@ public class DispatcherServlet extends FrameworkServlet { return; } - try { - // Actually invoke the handler. - mv = ha.handle(processedRequest, response, mappedHandler.getHandler()); - } - finally { - if (asyncManager.isConcurrentHandlingStarted()) { - return; - } + // Actually invoke the handler. + mv = ha.handle(processedRequest, response, mappedHandler.getHandler()); + + if (asyncManager.isConcurrentHandlingStarted()) { + return; } applyDefaultViewName(request, mv); @@ -941,12 +953,15 @@ public class DispatcherServlet extends FrameworkServlet { finally { if (asyncManager.isConcurrentHandlingStarted()) { // Instead of postHandle and afterCompletion - mappedHandler.applyAfterConcurrentHandlingStarted(processedRequest, response); - return; + if (mappedHandler != null) { + mappedHandler.applyAfterConcurrentHandlingStarted(processedRequest, response); + } } - // Clean up any resources used by a multipart request. - if (multipartRequestParsed) { - cleanupMultipart(processedRequest); + else { + // Clean up any resources used by a multipart request. + if (multipartRequestParsed) { + cleanupMultipart(processedRequest); + } } } } @@ -1255,7 +1270,7 @@ public class DispatcherServlet extends FrameworkServlet { } private void triggerAfterCompletionWithError(HttpServletRequest request, HttpServletResponse response, - HandlerExecutionChain mappedHandler, Error error) throws Exception, ServletException { + HandlerExecutionChain mappedHandler, Error error) throws Exception { ServletException ex = new NestedServletException("Handler processing failed", error); if (mappedHandler != null) {