Refine search
public JobRelatedResource(Context ctx, Request req, Response res) throws ResourceException { super(ctx, req, res); cj = getEngine().getJob((String)req.getAttributes().get("job")); if(cj==null) { throw new ResourceException(404); } }
/** * Retrieve artifact details using a hash value. * @param algorithm The hash algorithm (i.e. md5 or sha1). * @param hash The hash string to compare. */ @Override @GET @ResourceMethodSignature( pathParams = { @PathParam( IdentifyHashPlexusResource.ALGORITHM_KEY ), @PathParam( IdentifyHashPlexusResource.HASH_KEY ) }, output = NexusArtifact.class ) public Object get( Context context, Request request, Response response, Variant variant ) throws ResourceException { String alg = request.getAttributes().get( ALGORITHM_KEY ).toString(); String checksum = request.getAttributes().get( HASH_KEY ).toString(); NexusArtifact na = null; try { if ( "sha1".equalsIgnoreCase( alg ) ) { na = ai2Na( request, indexerManager.identifyArtifact( MAVEN.SHA1, checksum ) ); } } catch ( IOException e ) { throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "IOException during configuration retrieval!", e ); } return na; }
@GET @ResourceMethodSignature(output = PlexusComponentListResourceResponse.class) public Object get(Context context, Request request, Response response, Variant variant) throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
@ResourceMethodSignature(pathParams = {@PathParam("userId")}) public void delete(Context context, Request request, Response response) throws ResourceException getSecuritySystem().resetPassword(userId); response.setStatus(Status.SUCCESS_NO_CONTENT); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Anonymous user cannot reset password!"); getLogger().debug("Invalid userid: " + userId, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "User ID not found!", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Failed to set password!.", e);
/** * Removes a security role. * * @param roleId Id of the role to be removed. */ @Override @DELETE @ResourceMethodSignature(pathParams = {@PathParam("roleId")}) public void delete(Context context, Request request, Response response) throws ResourceException { try { AuthorizationManager authzManager = getSecuritySystem().getAuthorizationManager(ROLE_SOURCE); authzManager.deleteRole(getRoleId(request)); } catch (NoSuchRoleException e) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, e.getMessage()); } catch (NoSuchAuthorizationManagerException e) { this.getLogger().warn("Could not found AuthorizationManager: " + ROLE_SOURCE, e); // we should not ever get here throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Authorization Manager for: " + ROLE_SOURCE + " could not be found."); } }
/** * Prevent the client from accessing resources in upper directories */ public void preventUpperDirectoryAccess() { String targetUriPath = new Reference(Reference.decode(targetUri)) .normalize() .toString(); if (!targetUriPath.startsWith(directory.getRootRef().toString())) { throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN); } }
@Override public Object get(Context context, Request request, Response response, Variant variant) throws ResourceException { Form form = request.getResourceRef().getQueryAsForm(); int requestedStatus = Integer.parseInt(form.getFirstValue("status")); throw new ResourceException(requestedStatus); } }
protected Map<String, String> getArguments(final Request request) throws ResourceException { Map<String, String> arguments; selfURI = request.getResourceRef().toString(); sail = LinkedDataServer.getInstance().getSail(); //getVariants().add(new Variant(MediaType.APPLICATION_JSON)); int i = selfURI.lastIndexOf("?"); arguments = new HashMap<>(); if (0 < i) { String args = selfURI.substring(i + 1); if (0 < args.length()) { try { arguments = parseParams(args); } catch (UnsupportedEncodingException e) { throw new ResourceException(e); } } } return arguments; }
@Test public void testGetWhoAmIUnauthenticated() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_WHOAMI_PATH, OasProps.DEF_WHOAMI_PATH))); try { creationClientResource.get(); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
public Reference toReference(String uri) { String query; try { query = form.encode(); } catch (IOException ex) { Logger.getLogger(OAuthParameters.class.getName()).log(Level.SEVERE, null, ex); throw new ResourceException(ex); } Reference reference = new Reference(uri); reference.setQuery(query); return reference; }
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; }
public void acceptRepresentation(Representation entity) throws ResourceException { if (appCtx == null) { throw new ResourceException(404); } // copy op? Form form = getRequest().getEntityAsForm(); beanPath = form.getFirstValue("beanPath"); String newVal = form.getFirstValue("newVal"); if(newVal!=null) { int i = beanPath.indexOf("."); String beanName = i<0?beanPath:beanPath.substring(0,i); Object namedBean = appCtx.getBean(beanName); BeanWrapperImpl bwrap = new BeanWrapperImpl(namedBean); String propPath = beanPath.substring(i+1); Object coercedVal = bwrap.convertIfNecessary(newVal, bwrap.getPropertyValue(propPath).getClass()); bwrap.setPropertyValue(propPath, coercedVal); } Reference ref = getRequest().getResourceRef(); ref.setPath(getBeansRefPath()); ref.addSegment(beanPath); getResponse().redirectSeeOther(ref); }
public static void main(String[] args) throws IOException, ResourceException { ClientResource itemsResource = new ClientResource( "http://localhost:8111/firstResource/items"); ClientResource itemResource = null; Representation r = itemsResource.post(getRepresentation(item)); itemResource = new ClientResource(r.getLocationRef()); } catch (ResourceException e) { System.out.println("Error status: " + e.getStatus()); System.out.println("Error message: " + e.getMessage());
@Test public void testGetAuditLogAuthenticatedNonAdminRdfJson() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); try { RestletTestUtils.doTestAuthenticatedRequest(creationClientResource, Method.GET, null, RestletUtilMediaType.APPLICATION_RDF_JSON, Status.SUCCESS_OK, this.testNoAdminPrivileges); Assert.fail("Did not receive expected exception"); } catch(final ResourceException rex) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, rex.getStatus()); } }
/** * Test whether Ontologies can be deleted after creating the ontology using an RDF/XML file. * * Specifically tests deletion with only the ontologyUri and no managedOntologyVersionUri * parameter. * */ @Test public void testOntologyDeleteNoUploadWithDeleteAllFalse() { try { final ClientResource deletionClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_ONTOLOGY_MANAGER_DELETE_PATH, OasProps.DEF_ONTOLOGY_MANAGER_DELETE_PATH))); deletionClientResource.getReference().addQueryParameter("ontologyUri", "http://purl.org/obo/owl/test"); deletionClientResource.getReference().addQueryParameter("deleteAllVersions", "true"); RestletTestUtils.doTestAuthenticatedRequest(deletionClientResource, Method.POST, null, MediaType.TEXT_PLAIN, Status.SUCCESS_NO_CONTENT, this.testWithAdminPrivileges); Assert.fail("Did not find expected exception while attempting to call the delete service with just an ontology URI"); } catch(final ResourceException ex) { Assert.assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, ex.getStatus()); } }
/** * Posts an object entity. Automatically serializes the object using the * {@link org.restlet.service.ConverterService}. * * @param entity * The object entity to post. * @return The optional result entity. * @throws ResourceException * @see <a * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5">HTTP * POST method</a> */ public Representation post(Object entity) throws ResourceException { try { return post(toRepresentation(entity)); } catch (IOException e) { throw new ResourceException(e); } }
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)"); } } }
/** * Puts an object entity. Automatically serializes the object using the * {@link org.restlet.service.ConverterService}. * * @param entity * The object entity to put. * @return The optional result entity. * @throws ResourceException * @see <a * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6">HTTP * PUT method</a> */ public Representation put(Object entity) throws ResourceException { try { return put(toRepresentation(entity)); } catch (IOException e) { throw new ResourceException(e); } }
er = (EditRepresentation) getVariants().get(0); } catch (ClassCastException cce) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "File modification should use either PUT or " + "POST with a '?format=textedit' query-string."); Reference ref = getRequest().getOriginalRef().clone(); getResponse().redirectSeeOther(ref);
/** * 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); } }