@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); }
public Representation represent(Variant variant) throws ResourceException { // generate report if (cj == null || cj.getCrawlController() == null) { throw new ResourceException(500); } File f = cj.getCrawlController().getStatisticsTracker().writeReportFile(reportClass); if (f==null) { throw new ResourceException(500); } // redirect String relative = JobResource.getHrefPath(f,cj); if(relative!=null) { getResponse().redirectSeeOther("../"+relative+"?m="+f.lastModified()); return new StringRepresentation(""); } else { return new StringRepresentation( "Report dumped to "+f.getAbsolutePath() +" (outside job directory)"); } } }
@Override public Representation toRepresentation(Object object) { return new StringRepresentation( object.toString(), mediaType ); }
/** * Returns a XMLRepresentation of the layer * * @param layer * @return */ public Representation getXMLRepresentation(TileLayer layer) { XStream xs = xmlConfig.getConfiguredXStream(new XStream()); String xmlText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + xs.toXML(layer); return new StringRepresentation(xmlText, MediaType.TEXT_XML); }
/** * Sets a textual entity. * * @param value * The represented string. * @param mediaType * The representation's media type. */ public void setEntity(String value, MediaType mediaType) { setEntity(new StringRepresentation(value, mediaType)); }
/** * @param s The message to report this error to the user (will report mimetype as text/plain) * @param stat The Status to report to the client * @param e The actual Exception that occurred */ public RestletException(String s, Status stat, Exception e){ super(e); init(new StringRepresentation(s + ":" + e.getMessage(), MediaType.TEXT_PLAIN), stat); }
/** * @param s The message to report this error to the user (will report mimetype as text/plain) * @param stat The Status to report to the client * @param e The actual Exception that occurred */ public RestletException(String s, Status stat, Throwable t){ super(t); init(new StringRepresentation(s + ":" + t.getMessage(), MediaType.TEXT_PLAIN), stat); }
/** * @param s The message to report this error to the user (will report mimetype as text/plain) * @param stat The Status to report to the client */ public RestletException(String s, Status stat){ init(new StringRepresentation(s, MediaType.TEXT_PLAIN), stat); }
/** * Returns the form as a Web representation * (MediaType.APPLICATION_WWW_FORM). * * @param characterSet * The supported character encoding. * @return The form as a Web representation. */ public Representation getWebRepresentation(CharacterSet characterSet) { return new StringRepresentation(getQueryString(characterSet), MediaType.APPLICATION_WWW_FORM, null, characterSet); }
/** * @param s The message to report this error to the user (will report mimetype as text/plain) * @param stat The Status to report to the client */ public RestletException(String s, Status stat){ init(new StringRepresentation(s, MediaType.TEXT_PLAIN), stat); }
private Response request(Method method, Reference uri, String data, MediaType mediaType, MediaType accepts) throws NotSuccessException { return request(method, uri, new StringRepresentation(data, mediaType), accepts, true); }
@Override public void handleGet() { Representation representation = new StringRepresentation(String.valueOf(count), MediaType.TEXT_PLAIN); getResponse().setEntity(representation); } }
/** * Returns a representation of the list in the "text/uri-list" format. * * @return A representation of the list in the "text/uri-list" format. */ public Representation getTextRepresentation() { final StringBuilder sb = new StringBuilder(); if (getIdentifier() != null) { sb.append("# ").append(getIdentifier().toString()).append("\r\n"); } for (final Reference ref : this) { sb.append(ref.toString()).append("\r\n"); } return new StringRepresentation(sb.toString(), MediaType.TEXT_URI_LIST); }
public Object sendCommand( String service, String command ) throws NexusConnectionException { return this.sendMessage( Method.PUT, this.buildUrl( service, "command" ), new StringRepresentation( command, MediaType.TEXT_ALL ) ); }
public static void sendNexusStatusCommand( String command ) throws IOException { Response response = RequestFacade.sendMessage( "service/local/status/command", Method.PUT, new StringRepresentation( command, MediaType.TEXT_ALL ) ); if ( !response.getStatus().isSuccess() ) { Assert.fail( "Could not " + command + " Nexus: (" + response.getStatus() + ")" ); } }
@Override public Object get(Context context, Request request, Response response, Variant variant) throws ResourceException { if (getLogger().isDebugEnabled()) { getLogger().debug( "getting usage of " + request.getResourceRef().getLastSegment()); } Collection<ArtifactUser> artifactList = artifactUsageStore .getArtifactUsers(new GAV(request.getResourceRef() .getLastSegment())); Set<GAV> artifacts = new TreeSet<GAV>(); collectArtifacts(artifacts, artifactList); String jsonText = "{" + ArtifactUsageSerializer.toJson(artifacts) + "}"; return new StringRepresentation(jsonText, MediaType.APPLICATION_JSON); }
@Override public void handleGet() { String bbox = "[" + bounds.getMinX() + ", " + bounds.getMinY() + ", " + bounds.getMaxX() + ", " + bounds.getMaxY() + "]"; Representation representation = new StringRepresentation(bbox, MediaType.APPLICATION_JSON); getResponse().setEntity(representation); } }
@SuppressWarnings( "unchecked" ) public List<ExternalRoleMappingResource> getExternalRoleMap( String source ) throws IOException { // external_role_map String uriPart = RequestFacade.SERVICE_LOCAL + "external_role_map/" + source; Response response = RequestFacade.sendMessage( uriPart, Method.GET, new StringRepresentation( "", this.mediaType ) ); String responseString = response.getEntity().getText(); Assert.assertTrue( "Status: " + response.getStatus() + "\nResponse:\n" + responseString, response .getStatus().isSuccess() ); ExternalRoleMappingResourceResponse result = (ExternalRoleMappingResourceResponse) this.parseResponseText( responseString, new ExternalRoleMappingResourceResponse() ); return result.getData(); }
public PlexusUserResource getPlexusUser( String source, String userId ) throws IOException { String sourcePart = ( source != null ) ? source + "/" : ""; // plexus_user String uriPart = RequestFacade.SERVICE_LOCAL + "plexus_user/" + sourcePart + userId; Response response = RequestFacade.sendMessage( uriPart, Method.GET, new StringRepresentation( "", this.mediaType ) ); String responseString = response.getEntity().getText(); Assert.assertTrue( "Status: " + response.getStatus() + "\nResponse:\n" + responseString, response.getStatus().isSuccess() ); PlexusUserResourceResponse result = (PlexusUserResourceResponse) this.parseResponseText( responseString, new PlexusUserResourceResponse() ); return result.getData(); }
@SuppressWarnings( "unchecked" ) public List<PlexusUserResource> searchPlexusUsers( String source, String userId ) throws IOException { // user_search String uriPart = RequestFacade.SERVICE_LOCAL + "user_search/" + source + "/" + userId; Response response = RequestFacade.sendMessage( uriPart, Method.GET, new StringRepresentation( "", this.mediaType ) ); String responseString = response.getEntity().getText(); Assert.assertTrue( "Status: " + response.getStatus() + "\nResponse:\n" + responseString, response.getStatus().isSuccess() ); PlexusUserListResourceResponse result = (PlexusUserListResourceResponse) this.parseResponseText( responseString, new PlexusUserListResourceResponse() ); return result.getData(); }