To add to the @Eric Stein's response, having regex in @Path will result in 404 without execution reaching filter methods. So validation has to be pushed inside the filter method.
In order to abort the call and return the customized response from filter used below code.
//groovy code
class MyCustomFilter implements ContainerRequestFilter
{
@Override
public ContainerRequest filter(ContainerRequest request) {
//do the validation for the resource URI and abort flow for errors
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity("Not valid input").build())
...
..
//for success scenarios, return the request with optional customization
return request;
}
}
@ResourceFilters(MyCustomFilter)
@Path('/users/{userId}/scripts')
class MyJaxRsResource {
}