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

Method Parameters are only validated on first invocation of an ejb managed rest endpoint

XMLWordPrintable

    • Hide

      1. Create a rest endpoint with method parameter validation and annotate as an ejb managed bean

      @Stateless
      @Path("/foo")
      public class FooRest {
      ...
      @POST
      @Path("/bar")
      @Consumes(MediaType.APPLICATION_JSON)
      public void addBar(@Valid Bar bar) throws Exception {

      2. Deploy the rest endpoint in a JEE application server
      3. Call the /foo/bar endpoint with an invalid Bar object, the http response code should be 400
      4. Make subsequent calls the to /foo/bar endpoint, the http response code will be 500 until the application is redeployed/ app server restarted

      Show
      1. Create a rest endpoint with method parameter validation and annotate as an ejb managed bean @Stateless @Path("/foo") public class FooRest { ... @POST @Path("/bar") @Consumes(MediaType.APPLICATION_JSON) public void addBar(@Valid Bar bar) throws Exception { 2. Deploy the rest endpoint in a JEE application server 3. Call the /foo/bar endpoint with an invalid Bar object, the http response code should be 400 4. Make subsequent calls the to /foo/bar endpoint, the http response code will be 500 until the application is redeployed/ app server restarted

      In a CDI context; when a rest endpoint has parameter validation defined and is also defined as an ejb managed bean, only the first invocation of the endpoint will call the validation code path for validating the rest method parameters. Subsequent calls to the endpoint will not be validated by resteasy/CDI and will only be validated by the CDI context, which may not handle any ConstraintValidationExceptions correctly. In Wildlfly/EAP this manifests itself with the rest endpoint correctly returning a HTTP 400 (Bad Request) status on the first invocation, but subsequent invocations return a HTTP 500 (Internal Server Error) status.

        1. EJBCDIValidationApplication.java
          0.5 kB
          Ronald Sigal
        2. EJBCDIValidationSingletonResource.java
          0.8 kB
          Ronald Sigal
        3. EJBCDIValidationStatefulResource.java
          0.8 kB
          Ronald Sigal
        4. EJBCDIValidationStatelessResource.java
          0.8 kB
          Ronald Sigal
        5. EJBCDIValidationTest.java
          6 kB
          Ronald Sigal

              rsigal@redhat.com Ronald Sigal
              johara@redhat.com John O'Hara
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: