您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

请求上传期间如何处理客户端中止?

请求上传期间如何处理客户端中止?

我已经找到了解决方案,但还没有找到解决问题的案例。

@Autowired
private DefaultErrorAttributes defaultExceptionResolver;

@ExceptionHandler(HttpMessageNotReadableException.class)
public void checkForAbort(HttpServletRequest request, HttpServletResponse response, RuntimeException exception) {
    if (exception.getCause() instanceof EOFException) {
        ClientAbortException abortException = new ClientAbortException(exception.getCause());
        abortException.addSuppressed(exception);

        try {
            response.getOutputStream().close();
        }
        catch (IOException ex) {
            abortException.addSuppressed(ex);
        }

        defaultExceptionResolver.resolveException(request, response, null, abortException);
    }
    else {
        throw exception;
    }
}

例如,这可能会进入@ControllerAdvice

其他 2022/1/1 18:19:38 有345人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶