@Override protected void handleErrorPage( HttpServletRequest request, Writer writer, int code, String message) throws IOException { writer.write("<!DOCTYPE<html><head><title>Error</title></head><html><body>" + code + " - " + HttpStatus.getMessage(code) + "</body></html>"); } });
/** * Converts exception into json map. * @param ex Exception to be converted. * @param statusCode Status code to be returned. * @return Map to be converted into json. */ public static Map exceptionToJson(Exception ex, int statusCode) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); return ImmutableMap.of( "error", statusCode + " " + HttpStatus.getMessage(statusCode), "errorMessage", sw.toString()); }
@Override protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { String defaultErrorMessage = HttpStatus.getMessage(code); String errorPage = replaceHtml(code, defaultErrorMessage); writer.write(errorPage); }
@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context) throws ContainerException { final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo(); final int code = statusInfo.getStatusCode(); final String reason = statusInfo.getReasonPhrase() == null ? HttpStatus.getMessage(code) : statusInfo.getReasonPhrase(); response.setStatusWithReason(code, reason); if (contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) { for (final String value : e.getValue()) { response.addHeader(e.getKey(), value); } } try { return response.getOutputStream(); } catch (final IOException ioe) { throw new ContainerException("Error during writing out the response headers.", ioe); } }
@Override protected void handleErrorPage(HttpServletRequest request, Writer writer, int code, String message) throws IOException { if (message == null) message = HttpStatus.getMessage(code); JsonObject obj = new JsonObject(); obj.addProperty("code", code); obj.addProperty("message", message); writer.write(obj.toString()); }
@Override protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); // Write a very short body (this makes people pushing with collectd happy). writer.write(String.valueOf(code)); writer.write(" -- "); writer.write(message); // Log the request error. Throwable th = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); if (th != null) { final String http_request = request.getMethod() + ' ' + request.getRequestURI() + ' ' + request.getProtocol(); LOG.log(Level.WARNING, http_request, th); } } }
public static JSONObject getStandardReturn(int status_code, JSONObject data, JSONArray errors) { if(data == null) { data = new JSONObject(); } if(errors == null) { errors = new JSONArray(); } JSONObject standard = new JSONObject() .put("success", httpSuccess(status_code)) .put("status_code", status_code) .put("status_message", HttpStatus.getMessage(status_code)) .put("data", data) .put("errors", errors) ; return standard; }
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); writer.write("<html>\n<head>\n"); writeErrorPageHead(request,writer,code,message); writer.write("</head>\n<body>"); writeErrorPageBody(request,writer,code,message,showStacks); writer.write("\n</body>\n</html>\n"); }
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); writer.write("<html>\n<head>\n"); writeErrorPageHead(request,writer,code,message); writer.write("</head>\n<body>"); writeErrorPageBody(request,writer,code,message,showStacks); writer.write("\n</body>\n</html>\n"); }
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); writer.write("<html>\n<head>\n"); writeErrorPageHead(request,writer,code,message); writer.write("</head>\n<body>"); writeErrorPageBody(request,writer,code,message,showStacks); writer.write("\n</body>\n</html>\n"); }
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); writer.write("<html>\n<head>\n"); writeErrorPageHead(request,writer,code,message); writer.write("</head>\n<body>"); writeErrorPageBody(request,writer,code,message,showStacks); writer.write("\n</body>\n</html>\n"); }
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); writer.write("<html>\n<head>\n"); writeErrorPageHead(request,writer,code,message); writer.write("</head>\n<body>"); writeErrorPageBody(request,writer,code,message,showStacks); writer.write("\n</body>\n</html>\n"); }
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); writer.write("<html>\n<head>\n"); writeErrorPageHead(request,writer,code,message); writer.write("</head>\n<body>"); writeErrorPageBody(request,writer,code,message,showStacks); writer.write("\n</body>\n</html>\n"); }
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); writer.write("<html>\n<head>\n"); writeErrorPageHead(request,writer,code,message); writer.write("</head>\n<body>"); writeErrorPageBody(request,writer,code,message,showStacks); writer.write("\n</body>\n</html>\n"); }
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); writer.write("<html>\n<head>\n"); writeErrorPageHead(request,writer,code,message); writer.write("</head>\n<body>"); writeErrorPageBody(request,writer,code,message,showStacks); writer.write("\n</body>\n</html>\n"); }
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); writer.write("<html>\n<head>\n"); writeErrorPageHead(request,writer,code,message); writer.write("</head>\n<body>"); writeErrorPageBody(request,writer,code,message,showStacks); writer.write("\n</body>\n</html>\n"); }
protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { if (message == null) message=HttpStatus.getMessage(code); writer.write("<html>\n<head>\n"); writeErrorPageHead(request,writer,code,message); writer.write("</head>\n<body>"); writeErrorPageBody(request,writer,code,message,showStacks); writer.write("\n</body>\n</html>\n"); }
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String msg = (String)request.getAttribute(RequestDispatcher.ERROR_MESSAGE); if (StringUtils.isEmpty(msg) || msg.contains("org.apache.cxf.interceptor.Fault")) { msg = HttpStatus.getMessage(response.getStatus()); request.setAttribute(RequestDispatcher.ERROR_MESSAGE, msg); } if (response instanceof Response) { ((Response)response).setStatusWithReason(response.getStatus(), msg); } super.handle(target, baseRequest, request, response); }
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String msg = (String)request.getAttribute(RequestDispatcher.ERROR_MESSAGE); if (StringUtils.isEmpty(msg) || msg.contains("org.apache.cxf.interceptor.Fault")) { msg = HttpStatus.getMessage(response.getStatus()); request.setAttribute(RequestDispatcher.ERROR_MESSAGE, msg); } if (response instanceof Response) { ((Response)response).setStatusWithReason(response.getStatus(), msg); } super.handle(target, baseRequest, request, response); }
private String requestStatus(Request request, Response r, boolean uriIsSecret) { String safeUri = safeUri(request, uriIsSecret); return request.getMethod() + " " + safeUri + ": " + r.getStatus() + " " + HttpStatus.getMessage(r.getStatus()); }