Polishing
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
||||
/**
|
||||
* Configure the {@link ResourceHttpMessageConverter} to use.
|
||||
* <p>By default a {@link ResourceHttpMessageConverter} will be configured.
|
||||
* @since 4.3.0
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setResourceHttpMessageConverter(ResourceHttpMessageConverter resourceHttpMessageConverter) {
|
||||
this.resourceHttpMessageConverter = resourceHttpMessageConverter;
|
||||
@@ -172,7 +172,6 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
||||
return this.resourceHttpMessageConverter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configure a {@code ContentNegotiationManager} to determine the media types
|
||||
* for resources being served. If the manager contains a path
|
||||
@@ -185,7 +184,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
||||
* settings is used to create the manager. See the Javadoc of
|
||||
* {@code ContentNegotiationManagerFactoryBean} for details
|
||||
* @param contentNegotiationManager the manager to use
|
||||
* @since 4.3.0
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
|
||||
this.contentNegotiationManager = contentNegotiationManager;
|
||||
@@ -335,10 +334,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
||||
this.resourceHttpMessageConverter.write(rangeResource, mediaType, outputMessage);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
Long contentLength = resource.contentLength();
|
||||
if (contentLength != null) {
|
||||
response.addHeader("Content-Range", "bytes */" + resource.contentLength());
|
||||
}
|
||||
response.addHeader("Content-Range", "bytes */" + resource.contentLength());
|
||||
response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
|
||||
}
|
||||
}
|
||||
@@ -468,7 +464,6 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
protected MediaType getMediaType(HttpServletRequest request, Resource resource) {
|
||||
|
||||
// For backwards compatibility
|
||||
MediaType mediaType = getMediaType(resource);
|
||||
if (mediaType != null) {
|
||||
@@ -535,6 +530,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
||||
response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResourceHttpRequestHandler [locations=" + getLocations() + ", resolvers=" + getResourceResolvers() + "]";
|
||||
|
||||
Reference in New Issue
Block a user