@Override public Representation getRepresentation(Status status, Request request, Response response) { StringWriter st = new StringWriter(); PrintWriter pw = new PrintWriter(st); if(status.getCode()==404){ pw.append("<h1>Page not found</h1>\n"); pw.append("The page you are looking for does not exist. "+ "You may be able to recover by going " + "<a href='javascript:history.back();void(0);'>back</a>.\n"); } else{ pw.append("<h1>An error occurred</h1>\n"); pw.append( "You may be able to recover and try something " + "else by going " + "<a href='javascript:history.back();void(0);'>back</a>.\n"); if(status.getThrowable()!=null) { pw.append("<h2>Cause: "+ status.getThrowable().toString()+"</h2>\n"); pw.append("<pre>"); status.getThrowable().printStackTrace(pw); pw.append("</pre>"); } } pw.flush(); return new StringRepresentation(st.toString(),MediaType.TEXT_HTML); }
/** {@inheritDoc} */ @Override public int hashCode() { return getCode(); }
/** {@inheritDoc} */ @Override public int hashCode() { return getCode(); }
public HTTPOutput(String description, Object result) { this.status = Status.SUCCESS_OK; this.description = description; this.code = status.getCode(); this.result = result; }
/** * Indicates if the status is a redirection status, meaning "Further action * must be taken in order to complete the request". * * @return True if the status is a redirection status. */ public boolean isRedirection() { return isRedirection(getCode()); }
/** * Indicates if the status is a success status, meaning "The action was * successfully received, understood, and accepted". * * @return True if the status is a success status. */ public boolean isSuccess() { return isSuccess(getCode()); }
/** * Indicates if the status is an error (client or server) status. * * @return True if the status is an error (client or server) status. */ public boolean isError() { return isError(getCode()); }
/** * Indicates if the status is a redirection status, meaning "Further action * must be taken in order to complete the request". * * @return True if the status is a redirection status. */ public boolean isRedirection() { return isRedirection(getCode()); }
/** * Indicates if the status is a connector error status, meaning "The * connector failed to send or receive an apparently valid message". * * @return True if the status is a connector error status. */ public boolean isConnectorError() { return isConnectorError(getCode()); }
/** * Indicates if the status is a client error status, meaning "The request * contains bad syntax or cannot be fulfilled". * * @return True if the status is a client error status. */ public boolean isClientError() { return isClientError(getCode()); }
/** * Indicates if the status is a connector error status, meaning "The * connector failed to send or receive an apparently valid message". * * @return True if the status is a connector error status. */ public boolean isConnectorError() { return isConnectorError(getCode()); }
/** * Indicates if the status is a client error status, meaning "The request * contains bad syntax or cannot be fulfilled". * * @return True if the status is a client error status. */ public boolean isClientError() { return isClientError(getCode()); }
/** * Indicates if the status is a global error status, meaning "The server has * definitive information about a particular user". * * @return True if the status is a global error status. */ public boolean isGlobalError() { return isGlobalError(getCode()); }
@Override protected boolean matchesSafely( Response item ) { return item.getStatus().getCode() == expectedStatusCode; }
/** * Indicates if the status is an information status, meaning "request * received, continuing process". * * @return True if the status is an information status. */ public boolean isInformational() { return isInformational(getCode()); }
/** * Indicates if the status is a server error status, meaning "The server * failed to fulfill an apparently valid request". * * @return True if the status is a server error status. */ public boolean isServerError() { return isServerError(getCode()); }
/** * Constructor. * * @param status * The status to copy. * @param description * The description to associate. */ public Status(final Status status, final String description) { this(status.getCode(), status.getName(), description, status.getUri()); }
/** * Constructor. The default status code is {@link Status#SUCCESS_OK}. */ public Response() { setCode(Status.SUCCESS_OK.getCode()); setMessage(Status.SUCCESS_OK.getDescription()); }
/** * Constructor. The default status code is {@link Status#SUCCESS_OK}. */ public Response() { setCode(Status.SUCCESS_OK.getCode()); setMessage(Status.SUCCESS_OK.getDescription()); }
/** * Constructor. The default status code is {@link Status#SUCCESS_OK}. */ public Response() { setCode(Status.SUCCESS_OK.getCode()); setMessage(Status.SUCCESS_OK.getDescription()); }