/** * Returns the first annotation descriptor matching the given method. * * @param method * The method to match. * @return The annotation descriptor. * @throws IOException */ private MethodAnnotationInfo getAnnotation(Method method) throws IOException { return getAnnotation(method, getQuery(), null); }
if (getAnnotation(method) != null) { MethodAnnotationInfo annotationInfo = getAnnotation(method, query, entity);
/** * Returns a descriptor of the response entity returned by a {@link Method#GET} call. * * @return The response entity. * @throws ResourceException */ private RepresentationInfo doGetInfo() throws ResourceException { RepresentationInfo result = null; MethodAnnotationInfo annotationInfo; try { annotationInfo = getAnnotation(Method.GET); if (annotationInfo != null) { result = doHandle(annotationInfo, null); } else { result = getInfo(); } } catch (IOException e) { throw new ResourceException(e); } return result; }
/** * Deletes the resource and all its representations. This method is only * invoked if content negotiation has been disabled as indicated by the {@link #isNegotiated()}, otherwise the * {@link #delete(Variant)} method is * invoked.<br> * <br> * The default behavior is to set the response status to * {@link org.restlet.data.Status#CLIENT_ERROR_METHOD_NOT_ALLOWED}. * * @return The optional response entity. * @throws ResourceException * @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7" >HTTP DELETE method</a> */ protected Representation delete() throws ResourceException { Representation result = null; MethodAnnotationInfo annotationInfo; try { annotationInfo = getAnnotation(Method.DELETE); if (annotationInfo != null) { result = doHandle(annotationInfo, null); } else { doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } } catch (IOException e) { throw new ResourceException(e); } return result; }
/** * Returns a full representation. This method is only invoked if content * negotiation has been disabled as indicated by the {@link #isNegotiated()} , otherwise the {@link #get(Variant)} * method is invoked.<br> * <br> * The default behavior is to set the response status to * {@link org.restlet.data.Status#CLIENT_ERROR_METHOD_NOT_ALLOWED}. * * @return The resource's representation. * @throws ResourceException * @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3">HTTP GET method</a> */ protected Representation get() throws ResourceException { Representation result = null; MethodAnnotationInfo annotationInfo; try { annotationInfo = getAnnotation(Method.GET); if (annotationInfo != null) { result = doHandle(annotationInfo, null); } else { doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } } catch (IOException e) { throw new ResourceException(e); } return result; }
/** * Indicates the communication options available for this resource. This * method is only invoked if content negotiation has been disabled as * indicated by the {@link #isNegotiated()}, otherwise the {@link #options(Variant)} method is invoked.<br> * <br> * The default behavior is to set the response status to * {@link org.restlet.data.Status#CLIENT_ERROR_METHOD_NOT_ALLOWED}. * * @return The optional response entity. */ protected Representation options() throws ResourceException { Representation result = null; MethodAnnotationInfo annotationInfo; try { annotationInfo = getAnnotation(Method.OPTIONS); // Updates the list of allowed methods updateAllowedMethods(); if (annotationInfo != null) { result = doHandle(annotationInfo, null); } else { doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } } catch (IOException e) { throw new ResourceException(e); } return result; }
/** * Apply a patch entity to the current representation of the resource * retrieved by calling {@link #get()}. By default, the * {@link ConverterService#applyPatch(Representation, Representation)} method is used and then the * {@link #put(Representation)} method called. * * @param entity * The patch entity to apply. * @return The optional result entity. * @throws ResourceException * @see <a href="https://tools.ietf.org/html/rfc5789">HTTP PATCH method</a> */ protected Representation patch(Representation entity) throws ResourceException { AnnotationInfo annotationInfo; try { annotationInfo = getAnnotation(Method.PATCH); if (annotationInfo != null) { return doHandle(Method.PATCH, getQuery(), entity); } else { // Default implementation return put(getConverterService().applyPatch(get(), entity)); // doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } } catch (IOException e) { throw new ResourceException(e); } }