@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -71,14 +71,11 @@ import org.springframework.web.util.WebUtils;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.2
|
||||
*
|
||||
* @see #handleException(Exception, WebRequest)
|
||||
* @see org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
|
||||
*/
|
||||
public abstract class ResponseEntityExceptionHandler {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
/**
|
||||
* Log category to use when no mapped handler is found for a request.
|
||||
* @see #pageNotFoundLogger
|
||||
@@ -86,11 +83,16 @@ public abstract class ResponseEntityExceptionHandler {
|
||||
public static final String PAGE_NOT_FOUND_LOG_CATEGORY = "org.springframework.web.servlet.PageNotFound";
|
||||
|
||||
/**
|
||||
* Additional logger to use when no mapped handler is found for a request.
|
||||
* Specific logger to use when no mapped handler is found for a request.
|
||||
* @see #PAGE_NOT_FOUND_LOG_CATEGORY
|
||||
*/
|
||||
protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY);
|
||||
|
||||
/**
|
||||
* Common logger for use in subclasses.
|
||||
*/
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
/**
|
||||
* Provides handling for standard Spring MVC exceptions.
|
||||
@@ -115,9 +117,7 @@ public abstract class ResponseEntityExceptionHandler {
|
||||
NoHandlerFoundException.class
|
||||
})
|
||||
public final ResponseEntity<Object> handleException(Exception ex, WebRequest request) {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
if (ex instanceof NoSuchRequestHandlingMethodException) {
|
||||
HttpStatus status = HttpStatus.NOT_FOUND;
|
||||
return handleNoSuchRequestHandlingMethod((NoSuchRequestHandlingMethodException) ex, headers, status, request);
|
||||
@@ -202,7 +202,6 @@ public abstract class ResponseEntityExceptionHandler {
|
||||
if (HttpStatus.INTERNAL_SERVER_ERROR.equals(status)) {
|
||||
request.setAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE, ex, WebRequest.SCOPE_REQUEST);
|
||||
}
|
||||
|
||||
return new ResponseEntity<Object>(body, headers, status);
|
||||
}
|
||||
|
||||
@@ -242,7 +241,6 @@ public abstract class ResponseEntityExceptionHandler {
|
||||
if (!supportedMethods.isEmpty()) {
|
||||
headers.setAllow(supportedMethods);
|
||||
}
|
||||
|
||||
return handleExceptionInternal(ex, null, headers, status, request);
|
||||
}
|
||||
|
||||
@@ -443,8 +441,8 @@ public abstract class ResponseEntityExceptionHandler {
|
||||
* @return a {@code ResponseEntity} instance
|
||||
* @since 4.0
|
||||
*/
|
||||
protected ResponseEntity<Object> handleNoHandlerFoundException(NoHandlerFoundException ex, HttpHeaders headers,
|
||||
HttpStatus status, WebRequest request) {
|
||||
protected ResponseEntity<Object> handleNoHandlerFoundException(
|
||||
NoHandlerFoundException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
|
||||
|
||||
return handleExceptionInternal(ex, null, headers, status, request);
|
||||
}
|
||||
|
||||
@@ -187,17 +187,15 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for a {@link org.springframework.web.servlet.resource.PathResourceResolver}
|
||||
* among the {@link #getResourceResolvers() resource resolvers} and configure
|
||||
* its {@code "allowedLocations"} to match the value of the
|
||||
* {@link #setLocations(java.util.List) locations} property unless the "allowed
|
||||
* locations" of the {@code PathResourceResolver} is non-empty.
|
||||
* Look for a {@code PathResourceResolver} among the configured resource
|
||||
* resolvers and set its {@code allowedLocations} property (if empty) to
|
||||
* match the {@link #setLocations locations} configured on this class.
|
||||
*/
|
||||
protected void initAllowedLocations() {
|
||||
if (CollectionUtils.isEmpty(this.locations)) {
|
||||
return;
|
||||
}
|
||||
for (int i = getResourceResolvers().size()-1; i >= 0; i--) {
|
||||
for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
|
||||
if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
|
||||
PathResourceResolver pathResolver = (PathResourceResolver) getResourceResolvers().get(i);
|
||||
if (ObjectUtils.isEmpty(pathResolver.getAllowedLocations())) {
|
||||
@@ -245,7 +243,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
||||
// Apply cache settings, if any
|
||||
prepareResponse(response);
|
||||
|
||||
// Check the resource's media type
|
||||
// Check the media type for the resource
|
||||
MediaType mediaType = getMediaType(resource);
|
||||
if (mediaType != null) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
|
||||
Reference in New Issue
Block a user