public static void handleException(HttpServletRequest request, HttpServletResponse response,
Exception e, String realm, boolean sendBodyInJson, boolean withAuthHeader)
throws IOException, ServletException {
if (e instanceof OAuth2ProblemException) {
OAuth2ProblemException problem = (OAuth2ProblemException) e;
Object httpCode = getHttpCode(problem);
response.reset();
response.setStatus(Integer.parseInt(httpCode.toString()));
OAuth2Message message = new OAuth2Message(null, null, problem.getParameters().entrySet());
if(withAuthHeader){
response.addHeader("WWW-Authenticate", message.getWWWAuthenticateHeader(realm));
}
List<Map.Entry<String, String>> sendBackErrorParameters = new ArrayList<Map.Entry<String, String>>(SEND_BACK_ERROR_PARAMETERS.size());