Revert "Add handleFailure property to FrameworkServlet"

This reverts commit 29ce6685ca.
This commit is contained in:
Rossen Stoyanchev
2018-08-17 09:47:00 +03:00
parent 0dd9e8ce02
commit 498984324d
4 changed files with 9 additions and 74 deletions

View File

@@ -209,9 +209,6 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
/** Should we dispatch an HTTP TRACE request to {@link #doService}?. */
private boolean dispatchTraceRequest = false;
/** Should we set the status to 500 for unhandled failures? */
private boolean shouldHandleFailure = false;
/** WebApplicationContext for this servlet. */
@Nullable
private WebApplicationContext webApplicationContext;
@@ -475,17 +472,6 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
this.dispatchTraceRequest = dispatchTraceRequest;
}
/**
* Whether to handle failures wth {@code response.sendError(500)} as opposed
* to letting them propagate to the container which may log a stacktrace
* even if an error dispatch (e.g. Spring Boot app) handles the exception.
* @param shouldHandleFailure whether to handle failures or propagate
* @since 5.1
*/
public void setShouldHandleFailure(boolean shouldHandleFailure) {
this.shouldHandleFailure = shouldHandleFailure;
}
/**
* Whether to log request params at DEBUG level, and headers at TRACE level.
* Both may contain sensitive information.
@@ -1012,16 +998,12 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
doService(request, response);
}
catch (ServletException | IOException ex) {
if (!handleFailure(request, response, ex)) {
failureCause = ex;
throw ex;
}
failureCause = ex;
throw ex;
}
catch (Throwable ex) {
if (!handleFailure(request, response, ex)) {
failureCause = ex;
throw new NestedServletException("Request processing failed", ex);
}
failureCause = ex;
throw new NestedServletException("Request processing failed", ex);
}
finally {
@@ -1087,24 +1069,6 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
RequestContextHolder.setRequestAttributes(previousAttributes, this.threadContextInheritable);
}
private boolean handleFailure(HttpServletRequest request, HttpServletResponse response, Throwable ex) {
if (this.shouldHandleFailure) {
try {
response.sendError(500);
}
catch (IOException ex2) {
if (logger.isDebugEnabled()) {
logger.debug("Handling of failure failed: " + ex2);
}
return false;
}
request.setAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE, 500);
WebUtils.exposeErrorRequestAttributes(request, ex, getServletName());
return true;
}
return false;
}
private void logResult(HttpServletRequest request, HttpServletResponse response,
@Nullable Throwable failureCause, WebAsyncManager asyncManager) {

View File

@@ -281,7 +281,8 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
inputMessage, outputMessage);
if (body != null) {
if (logger.isDebugEnabled()) {
logger.debug("Writing [" + formatValue(body) + "]");
Object formatted = (body instanceof CharSequence ? "\"" + body + "\"" : body);
logger.debug("Writing [" + formatted + "]");
}
addContentDispositionHeader(inputMessage, outputMessage);
if (genericConverter != null) {
@@ -398,10 +399,6 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
return (MediaType.SPECIFICITY_COMPARATOR.compare(acceptType, produceTypeToUse) <= 0 ? acceptType : produceTypeToUse);
}
static String formatValue(Object body) {
return (body instanceof CharSequence ? "\"" + body + "\"" : body.toString());
}
/**
* Check if the path has a file extension and whether the extension is
* either {@link #WHITELISTED_EXTENSIONS whitelisted} or explicitly

View File

@@ -885,8 +885,8 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
mavContainer = (ModelAndViewContainer) asyncManager.getConcurrentResultContext()[0];
asyncManager.clearConcurrentResult();
if (logger.isDebugEnabled()) {
String formatted = AbstractMessageConverterMethodProcessor.formatValue(result);
logger.debug("Resume with async result [" + formatted + "]");
logger.debug("Resume with async result [" +
(result instanceof CharSequence ? "\"" + result + "\"" : result) + "]");
}
invocableMethod = invocableMethod.wrapConcurrentResult(result);
}