@Override protected void doError(Status status) { if (status.equals(Status.CLIENT_ERROR_NOT_ACCEPTABLE) && (status.getThrowable() == null)) { // we have an ontopia error for this List<Preference<MediaType>> acceptedMediaTypes = getClientInfo().getAcceptedMediaTypes(); List<MediaType> accepted = new ArrayList<>(acceptedMediaTypes.size()); for (Preference<MediaType> mt : acceptedMediaTypes) { accepted.add(mt.getMetadata()); } super.doError(OntopiaRestErrors.UNSUPPORTED_MIME_TYPE.build(getClass().getName(), Arrays.toString(accepted.toArray())).getStatus()); } else { super.doError(status); } }
/** * Returns a full representation for a given variant. A variant parameter is * passed to indicate which representation should be returned if any.<br> * <br> * This method is only invoked if content negotiation has been enabled as * indicated by the {@link #isNegotiated()}, otherwise the {@link #get()} 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}.<br> * * @param variant * The variant whose full representation must be returned. * @return The resource's representation. * @see #get(Variant) * @throws ResourceException */ protected Representation get(Variant variant) throws ResourceException { Representation result = null; if (variant instanceof VariantInfo) { result = doHandle(((VariantInfo) variant).getAnnotationInfo(), variant); } else { doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } return result; }
/** * Deletes the resource and all its representations. A variant parameter is * passed to indicate which representation should be returned if any.<br> * <br> * This method is only invoked if content negotiation has been enabled as * indicated by the {@link #isNegotiated()}, otherwise the {@link #delete()} 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}. * * @param variant * The variant of the response entity. * @return The optional response entity. * @throws ResourceException * @see #get(Variant) * @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7" >HTTP DELETE method</a> */ protected Representation delete(Variant variant) throws ResourceException { Representation result = null; if (variant instanceof VariantInfo) { result = doHandle(((VariantInfo) variant).getAnnotationInfo(), variant); } else { doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } return result; }
/** * Posts a representation to the resource at the target URI reference. A * variant parameter is passed to indicate which representation should be * returned if any.<br> * <br> * This method is only invoked if content negotiation has been enabled as * indicated by the {@link #isNegotiated()}, otherwise the {@link #post(Representation)} 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}.<br> * * @param entity * The posted entity. * @param variant * The variant of the response entity. * @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> */ protected Representation post(Representation entity, Variant variant) throws ResourceException { Representation result = null; if (variant instanceof VariantInfo) { result = doHandle(((VariantInfo) variant).getAnnotationInfo(), variant); } else { doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } return result; }
variant); } else { doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
/** * Indicates the communication options available for this resource. A * variant parameter is passed to indicate which representation should be * returned if any.<br> * <br> * This method is only invoked if content negotiation has been enabled as * indicated by the {@link #isNegotiated()}, otherwise the {@link #options()} 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}.<br> * * @param variant * The variant of the response entity. * @return The optional response entity. * @see #get(Variant) */ protected Representation options(Variant variant) throws ResourceException { Representation result = null; // Updates the list of allowed methods updateAllowedMethods(); if (variant instanceof VariantInfo) { result = doHandle(((VariantInfo) variant).getAnnotationInfo(), variant); } else { doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } 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; }
/** * 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; }
/** * 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; }
doError(Status.CLIENT_ERROR_NOT_ACCEPTABLE); result = describeVariants(); } else {
doError(Status.CLIENT_ERROR_NOT_ACCEPTABLE); } else { resultInfo = doGetInfo(preferredVariant); || (getStatus().isSuccess() && !Status.SUCCESS_NO_CONTENT .equals(getStatus()))) { doError(Status.CLIENT_ERROR_NOT_FOUND); } else { doError(status); } else { setStatus(status); doError(status); } else { setStatus(status);
doError(Status.CLIENT_ERROR_NOT_FOUND); } else { try {
doError(Status.CLIENT_ERROR_NOT_FOUND);