/** * Return a string representation of this status code. */ @Override public String toString() { return reason() + " (" + value + ")"; }
private void parse(final String text) { Pattern pattern = Pattern.compile("(\\d+)\\s*([:=]\\s*((.*)))?"); Matcher matcher = pattern.matcher(text); if (matcher.find()) { try { int statusCode = Integer.parseInt(matcher.group(1).trim()); String desc = Optional.ofNullable(matcher.group(3)) .orElse(Status.valueOf(statusCode).reason()); statusCodes.put(statusCode, desc); } catch (IllegalArgumentException x) { LoggerFactory.getLogger(DocParser.class).debug("Ignoring status code", x); } } } };
/** * Build an error message using the HTTP status. * * @param status The HTTP Status. * @param tail A message to append. * @return An error message. */ private static String message(final Status status, @Nullable final String tail) { return message(status.reason(), status.value(), tail); }
/** * Produces a friendly view of the err, resulting map has these attributes: * * <pre> * message: exception message (if present) * stacktrace: array with the stacktrace * status: status code * reason: a status code reason * </pre> * * @param stacktrace True for adding stacktrace. * @return A lightweight view of the err. */ public Map<String, Object> toMap(boolean stacktrace) { Status status = Status.valueOf(this.status); Throwable cause = Optional.ofNullable(getCause()).orElse(this); String message = Optional.ofNullable(cause.getMessage()).orElse(status.reason()); Map<String, Object> err = new LinkedHashMap<>(); err.put("message", message); if (stacktrace) { err.put("stacktrace", Throwables.getStackTraceAsString(cause).replace("\r", "").split("\\n")); } err.put("status", status.value()); err.put("reason", status.reason()); return err; }
if (status != null) { routeResponse.status(ImmutableMap.of(status, Try.apply(() -> Status.valueOf(status.intValue()).reason()) .orElse(status.toString())));
/** * Return a string representation of this status code. */ @Override public String toString() { return reason() + " (" + value + ")"; }
private void parse(final String text) { Pattern pattern = Pattern.compile("(\\d+)\\s*([:=]\\s*((.*)))?"); Matcher matcher = pattern.matcher(text); if (matcher.find()) { try { int statusCode = Integer.parseInt(matcher.group(1).trim()); String desc = Optional.ofNullable(matcher.group(3)) .orElse(Status.valueOf(statusCode).reason()); statusCodes.put(statusCode, desc); } catch (IllegalArgumentException x) { LoggerFactory.getLogger(DocParser.class).debug("Ignoring status code", x); } } } };
/** * Build an error message using the HTTP status. * * @param status The HTTP Status. * @param tail A message to append. * @return An error message. */ private static String message(final Status status, @Nullable final String tail) { return message(status.reason(), status.value(), tail); }
public Map<String, Object> accept(final Node node, final String method, final Context ctx) { try { node.accept(this, ctx); if (!doc.containsKey("@statusCodes")) { Map<Object, Object> codes = new LinkedHashMap<>(); Status status = Status.OK; if ("DELETE".equals(method)) { status = Status.NO_CONTENT; } codes.put(status.value(), status.reason()); doc.put("@statusCodes", codes); } } catch (Exception x) { log.debug("Doc collector resulted in exception", x); } return doc; }
/** * Produces a friendly view of the err, resulting map has these attributes: * * <pre> * message: exception message (if present) * stacktrace: array with the stacktrace * status: status code * reason: a status code reason * </pre> * * @param stacktrace True for adding stacktrace. * @return A lightweight view of the err. */ public Map<String, Object> toMap(boolean stacktrace) { Status status = Status.valueOf(this.status); Throwable cause = Optional.ofNullable(getCause()).orElse(this); String message = Optional.ofNullable(cause.getMessage()).orElse(status.reason()); Map<String, Object> err = new LinkedHashMap<>(); err.put("message", message); if (stacktrace) { err.put("stacktrace", Throwables.getStackTraceAsString(cause).replace("\r", "").split("\\n")); } err.put("status", status.value()); err.put("reason", status.reason()); return err; }
while (cmatcher.find()) { Status status = Status.valueOf(Integer.parseInt(cmatcher.group(1).trim())); String message = Optional.ofNullable(cmatcher.group(3)).orElse(status.reason()).trim(); codes.put(status.value(), message);
if (status != null) { routeResponse.status(ImmutableMap.of(status, Try.apply(() -> Status.valueOf(status.intValue()).reason()) .orElse(status.toString())));