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); } }
public Representation represent(Variant variant) throws ResourceException { if (appCtx == null) { throw new ResourceException(404); } Representation representation; if (variant.getMediaType() == MediaType.APPLICATION_XML) { representation = new WriterRepresentation(MediaType.APPLICATION_XML) { public void write(Writer writer) throws IOException { XmlMarshaller.marshalDocument(writer, "beans", makeDataModel()); } }; } else { representation = new WriterRepresentation( MediaType.TEXT_HTML) { public void write(Writer writer) throws IOException { BeanBrowseResource.this.writeHtml(writer); } }; } // TODO: remove if not necessary in future? representation.setCharacterSet(CharacterSet.UTF_8); return representation; }
public Representation represent(Variant variant) throws ResourceException { if (cj == null) { throw new ResourceException(404); } Representation representation = null; if (variant.getMediaType() == MediaType.APPLICATION_XML) { representation = new WriterRepresentation(MediaType.APPLICATION_XML) { public void write(Writer writer) throws IOException { CrawlJobModel model = makeDataModel(); model.put("heapReport", getEngine().heapReportData()); XmlMarshaller.marshalDocument(writer, "job", model); } }; } else { representation = new WriterRepresentation(MediaType.TEXT_HTML) { public void write(Writer writer) throws IOException { JobResource.this.writeHtml(writer); } }; } // TODO: remove if not necessary in future? // honor requested charset? representation.setCharacterSet(CharacterSet.UTF_8); return representation; }
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)"); } } }
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); }
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.");
throws ResourceException { if (cj == null) { throw new ResourceException(404);
public void warning(SAXParseException exception) throws SAXException { throw new ResourceException(exception); } });
/** * By default, it throws a new resource exception. * * @param errorStatus * The error status received. */ @Override public void doError(Status errorStatus) { throw new ResourceException(errorStatus, this); }
static void validateEmail( final String email ) throws ResourceException { if ( StringUtils.isEmpty( email ) ) { throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "E-mail address cannot be empty" ); } if ( !EMAIL_PATTERN.matcher( email ).matches() ) { throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "Invalid e-mail address: " + email ); } }
static void validateEmail(final String email) throws ResourceException { if (StringUtils.isEmpty(email)) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "E-mail address cannot be empty"); } if (!EMAIL_PATTERN.matcher(email).matches()) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid e-mail address: " + email); } }
private ReferenceList tryToConvertAsReferenceList(Representation entity) throws ResourceException { try { return new ReferenceList(entity); } catch (IOException e) { throw new ResourceException(e); } }
private void result( Object resultValue ) throws Exception { if( resultValue != null ) { if( !responseWriter.writeResponse( resultValue, Response.getCurrent() ) ) { throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "No result writer for type " + resultValue.getClass() .getName() ); } } }
@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); } }
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); } }
@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { List<? extends Variant> variants; try { Variant targetVariant = new Variant(toRestletMediaType(mediaType)); variants = getConverterService().getVariants(type, targetVariant); } catch (IOException e) { throw new ResourceException(e); } return (variants != null) && !variants.isEmpty(); }
/** * 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); } }
protected <T> T selectFromManyAssociation( ManyAssociation<T> manyAssociation, Identity id ) throws ResourceException { T entity = (T) uowf.currentUnitOfWork().get( Object.class, id ); if( !manyAssociation.contains( entity ) ) { throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND ); } current().select( entity ); return entity; }
protected <T> T selectFromNamedAssociation( NamedAssociation<T> namedAssociation, String id ) throws ResourceException { T entity = (T) module.currentUnitOfWork().get( Object.class, id ); String name = namedAssociation.nameOf( entity ); if(name == null) { throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND ); } current().select( entity ); return entity; }
protected <T> T selectFromManyAssociation( ManyAssociation<T> manyAssociation, String id ) throws ResourceException { T entity = (T) module.currentUnitOfWork().get( Object.class, id ); if( !manyAssociation.contains( entity ) ) { throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND ); } current().select( entity ); return entity; }