@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); }
/** * Constructor. * * @param status * The status to associate. */ public ResourceException(Status status, Resource resource) { this(status, (Throwable) ((status == null) ? null : status.getThrowable()), resource); }
/** * Constructor. * * @param status * The status to associate. */ public ResourceException(Status status) { this(status, (Throwable) ((status == null) ? null : status.getThrowable())); }
/** * Constructor. * * @param status * The status to associate. */ public ResourceException(Status status) { this(status, (Throwable) ((status == null) ? null : status .getThrowable())); }
@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); }
@Override public Representation getRepresentation(Status status, Request request, Response response) { StringBuilder sb = new StringBuilder(); Throwable throwable = status.getThrowable(); if (throwable != null) { sb.append(throwable.getMessage()); return new StringRepresentation(String.format("Http Status = %s\n + Error = %s", new Object[]{status.toString(), sb.toString()})); } else { return new StringRepresentation(String.format("Http Status = %s", new Object[]{status.toString()})); } }
public Error(Status status) { this.httpcode = status.getCode(); this.message = status.toString(); this.description = status.getDescription(); if (status.getThrowable() != null) { Throwable t = status.getThrowable(); if (t instanceof OntopiaRestException) { code = ((OntopiaRestException) t).getOntopiaCode(); } Set<String> c = new HashSet<>(); while (t.getCause() != null) { t = t.getCause(); c.add(t.getClass().getName() + ": " + (t.getMessage() != null ? t.getMessage() : "")); } if (!c.isEmpty()) { causes = c.toArray(causes); } } }
public Representation getRepresentation(final Status status, final Request request, final Response response) { final HashMap<String, Object> dataModel = new HashMap<String, Object>(); final SystemStatus systemStatus = applicationStatusSource.getSystemStatus(); dataModel.put("request", request); dataModel.put("nexusVersion", systemStatus.getVersion()); dataModel.put("nexusRoot", BaseUrlHolder.get()); dataModel.put("statusCode", status.getCode()); dataModel.put("statusName", status.getName()); dataModel.put("errorDescription", StringEscapeUtils.escapeHtml(status.getDescription())); if (null != status.getThrowable()) { dataModel.put("errorStackTrace", StringEscapeUtils.escapeHtml(ExceptionUtils.getStackTrace(status.getThrowable()))); } final VelocityRepresentation representation = new VelocityRepresentation(Context.getCurrent(), "/templates/errorPageContentHtml.vm", getClass().getClassLoader(), dataModel, MediaType.TEXT_HTML); return representation; } }
@Override public Representation getRepresentation(final Status status, final Request request, final Response response) { final Map<String, Object> dataModel = RestletUtils.getBaseDataModel(request); dataModel.put("contentTemplate", this.propertyUtil.get(OasProps.PROP_TMPL_ERROR, OasProps.DEF_TMPL_ERROR)); dataModel.put("pageTitle", "An error occurred : HTTP " + status.getCode()); if(status.getThrowable() != null) { dataModel.put("errorMessage", status.getThrowable().getMessage()); } else { dataModel.put("errorMessage", status.getDescription()); } // TODO: Support non-HTML error representations return RestletUtils.getHtmlRepresentation( this.propertyUtil.get(OasProps.PROP_TMPL_BASE, OasProps.DEF_TMPL_BASE), dataModel, MediaType.TEXT_HTML, this.freemarkerConfiguration); }
@Override protected void doError(Status status) { if (status.equals(Status.CLIENT_ERROR_NOT_ACCEPTABLE) && (status.getThrowable() == null)) { // we have an ontopia error for this List<Preference<MediaType>> acceptedMediaTypes = getClientInfo().getAcceptedMediaTypes(); List<MediaType> accepted = new ArrayList<>(acceptedMediaTypes.size()); for (Preference<MediaType> mt : acceptedMediaTypes) { accepted.add(mt.getMetadata()); } super.doError(OntopiaRestErrors.UNSUPPORTED_MIME_TYPE.build(getClass().getName(), Arrays.toString(accepted.toArray())).getStatus()); } else { super.doError(status); } }
public Representation getRepresentation( final Status status, final Request request, final Response response ) { final HashMap<String, Object> dataModel = new HashMap<String, Object>(); dataModel.put( "request", request ); dataModel.put( "nexusVersion", nexus.getSystemStatus().getVersion() ); dataModel.put( "nexusRoot", referenceFactory.getContextRoot( request ).toString() ); dataModel.put( "statusCode", status.getCode() ); dataModel.put( "statusName", status.getName() ); dataModel.put( "errorDescription", StringEscapeUtils.escapeHtml( status.getDescription() ) ); if ( null != status.getThrowable() ) { dataModel.put( "errorStackTrace", StringEscapeUtils.escapeHtml( ExceptionUtils.getStackTrace( status.getThrowable() ) ) ); } // Load up the template, and pass in the data VelocityRepresentation representation = new VelocityRepresentation( Context.getCurrent(), "/templates/errorPageContentHtml.vm", dataModel, MediaType.TEXT_HTML ); return representation; } }
/** * Constructor. * * @param status * The status to copy. * @param throwable * The related error or exception. * @param description * The description to associate. */ public Status(Status status, Throwable throwable, String description) { this(status.getCode(), (throwable == null) ? status.getThrowable() : throwable, status.getReasonPhrase(), (description == null) ? status.getDescription() : description, status.getUri()); }
/** * Constructor. * * @param status * The status to copy. * @param throwable * The related error or exception. * @param reasonPhrase * The short reason phrase displayed next to the status code in a * HTTP response. * @param description * The description to associate. */ public Status(Status status, Throwable throwable, String reasonPhrase, String description) { this(status.getCode(), (throwable == null) ? status.getThrowable() : throwable, (reasonPhrase == null) ? status.getReasonPhrase() : reasonPhrase, (description == null) ? status.getDescription() : description, status.getUri()); }
Throwable cause = status.getThrowable();
@Override public Representation getRepresentation(org.restlet.data.Status status, Request request, Response response) { TreeWriter tree = new TreeWriter(globalRuntime); tree.startDocument(URI.create("http://example.com/")); tree.addStartElement(BaseResource.pr_error); tree.startContent(); tree.addStartElement(BaseResource.pr_code); tree.startContent(); tree.addText("" + status.getCode()); tree.addEndElement(); tree.addStartElement(BaseResource.pr_message); tree.startContent(); tree.addText("Bad request: " + exceptionMessage(status.getThrowable())); tree.addEndElement(); tree.addEndElement(); tree.endDocument(); return new StringRepresentation(tree.getResult().toString()); }
@Override public Representation getRepresentation(org.restlet.data.Status status, Request request, Response response) { TreeWriter tree = new TreeWriter(globalRuntime); tree.startDocument(URI.create("http://example.com/")); tree.addStartElement(BaseResource.pr_error); tree.startContent(); tree.addStartElement(BaseResource.pr_code); tree.startContent(); tree.addText("" + status.getCode()); tree.addEndElement(); tree.addStartElement(BaseResource.pr_message); tree.startContent(); tree.addText("Bad request: " + exceptionMessage(status.getThrowable())); tree.addEndElement(); tree.addEndElement(); tree.endDocument(); return new StringRepresentation(tree.getResult().toString()); }