Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1186

Constraint violations produced by invalid parameters of a JAXRS resource method are not immediately returned in the Response returned by the method, causing business methods to be called with invalid values.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.1.0.Beta1, 3.0.20.Final
    • 3.0.10.Final
    • jaxrs
    • None
    • Hide

      public class QueryBeanParam {

      @Size(min = 1)
      @QueryParam("foo")
      private String param;

      public String getParam()

      { return param; }

      }

      public interface ValidResource

      { Response getAll(@Valid QueryBeanParam beanParam); }

      public class RootResource implements ValidResource {

      @GET
      @Override
      public Response getAll(@BeanParam QueryBeanParam beanParam)

      { System.out.println("beanParam invalid value: " + beanParam.getParam()); // the line above is still called even with an invalid value passed to //beanParam#getparam, but the returned Response contains the list of //violations. return Response.ok().build(); }

      }

      public class ValidRootResource {

      @GET
      public Response getAll(@Valid @BeanParam QueryBeanParam beanParam)

      { System.out.println("beanParam invalid value: " + beanParam.getParam()); // the line above is NOT called, as expected, when an invalid value is //passed to //beanParam#getparam. Notice the @Valid annotation is placed //on the class and not on any interface return Response.ok().build(); }

      }

      Show
      public class QueryBeanParam { @Size(min = 1) @QueryParam("foo") private String param; public String getParam() { return param; } } public interface ValidResource { Response getAll(@Valid QueryBeanParam beanParam); } public class RootResource implements ValidResource { @GET @Override public Response getAll(@BeanParam QueryBeanParam beanParam) { System.out.println("beanParam invalid value: " + beanParam.getParam()); // the line above is still called even with an invalid value passed to //beanParam#getparam, but the returned Response contains the list of //violations. return Response.ok().build(); } } public class ValidRootResource { @GET public Response getAll(@Valid @BeanParam QueryBeanParam beanParam) { System.out.println("beanParam invalid value: " + beanParam.getParam()); // the line above is NOT called, as expected, when an invalid value is //passed to //beanParam#getparam. Notice the @Valid annotation is placed //on the class and not on any interface return Response.ok().build(); } }

      When a JAXRS resource class implements an interface containing Bean Validation constraints on method parameters, any constraint violations caught by the registered ExceptionMapper are not throw until the method returns, allowing the method to continue with invalid parameter values. When the Bean Validation constraints are placed directly on the JAXRS class methods instead of on an implemented interface, the method behaves as expected by immediately returning a Response containing the violations.

        1. AsyncTestResources.java
          2 kB
          Eric Taylor
        2. AsyncTestResources.java
          2 kB
          Eric Taylor
        3. AsyncTestResources.java
          2 kB
          Eric Taylor
        4. RESTEASY-TEST-WF8.tgz
          6.60 MB
          Ronald Sigal
        5. TestInterfaceMethodConstraints.java
          6 kB
          Ronald Sigal
        6. TestResources.java
          1 kB
          Eric Taylor

              rsigal@redhat.com Ronald Sigal
              etayjboss99 Eric Taylor (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: