public List<PrivilegeStatusResource> getList( ) throws IOException { Response response = this.sendMessage( Method.GET, null ); if ( !response.getStatus().isSuccess() ) { Assert.fail( "Could not get Privilege: " + response.getStatus() +"\n" + response.getEntity().getText()); } return this.getResourceListFromResponse( response ); }
@Override public void acceptRepresentation(Representation entity) throws ResourceException { Form form = getRequest().getEntityAsForm(); chosenEngine = form.getFirstValue("engine"); String script = form.getFirstValue("script"); if(StringUtils.isBlank(script)) { script=""; } ScriptEngine eng = MANAGER.getEngineByName(chosenEngine); scriptingConsole.bind("scriptResource", this); scriptingConsole.execute(eng, script); scriptingConsole.unbind("scriptResource"); //TODO: log script, results somewhere; job log INFO? getResponse().setEntity(represent()); }
/** * Permanently redirects the client to a target URI. The client is expected * to reuse the same method for the new request. * * @param targetRef * The target URI reference. */ public void redirectPermanent(Reference targetRef) { setLocationRef(targetRef); setStatus(Status.REDIRECTION_PERMANENT); }
final Reference baseRef = new Reference(base); targetRef = new Reference(baseRef, href); } else { targetRef = new Reference(href); final Response response = this.context.getClientDispatcher() .get(targetUri); if (response.getStatus().isSuccess() && response.isEntityAvailable()) { try { result = new StreamSource(response.getEntity() .getStream()); result.setSystemId(targetUri);
throws ResourceException String path = parsePathFromUri(request.getResourceRef().toString()); if (!path.endsWith("/")) { response.redirectPermanent(path + "/"); return null; String versionHint = null; Form form = request.getResourceRef().getQueryAsForm(); new IndexBrowserTreeNodeFactory(repository, createRedirectBaseRef(request).toString()); throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "The index is disabled for this repository."); throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, "Access Denied to Repository");
protected File downloadSnapshotArtifact( String repository, Gav gav, File parentDir ) throws IOException { // @see http://issues.sonatype.org/browse/NEXUS-599 // r=<repoId> -- mandatory // g=<groupId> -- mandatory // a=<artifactId> -- mandatory // v=<version> -- mandatory // c=<classifier> -- optional // p=<packaging> -- optional, jar is taken as default // http://localhost:8087/nexus/service/local/artifact/maven/redirect?r=tasks-snapshot-repo&g=nexus&a=artifact& // v=1.0-SNAPSHOT String serviceURI = "service/local/artifact/maven/redirect?r=" + repository + "&g=" + gav.getGroupId() + "&a=" + gav.getArtifactId() + "&v=" + gav.getVersion(); Response response = RequestFacade.doGetRequest( serviceURI ); Status status = response.getStatus(); Assert.assertEquals( "Snapshot download should redirect to a new file\n " + response.getRequest().getResourceRef().toString() + " \n Error: " + status.getDescription(), 301, status.getCode() ); Reference redirectRef = response.getRedirectRef(); Assert.assertNotNull( "Snapshot download should redirect to a new file " + response.getRequest().getResourceRef().toString(), redirectRef ); serviceURI = redirectRef.toString(); File file = FileUtils.createTempFile( gav.getArtifactId(), '.' + gav.getExtension(), parentDir ); RequestFacade.downloadFile( new URL( serviceURI ), file.getAbsolutePath() ); return file; }
public Object get(Context context, Request request, Response response, Variant variant) throws ResourceException { Form form = request.getResourceRef().getQueryAsForm(); final long timeout = Long.parseLong(form.getFirstValue("timeout", "60000")); try { final long startTime = System.currentTimeMillis(); while (System.currentTimeMillis() - startTime <= timeout) { if (!((ManagerImpl) manager).isUpdatePrefixFileJobRunning()) { response.setStatus(Status.SUCCESS_OK); return "Ok"; } Thread.sleep(500); } } catch (final InterruptedException ignore) { // ignore } response.setStatus(Status.SUCCESS_ACCEPTED); return "Still munching on them..."; } }
private void doGet(Request request, Response response) { Reference resourceRef = request.getResourceRef(); String baseUrl = resourceRef.toString(); if (baseUrl.endsWith("/")) { baseUrl = baseUrl.substring(0, baseUrl.length() - 1); } Representation result = new StringRepresentation( "<html><body>\n" + "<a id=\"logo\" href=\"" + resourceRef.getParentRef() + "\">" + "<img src=\"" + baseUrl + "/web/geowebcache_logo.png\" alt=\"\" height=\"100\" width=\"353\" border=\"0\"/></a>\n" + "<h3>Resources available from here:</h3>" + "<ul>" + "<li><h4><a href=\"" + baseUrl + "/layers/\">layers</a></h4>" + "Lets you see the configured layers. You can also view a specific layer " + " by appending the name of the layer to the URL, DELETE an existing layer " + " or POST a new one. Note that the latter operations only make sense when GeoWebCache" + " has been configured through geowebcache.xml. You can POST either XML or JSON." + "</li>\n" + "<li><h4>seed</h4>" + "" + "</li>\n" + "</ul>" + "</body></html>", MediaType.TEXT_HTML); response.setEntity(result); } }
AccessDeniedException, ResourceException String resPath = parsePathFromUri(req.getResourceRef().toString()); res.redirectPermanent(createRedirectReference(req).getTargetRef().toString() + "/"); if (Method.HEAD.equals(req.getMethod())) { return renderHeadResponseItem(context, req, res, variant, store, coll.getResourceStoreRequest(), coll); Representation result = serialize(context, req, variant, response); result.setModificationDate(new Date(coll.getModified()));
public ArtifactInfoResource getInfo(String repositoryId, String itemPath) throws IOException { Response response = null; String entityText; try { response = RequestFacade.sendMessage("service/local/repositories/" + repositoryId + "/content/" + itemPath + "?describe=info", Method.GET, new XStreamRepresentation(xstream, "", MediaType.APPLICATION_XML)); entityText = response.getEntity().getText(); // to make Restlet response buffer it if (response.getStatus().getCode() == Status.REDIRECTION_FOUND.getCode()) { // follow redirection but only ONCE RequestFacade.releaseResponse(response); response = RequestFacade.sendMessage(new URL(response.getLocationRef().toString()), Method.GET, new XStreamRepresentation(xstream, "", MediaType.APPLICATION_XML)); entityText = response.getEntity().getText(); // to make Restlet response buffer it } assertThat(response, isSuccessful()); } finally { RequestFacade.releaseResponse(response); } XStreamRepresentation rep = new XStreamRepresentation(XStreamFactory.getXmlXStream(), entityText, MediaType.APPLICATION_XML); ArtifactInfoResourceResponse info = (ArtifactInfoResourceResponse) rep.getPayload(new ArtifactInfoResourceResponse()); return info.getData(); }
protected String buildUploadFailedHtmlResponse(Throwable t, Request request, Response response) { try { handleException(request, response, t); } catch (ResourceException e) { getLogger().debug("Got error while uploading artifact", t); StringBuilder resp = new StringBuilder(); resp.append("<html><body><error>"); resp.append(StringEscapeUtils.escapeHtml(e.getMessage())); resp.append("</error></body></html>"); String forceSuccess = request.getResourceRef().getQueryAsForm().getFirstValue("forceSuccess"); if (!"true".equals(forceSuccess)) { response.setStatus(e.getStatus()); } return resp.toString(); } // We have an error at this point, can't get here return null; }
Method m = request.getMethod(); LockType type; String path= request.getResourceRef().getPath(); response.setStatus(Status.CLIENT_ERROR_LOCKED); throw new HttpErrorCodeException(Status.CLIENT_ERROR_LOCKED.getCode());
/** * Returns the feed representation. * * @return The feed representation. * @throws Exception */ public Feed getFeed() throws Exception { final Reference feedRef = getHref(); if (feedRef.isRelative()) { feedRef.setBaseRef(getWorkspace().getService().getReference()); } final Request request = new Request(Method.GET, feedRef.getTargetRef()); final Response response = getWorkspace().getService() .getClientDispatcher().handle(request); if (response.getStatus().equals(Status.SUCCESS_OK)) { return new Feed(response.getEntity()); } else { throw new Exception( "Couldn't get the feed representation. Status returned: " + response.getStatus().getDescription()); } }
@Override public void delete(Context context, Request request, Response response) throws ResourceException { String repoId = this.getRepositoryId(request); try { getNexusConfiguration().deleteRepository(repoId, true); response.setStatus(Status.SUCCESS_NO_CONTENT); } catch (Exception e) { getLogger().warn("Unable to delete repository, id=" + repoId); throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Unable to delete repository, id=" + repoId); } }
@Override protected void afterHandle(Request request, Response response) { if (response.isEntityAvailable() && response.getEntity().getEncodings().contains( Encoding.FREEMARKER)) { final TemplateRepresentation representation = new TemplateRepresentation( response.getEntity(), this.configuration, response .getEntity().getMediaType()); if (this.dataModel == null) { representation.setDataModel(request, response); } else { representation.setDataModel(this.dataModel); } response.setEntity(representation); } }
public void doPost(Request req, Response resp) throws RestletException { Form form = req.getEntityAsForm(); "Unknown or malformed request. Please try again, somtimes the form " +"is not properly received. This frequently happens on the first POST " +"after a restart. The POST was to " + req.getResourceRef().getPath(), Status.CLIENT_ERROR_BAD_REQUEST ); doc.append("</body></html>"); resp.setEntity(doc.toString(), MediaType.TEXT_HTML);
public static void removeAllTarget() throws IOException { List<RepositoryTargetListResource> targets = getList(); for (RepositoryTargetListResource target : targets) { Status status = RequestFacade.sendMessage("service/local/repo_targets/" + target.getId(), Method.DELETE).getStatus(); Assert.assertTrue("Failt to delete: " + status.getDescription(), status.isSuccess()); } }
/** * Asks the resource to delete itself and all its representations.The * default behavior is to invoke the {@link #removeRepresentations()} * method. * * @deprecated Use the {@link #removeRepresentations()} method instead. */ @Deprecated public void delete() { try { removeRepresentations(); } catch (ResourceException re) { getResponse().setStatus(re.getStatus(), re); } }