title: Is it possible to put a constraint on a jersey REST method?
body: <p>I would like to do a check to see if we have "turned off" a particular endpoint. Currently it is implemented via a ContainerRequestFilter. But since I can't directly hook into a filter at the controller/resource level (as far as I know) then the best I can do is throw an exception from the filter which is then returned to the client and I would rather the client see a formatted json error response instead of a stack trace.</p>
  
  <p>I implemented the following constraint interface and class:</p>
  
  <pre><code>@NotNull
  @Target({METHOD, FIELD, ANNOTATION_TYPE, PARAMETER})
  @Retention(RUNTIME)
  @Constraint(validatedBy = MethodNotImplementedImpl.class)
  @Documented
  public @interface MethodNotImplemented {
      String message() default "{Default message}";
      Class&lt;?&gt;[] groups() default {};
      Class&lt;? extends Payload&gt;[] payload() default {};
  }
  
  public class MethodNotImplementedImpl implements ConstraintValidator&lt;MethodNotImplemented, UriInfo&gt;  {
      public void initialize(MethodNotImplemented constraintAnnotation) {logger.debug("init called");}
      public boolean isValid(UriInfo uriInfo, ConstraintValidatorContext constraintContext) {
          logger.debug("validate called");
          return true;
      }
  }
  </code></pre>
  
  <p>I would like to have each rest method then execute the constraint, but the constraint is not firing.  </p>
  
  <pre><code>@Validated
  @Path("/people")
  public class PeopleController extends BaseController {
  @GET
  @Path("/{peopleId}")
  @Produces(MediaType.APPLICATION_JSON)
  public Response getPeople(@MethodNotImplemented @Context UriInfo uriInfo,
                            @PathParam("peopleId") String peopleId,
                            @DefaultValue("") @QueryParam("fields") String partialResponseFields) {
  ....
  </code></pre>
  
  <p>Everything compiles and deploys fine, but neither the init or isValid methods are being called when the end point is called. I have other method level constraints set on POJOs in my app and they automatically fire when the method is called. Is what I'm trying to do possible? If so, what am I doing wrong?</p>