public MethodNotAllowedException(Reference uri, Method method) { super( Status.CLIENT_ERROR_METHOD_NOT_ALLOWED.getCode(), String.format("Method %s not allowed", method), String.format("Method %s not allowed to %s", method.getName(), uri), null); }
/** * Handles any call to this resource. The default implementation check the {@link * #isConditional()} and {@link #isNegotiated()} method to determine which one of the {@link * #doConditionalHandle()}, {@link #doNegotiatedHandle()} and {@link #doHandle()} methods should * be invoked. It also catches any {@link ResourceException} thrown and updates the response * status using the {@link #setStatus(Status, Throwable, String)} method.<br> * <br> * After handling, if the status is set to {@link Status#CLIENT_ERROR_METHOD_NOT_ALLOWED}, then * {@link #updateAllowedMethods()} is invoked to give the resource a chance to inform the client * about the allowed methods. * * @return The response entity. */ @Override public Representation handle() { Representation result = null; // If the resource is not available after initialization and if this a // retrieval method, then return a "not found" response. if (!isExisting() && getMethod().isSafe()) { setStatus(Status.CLIENT_ERROR_NOT_FOUND); } else { try { if (isConditional()) { result = doConditionalHandle(); } else if (isNegotiated()) { result = doNegotiatedHandle(); } else { result = doHandle(); } if (!getResponse().isEntityAvailable()) { // If the user manually set the entity, keep it getResponse().setEntity(result); } if (Status.CLIENT_ERROR_METHOD_NOT_ALLOWED.equals(getStatus())) { updateAllowedMethods(); } else if (Method.GET.equals(getMethod()) && Status.SUCCESS_OK.equals(getStatus()) && (getResponseEntity() == null || !getResponseEntity().isAvailable())) { getLogger() .fine( "A response with a 200 (Ok) status should have an entity. Changing the status to 204 (No content)."); setStatus(Status.SUCCESS_NO_CONTENT); } } catch (Throwable t) { doCatch(t); } } return result; }