@Override public List<String> getHeaders(String headerName) { return getHeadersMap().get(headerName); }
/** * Helper wrapper around {@link #handleException(Throwable, RequestInfoForLogging)} that takes in servlet request * and servlet response. The request will be wrapped in a {@link RequestInfoForLoggingServletApiAdapter} so that it * can be passed along to the method that does the work. If there are any headers in the returned {@link * ErrorResponseInfo#headersToAddToResponse} then they will be automatically added to the given servlet response, * and {@link javax.servlet.http.HttpServletResponse#setStatus(int)} will be automatically set with {@link * ErrorResponseInfo#httpStatusCode} as well. */ public ErrorResponseInfo<T> handleException(Throwable ex, HttpServletRequest servletRequest, HttpServletResponse servletResponse) { ErrorResponseInfo<T> errorResponseInfo = handleException( ex, new RequestInfoForLoggingServletApiAdapter(servletRequest) ); processServletResponse(errorResponseInfo, servletResponse); return errorResponseInfo; }
@Override public String getBody() throws GetBodyException { ServletInputStream is = null; Reader reader = null; try { is = request.getInputStream(); reader = new BufferedReader( new InputStreamReader(is, request.getCharacterEncoding() != null ? request.getCharacterEncoding() : StandardCharsets.UTF_8.name()) ); StringBuilder textBuilder = new StringBuilder(); int c; while ((c = reader.read()) != -1) { textBuilder.append((char) c); } return textBuilder.toString(); } catch (Throwable e) { throw new GetBodyException("An error occurred while extracting the request body", e); } finally { safeCloseCloseable(reader); safeCloseCloseable(is); } }
/** * Helper wrapper around {@link #maybeHandleException(Throwable, RequestInfoForLogging)} that takes in servlet * request and servlet response. The request will be wrapped in a {@link RequestInfoForLoggingServletApiAdapter} so * that it can be passed along to the method that does the work. If there are any headers in the returned {@link * ErrorResponseInfo#headersToAddToResponse} then they will be automatically added to the given servlet response, * and {@link javax.servlet.http.HttpServletResponse#setStatus(int)} will be automatically set with {@link * ErrorResponseInfo#httpStatusCode} as well. */ public ErrorResponseInfo<T> maybeHandleException( Throwable ex, HttpServletRequest servletRequest, HttpServletResponse servletResponse ) throws UnexpectedMajorExceptionHandlingError { ErrorResponseInfo<T> errorResponseInfo = maybeHandleException( ex, new RequestInfoForLoggingServletApiAdapter(servletRequest) ); if (errorResponseInfo != null) processServletResponse(errorResponseInfo, servletResponse); return errorResponseInfo; }