Sync with 3.1.x
* 3.1.x: (61 commits) Compensate for changes in JDK 7 Introspector Avoid 'type mismatch' errors in ExtendedBeanInfo Polish ExtendedBeanInfo and tests Infer AnnotationAttributes method return types Minor fix in MVC reference doc chapter Hibernate 4.1 etc TypeDescriptor equals implementation accepts annotations in any order "setBasenames" uses varargs now (for programmatic setup; SPR-9106) @ActiveProfiles mechanism works with @ImportResource as well (SPR-8992 polishing clarified Resource's "getFilename" method to consistently return null substituteNamedParameters detects and unwraps SqlParameterValue object Replace spaces with tabs Consider security in ClassUtils#getMostSpecificMethod Adding null check for username being null. Improvements for registering custom SQL exception translators in app c SPR-7680 Adding QueryTimeoutException to the DataAccessException hiera Minor polish in WebMvcConfigurationSupport Detect overridden boolean getters in ExtendedBeanInfo Polish ExtendedBeanInfoTests ...
This commit is contained in:
@@ -840,14 +840,14 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||
request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
|
||||
request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
|
||||
request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource());
|
||||
|
||||
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response);
|
||||
if (inputFlashMap != null) {
|
||||
request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap));
|
||||
}
|
||||
request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
|
||||
request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager);
|
||||
|
||||
Map<String, ?> flashMap = this.flashMapManager.getFlashMapForRequest(request);
|
||||
if (flashMap != null) {
|
||||
request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, flashMap);
|
||||
}
|
||||
|
||||
try {
|
||||
doDispatch(request, response);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -32,12 +32,11 @@ import org.springframework.util.StringUtils;
|
||||
* <p>A FlashMap can be set up with a request path and request parameters to
|
||||
* help identify the target request. Without this information, a FlashMap is
|
||||
* made available to the next request, which may or may not be the intended
|
||||
* recipient. On a redirect, the target URL is known and for example
|
||||
* {@code org.springframework.web.servlet.view.RedirectView} has the
|
||||
* opportunity to automatically update the current FlashMap with target
|
||||
* URL information.
|
||||
* recipient. On a redirect, the target URL is known and a FlashMap can be
|
||||
* updated with that information. This is done automatically when the
|
||||
* {@code org.springframework.web.servlet.view.RedirectView} is used.
|
||||
*
|
||||
* <p>Annotated controllers will usually not use this type directly.
|
||||
* <p>Note: annotated controllers will usually not use FlashMap directly.
|
||||
* See {@code org.springframework.web.servlet.mvc.support.RedirectAttributes}
|
||||
* for an overview of using flash attributes in annotated controllers.
|
||||
*
|
||||
@@ -58,25 +57,6 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
|
||||
|
||||
private int timeToLive;
|
||||
|
||||
private final int createdBy;
|
||||
|
||||
/**
|
||||
* Create a new instance with an id uniquely identifying the creator of
|
||||
* this FlashMap.
|
||||
* @param createdBy identifies the FlashMapManager instance that created
|
||||
* and will manage this FlashMap instance (e.g. via a hashCode)
|
||||
*/
|
||||
public FlashMap(int createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public FlashMap() {
|
||||
this.createdBy = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a URL path to help identify the target request for this FlashMap.
|
||||
* The path may be absolute (e.g. /application/resource) or relative to the
|
||||
@@ -96,7 +76,6 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
|
||||
|
||||
/**
|
||||
* Provide request parameters identifying the request for this FlashMap.
|
||||
* Null or empty keys and values are skipped.
|
||||
* @param params a Map with the names and values of expected parameters.
|
||||
*/
|
||||
public FlashMap addTargetRequestParams(MultiValueMap<String, String> params) {
|
||||
@@ -112,8 +91,8 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
|
||||
|
||||
/**
|
||||
* Provide a request parameter identifying the request for this FlashMap.
|
||||
* @param name the expected parameter name, skipped if {@code null}
|
||||
* @param value the expected parameter value, skipped if {@code null}
|
||||
* @param name the expected parameter name, skipped if empty or {@code null}
|
||||
* @param value the expected value, skipped if empty or {@code null}
|
||||
*/
|
||||
public FlashMap addTargetRequestParam(String name, String value) {
|
||||
if (StringUtils.hasText(name) && StringUtils.hasText(value)) {
|
||||
@@ -151,13 +130,6 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the given id matches the id of the creator of this FlashMap.
|
||||
*/
|
||||
public boolean isCreatedBy(int createdBy) {
|
||||
return this.createdBy == createdBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two FlashMaps and prefer the one that specifies a target URL
|
||||
* path or has more target URL parameters. Before comparing FlashMap
|
||||
|
||||
@@ -16,44 +16,43 @@
|
||||
|
||||
package org.springframework.web.servlet;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* A strategy interface for retrieving and saving FlashMap instances.
|
||||
* See {@link FlashMap} for a general overview of flash attributes.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
*
|
||||
*
|
||||
* @see FlashMap
|
||||
*/
|
||||
public interface FlashMapManager {
|
||||
|
||||
/**
|
||||
* Get a Map with flash attributes saved by a previous request.
|
||||
* See {@link FlashMap} for details on how FlashMap instances
|
||||
* identifies the target requests they're saved for.
|
||||
* If found, the Map is removed from the underlying storage.
|
||||
* Find a FlashMap saved by a previous request that matches to the current
|
||||
* request, remove it from underlying storage, and also remove other
|
||||
* expired FlashMap instances.
|
||||
* <p>This method is invoked in the beginning of every request in contrast
|
||||
* to {@link #saveOutputFlashMap}, which is invoked only when there are
|
||||
* flash attributes to be saved - i.e. before a redirect.
|
||||
* @param request the current request
|
||||
* @return a read-only Map with flash attributes or {@code null}
|
||||
* @param response the current response
|
||||
* @return a FlashMap matching the current request or {@code null}
|
||||
*/
|
||||
Map<String, ?> getFlashMapForRequest(HttpServletRequest request);
|
||||
FlashMap retrieveAndUpdate(HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* Save the given FlashMap, in some underlying storage, mark the beginning
|
||||
* of its expiration period, and remove other expired FlashMap instances.
|
||||
* The method has no impact if the FlashMap is empty and there are no
|
||||
* expired FlashMap instances to be removed.
|
||||
* Save the given FlashMap, in some underlying storage and set the start
|
||||
* of its expiration period.
|
||||
* <p><strong>Note:</strong> Invoke this method prior to a redirect in order
|
||||
* to allow saving the FlashMap in the HTTP session or perhaps in a response
|
||||
* to allow saving the FlashMap in the HTTP session or in a response
|
||||
* cookie before the response is committed.
|
||||
* @param flashMap the FlashMap to save
|
||||
* @param request the current request
|
||||
* @param response the current response
|
||||
*/
|
||||
void save(FlashMap flashMap, HttpServletRequest request, HttpServletResponse response);
|
||||
void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolv
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
*/
|
||||
public abstract class WebMvcConfigurationSupport implements ApplicationContextAware, ServletContextAware {
|
||||
public class WebMvcConfigurationSupport implements ApplicationContextAware, ServletContextAware {
|
||||
|
||||
private ServletContext servletContext;
|
||||
|
||||
@@ -419,9 +419,9 @@ public abstract class WebMvcConfigurationSupport implements ApplicationContextAw
|
||||
String className = "org.springframework.validation.beanvalidation.LocalValidatorFactoryBean";
|
||||
clazz = ClassUtils.forName(className, WebMvcConfigurationSupport.class.getClassLoader());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new BeanInitializationException("Could not find default validator");
|
||||
throw new BeanInitializationException("Could not find default validator", e);
|
||||
} catch (LinkageError e) {
|
||||
throw new BeanInitializationException("Could not find default validator");
|
||||
throw new BeanInitializationException("Could not find default validator", e);
|
||||
}
|
||||
validator = (Validator) BeanUtils.instantiate(clazz);
|
||||
}
|
||||
@@ -474,7 +474,7 @@ public abstract class WebMvcConfigurationSupport implements ApplicationContextAw
|
||||
* providing a list of resolvers.
|
||||
*/
|
||||
@Bean
|
||||
public HandlerExceptionResolver handlerExceptionResolver() throws Exception {
|
||||
public HandlerExceptionResolver handlerExceptionResolver() {
|
||||
List<HandlerExceptionResolver> exceptionResolvers = new ArrayList<HandlerExceptionResolver>();
|
||||
configureHandlerExceptionResolvers(exceptionResolvers);
|
||||
|
||||
|
||||
@@ -110,9 +110,7 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
|
||||
NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
|
||||
if (!isMultipartRequest(servletRequest)) {
|
||||
throw new MultipartException("The current request is not a multipart request");
|
||||
}
|
||||
assertIsMultipartRequest(servletRequest);
|
||||
|
||||
MultipartHttpServletRequest multipartRequest =
|
||||
WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
|
||||
@@ -166,12 +164,11 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
|
||||
return arg;
|
||||
}
|
||||
|
||||
private boolean isMultipartRequest(HttpServletRequest request) {
|
||||
if (!"post".equals(request.getMethod().toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
private static void assertIsMultipartRequest(HttpServletRequest request) {
|
||||
String contentType = request.getContentType();
|
||||
return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
|
||||
if (contentType == null || !contentType.toLowerCase().startsWith("multipart/")) {
|
||||
throw new MultipartException("The current request is not a multipart request");
|
||||
}
|
||||
}
|
||||
|
||||
private String getPartName(MethodParameter parameter) {
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.web.servlet.support;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -50,6 +49,8 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
|
||||
private UrlPathHelper urlPathHelper = new UrlPathHelper();
|
||||
|
||||
private static final Object writeLock = new Object();
|
||||
|
||||
/**
|
||||
* Set the amount of time in seconds after a {@link FlashMap} is saved
|
||||
* (at request completion) and before it expires.
|
||||
@@ -81,34 +82,30 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
return this.urlPathHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>Does not cause an HTTP session to be created.
|
||||
*/
|
||||
public final Map<String, ?> getFlashMapForRequest(HttpServletRequest request) {
|
||||
List<FlashMap> flashMaps = retrieveFlashMaps(request);
|
||||
if (CollectionUtils.isEmpty(flashMaps)) {
|
||||
public final FlashMap retrieveAndUpdate(HttpServletRequest request, HttpServletResponse response) {
|
||||
List<FlashMap> allMaps = retrieveFlashMaps(request);
|
||||
if (CollectionUtils.isEmpty(allMaps)) {
|
||||
return null;
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Retrieved FlashMap(s): " + flashMaps);
|
||||
logger.debug("Retrieved FlashMap(s): " + allMaps);
|
||||
}
|
||||
List<FlashMap> result = new ArrayList<FlashMap>();
|
||||
for (FlashMap flashMap : flashMaps) {
|
||||
if (isFlashMapForRequest(flashMap, request)) {
|
||||
result.add(flashMap);
|
||||
}
|
||||
List<FlashMap> mapsToRemove = getExpiredFlashMaps(allMaps);
|
||||
FlashMap match = getMatchingFlashMap(allMaps, request);
|
||||
if (match != null) {
|
||||
mapsToRemove.add(match);
|
||||
}
|
||||
if (!result.isEmpty()) {
|
||||
Collections.sort(result);
|
||||
if (!mapsToRemove.isEmpty()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Found matching FlashMap(s): " + result);
|
||||
logger.debug("Removing FlashMap(s): " + allMaps);
|
||||
}
|
||||
synchronized (writeLock) {
|
||||
allMaps = retrieveFlashMaps(request);
|
||||
allMaps.removeAll(mapsToRemove);
|
||||
updateFlashMaps(allMaps, request, response);
|
||||
}
|
||||
FlashMap match = result.remove(0);
|
||||
flashMaps.remove(match);
|
||||
return Collections.unmodifiableMap(match);
|
||||
}
|
||||
return null;
|
||||
return match;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,10 +115,44 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
*/
|
||||
protected abstract List<FlashMap> retrieveFlashMaps(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Return a list of expired FlashMap instances contained in the given list.
|
||||
*/
|
||||
private List<FlashMap> getExpiredFlashMaps(List<FlashMap> allMaps) {
|
||||
List<FlashMap> result = new ArrayList<FlashMap>();
|
||||
for (FlashMap map : allMaps) {
|
||||
if (map.isExpired()) {
|
||||
result.add(map);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a FlashMap contained in the given list that matches the request.
|
||||
* @return a matching FlashMap or {@code null}
|
||||
*/
|
||||
private FlashMap getMatchingFlashMap(List<FlashMap> allMaps, HttpServletRequest request) {
|
||||
List<FlashMap> result = new ArrayList<FlashMap>();
|
||||
for (FlashMap flashMap : allMaps) {
|
||||
if (isFlashMapForRequest(flashMap, request)) {
|
||||
result.add(flashMap);
|
||||
}
|
||||
}
|
||||
if (!result.isEmpty()) {
|
||||
Collections.sort(result);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Found matching FlashMap(s): " + result);
|
||||
}
|
||||
return result.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the given FlashMap matches the current request.
|
||||
* The default implementation uses the target request path and query params
|
||||
* saved in the FlashMap.
|
||||
* The default implementation uses the target request path and query
|
||||
* parameters saved in the FlashMap.
|
||||
*/
|
||||
protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request) {
|
||||
if (flashMap.getTargetRequestPath() != null) {
|
||||
@@ -142,37 +173,21 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>The FlashMap, if not empty, is saved to the HTTP session.
|
||||
*/
|
||||
public final void save(FlashMap flashMap, HttpServletRequest request, HttpServletResponse response) {
|
||||
Assert.notNull(flashMap, "FlashMap must not be null");
|
||||
|
||||
List<FlashMap> flashMaps = retrieveFlashMaps(request);
|
||||
if (flashMap.isEmpty() && (flashMaps == null)) {
|
||||
public final void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest request, HttpServletResponse response) {
|
||||
if (CollectionUtils.isEmpty(flashMap)) {
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
boolean update = false;
|
||||
flashMaps = retrieveFlashMaps(request);
|
||||
if (!CollectionUtils.isEmpty(flashMaps)) {
|
||||
update = removeExpired(flashMaps);
|
||||
}
|
||||
if (!flashMap.isEmpty()) {
|
||||
String path = decodeAndNormalizePath(flashMap.getTargetRequestPath(), request);
|
||||
flashMap.setTargetRequestPath(path);
|
||||
flashMap.startExpirationPeriod(this.flashMapTimeout);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Saving FlashMap=" + flashMap);
|
||||
}
|
||||
flashMaps = (flashMaps == null) ? new CopyOnWriteArrayList<FlashMap>() : flashMaps;
|
||||
flashMaps.add(flashMap);
|
||||
update = true;
|
||||
}
|
||||
if (update) {
|
||||
updateFlashMaps(flashMaps, request, response);
|
||||
}
|
||||
String path = decodeAndNormalizePath(flashMap.getTargetRequestPath(), request);
|
||||
flashMap.setTargetRequestPath(path);
|
||||
flashMap.startExpirationPeriod(this.flashMapTimeout);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Saving FlashMap=" + flashMap);
|
||||
}
|
||||
synchronized (writeLock) {
|
||||
List<FlashMap> allMaps = retrieveFlashMaps(request);
|
||||
allMaps = (allMaps == null) ? new CopyOnWriteArrayList<FlashMap>() : allMaps;
|
||||
allMaps.add(flashMap);
|
||||
updateFlashMaps(allMaps, request, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,25 +212,4 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
|
||||
protected abstract void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request,
|
||||
HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* Remove expired FlashMap instances from the given List.
|
||||
*/
|
||||
protected boolean removeExpired(List<FlashMap> flashMaps) {
|
||||
List<FlashMap> expired = new ArrayList<FlashMap>();
|
||||
for (FlashMap flashMap : flashMaps) {
|
||||
if (flashMap.isExpired()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Removing expired FlashMap: " + flashMap);
|
||||
}
|
||||
expired.add(flashMap);
|
||||
}
|
||||
}
|
||||
if (expired.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return flashMaps.removeAll(expired);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,13 +23,11 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
/**
|
||||
* A builder for {@link UriComponents} that offers static factory methods to
|
||||
* extract information from an {@code HttpServletRequest}.
|
||||
* A UriComponentsBuilder that extracts information from an HttpServletRequest.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
@@ -50,24 +48,25 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a builder initialized with the host, port, scheme, and the
|
||||
* context path of the given request.
|
||||
* Prepare a builder from the host, port, scheme, and context path of
|
||||
* an HttpServletRequest.
|
||||
*/
|
||||
public static ServletUriComponentsBuilder fromContextPath(HttpServletRequest request) {
|
||||
ServletUriComponentsBuilder builder = fromRequest(request);
|
||||
builder.replacePath(new UrlPathHelper().getContextPath(request));
|
||||
builder.replacePath(request.getContextPath());
|
||||
builder.replaceQuery(null);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a builder initialized with the host, port, scheme, context path,
|
||||
* and the servlet mapping of the given request.
|
||||
*
|
||||
* <p>For example if the servlet is mapped by name, i.e. {@code "/main/*"},
|
||||
* then the resulting path will be {@code /appContext/main}. If the servlet
|
||||
* path is not mapped by name, i.e. {@code "/"} or {@code "*.html"}, then
|
||||
* the resulting path will contain the context path only.
|
||||
* Prepare a builder from the host, port, scheme, context path, and
|
||||
* servlet mapping of an HttpServletRequest. The results may vary depending
|
||||
* on the type of servlet mapping used.
|
||||
*
|
||||
* <p>If the servlet is mapped by name, e.g. {@code "/main/*"}, the path
|
||||
* will end with "/main". If the servlet is mapped otherwise, e.g.
|
||||
* {@code "/"} or {@code "*.do"}, the result will be the same as
|
||||
* if calling {@link #fromContextPath(HttpServletRequest)}.
|
||||
*/
|
||||
public static ServletUriComponentsBuilder fromServletMapping(HttpServletRequest request) {
|
||||
ServletUriComponentsBuilder builder = fromContextPath(request);
|
||||
@@ -78,8 +77,19 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a builder initialized with all available information in the given
|
||||
* request including scheme, host, port, path, and query string.
|
||||
* Prepare a builder from the host, port, scheme, and path of
|
||||
* an HttpSevletRequest.
|
||||
*/
|
||||
public static ServletUriComponentsBuilder fromRequestUri(HttpServletRequest request) {
|
||||
ServletUriComponentsBuilder builder = fromRequest(request);
|
||||
builder.replacePath(request.getRequestURI());
|
||||
builder.replaceQuery(null);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a builder by copying the scheme, host, port, path, and
|
||||
* query string of an HttpServletRequest.
|
||||
*/
|
||||
public static ServletUriComponentsBuilder fromRequest(HttpServletRequest request) {
|
||||
String scheme = request.getScheme();
|
||||
@@ -91,30 +101,38 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder {
|
||||
if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) {
|
||||
builder.port(port);
|
||||
}
|
||||
builder.path(new UrlPathHelper().getRequestUri(request));
|
||||
builder.path(request.getRequestURI());
|
||||
builder.query(request.getQueryString());
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Equivalent to {@link #fromContextPath(HttpServletRequest)} except the
|
||||
* request is obtained via {@link RequestContextHolder}.
|
||||
* Same as {@link #fromContextPath(HttpServletRequest)} except the
|
||||
* request is obtained through {@link RequestContextHolder}.
|
||||
*/
|
||||
public static ServletUriComponentsBuilder fromCurrentContextPath() {
|
||||
return fromContextPath(getCurrentRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent to {@link #fromServletMapping(HttpServletRequest)} except the
|
||||
* request is obtained via {@link RequestContextHolder}.
|
||||
* Same as {@link #fromServletMapping(HttpServletRequest)} except the
|
||||
* request is obtained through {@link RequestContextHolder}.
|
||||
*/
|
||||
public static ServletUriComponentsBuilder fromCurrentServletMapping() {
|
||||
return fromServletMapping(getCurrentRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent to {@link #fromRequest(HttpServletRequest)} except the
|
||||
* request is obtained via {@link RequestContextHolder}.
|
||||
* Same as {@link #fromRequestUri(HttpServletRequest)} except the
|
||||
* request is obtained through {@link RequestContextHolder}.
|
||||
*/
|
||||
public static ServletUriComponentsBuilder fromCurrentRequestUri() {
|
||||
return fromRequestUri(getCurrentRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #fromRequest(HttpServletRequest)} except the
|
||||
* request is obtained through {@link RequestContextHolder}.
|
||||
*/
|
||||
public static ServletUriComponentsBuilder fromCurrentRequest() {
|
||||
return fromRequest(getCurrentRequest());
|
||||
@@ -128,5 +146,5 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder {
|
||||
Assert.state(servletRequest != null, "Could not find current HttpServletRequest");
|
||||
return servletRequest;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import javax.servlet.http.HttpSession;
|
||||
import org.springframework.web.servlet.FlashMap;
|
||||
|
||||
/**
|
||||
* Stores {@link FlashMap} instances in the HTTP session.
|
||||
* Store and retrieve {@link FlashMap} instances to and from the HTTP session.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1.1
|
||||
@@ -35,9 +35,10 @@ public class SessionFlashMapManager extends AbstractFlashMapManager{
|
||||
private static final String FLASH_MAPS_SESSION_ATTRIBUTE = SessionFlashMapManager.class.getName() + ".FLASH_MAPS";
|
||||
|
||||
/**
|
||||
* Retrieve saved FlashMap instances from the HTTP session.
|
||||
* @param request the current request
|
||||
* @return a List with FlashMap instances or {@code null}
|
||||
* Retrieve saved FlashMap instances from the HTTP Session.
|
||||
* <p>Does not cause an HTTP session to be created but may update it if a
|
||||
* FlashMap matching the current request is found or there are expired
|
||||
* FlashMap to be removed.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<FlashMap> retrieveFlashMaps(HttpServletRequest request) {
|
||||
@@ -46,7 +47,7 @@ public class SessionFlashMapManager extends AbstractFlashMapManager{
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the given FlashMap instances in the HTTP session.
|
||||
* Save the given FlashMap instance, if not empty, in the HTTP session.
|
||||
*/
|
||||
protected void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request, HttpServletResponse response) {
|
||||
request.getSession().setAttribute(FLASH_MAPS_SESSION_ATTRIBUTE, flashMaps);
|
||||
|
||||
@@ -276,7 +276,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
|
||||
}
|
||||
|
||||
FlashMapManager flashMapManager = RequestContextUtils.getFlashMapManager(request);
|
||||
flashMapManager.save(flashMap, request, response);
|
||||
flashMapManager.saveOutputFlashMap(flashMap, request, response);
|
||||
|
||||
sendRedirect(request, response, targetUrl.toString(), this.http10Compatible);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -485,38 +485,38 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
|
||||
*/
|
||||
protected final JasperReport loadReport(Resource resource) {
|
||||
try {
|
||||
String fileName = resource.getFilename();
|
||||
if (fileName.endsWith(".jasper")) {
|
||||
// Load pre-compiled report.
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Loading pre-compiled Jasper Report from " + resource);
|
||||
String filename = resource.getFilename();
|
||||
if (filename != null) {
|
||||
if (filename.endsWith(".jasper")) {
|
||||
// Load pre-compiled report.
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Loading pre-compiled Jasper Report from " + resource);
|
||||
}
|
||||
InputStream is = resource.getInputStream();
|
||||
try {
|
||||
return (JasperReport) JRLoader.loadObject(is);
|
||||
}
|
||||
finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
InputStream is = resource.getInputStream();
|
||||
try {
|
||||
return (JasperReport) JRLoader.loadObject(is);
|
||||
}
|
||||
finally {
|
||||
is.close();
|
||||
else if (filename.endsWith(".jrxml")) {
|
||||
// Compile report on-the-fly.
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Compiling Jasper Report loaded from " + resource);
|
||||
}
|
||||
InputStream is = resource.getInputStream();
|
||||
try {
|
||||
JasperDesign design = JRXmlLoader.load(is);
|
||||
return JasperCompileManager.compileReport(design);
|
||||
}
|
||||
finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fileName.endsWith(".jrxml")) {
|
||||
// Compile report on-the-fly.
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Compiling Jasper Report loaded from " + resource);
|
||||
}
|
||||
InputStream is = resource.getInputStream();
|
||||
try {
|
||||
JasperDesign design = JRXmlLoader.load(is);
|
||||
return JasperCompileManager.compileReport(design);
|
||||
}
|
||||
finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Report filename [" + fileName + "] must end in either .jasper or .jrxml");
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"Report filename [" + filename + "] must end in either .jasper or .jrxml");
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new ApplicationContextException(
|
||||
|
||||
Reference in New Issue
Block a user