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

Reading the input stream in a Pre-process interceptor should not result in @FormParam parameters being null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 6.2.2.Final
    • 2.2.0.GA, 2.2.1, 4.0.0.Beta7, 3.6.3.Final
    • jaxrs
    • None
    • Hide
      @Provider
      public class CustomContainerRequestFilter implements ContainerRequestFilter {
          @Override
          public void filter(ContainerRequestContext requestContext) throws IOException {
              System.out.println("Filter applied");
              InputStream is = requestContext.getEntityStream();
              requestContext.setEntityStream(is);
          }
      }
      @Path("/")
      public class Resource {
          @POST
          @Path("a")
          public String a(@FormParam("fp") String fp) {
              System.out.println(fp);
              return fp;
          }
      }
      
      <!DOCTYPE html><html><head><meta charset="UTF-8"></head><body>
      <form action="http://localhost:8080/jaxrs-wf/a" method="post" enctype="application/x-www-form-urlencoded">
          <input type="input" name="fp" id="key"><br>
          <input type="submit" value="Upload" name="submit">
      </form></body></html>
      
      Show
      @Provider public class CustomContainerRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { System .out.println( "Filter applied" ); InputStream is = requestContext.getEntityStream(); requestContext.setEntityStream(is); } } @Path( "/" ) public class Resource { @POST @Path( "a" ) public String a(@FormParam( "fp" ) String fp) { System .out.println(fp); return fp; } } <!DOCTYPE html> <html> <head> <meta charset= "UTF-8" > </head> <body> <form action= "http://localhost:8080/jaxrs-wf/a" method= "post" enctype= "application/x-www-form-urlencoded" > <input type= "input" name= "fp" id= "key" > <br> <input type= "submit" value= "Upload" name= "submit" > </form> </body> </html>

      If you have a PreProcessInterceptor that calls getInputStream on the Request object in the preProcess method all the @FormParam method attributes end up being null. Even if you create another stream that wraps the original one or the contents of the original one say by using an ByteArrayInputStream and call setInputStream() on the request object the problem still persists.

      I realize that calling setStream() doesn't override the HtppServletRequest stream but I would think that the parsing for the parameters would be done on the wrapped stream that the resteasy request abstraction contains.

      Resteasy Interceptors should be able to provide :

      • Repeatable Inputstreams for incoming requests so that multiple interceptors can read and change it if desired
      • Resteasy services should be able to use @FormParam , @QueryParam annotations. (i.e Paramater marshalling should work fine) while using interceptors.

      I realize that there are some limitations that servlet containers such as Tomcat impose for eg. on Tomcat if you've read the input stream using getInputStream() on a request object then the getParameters*() methods no longer return anythings and vice versa. However, I would think that since Resteasy already provides an abstraction layer over the HttpServletRequest it should be able to take care of that issue by always parsing the input stream and then retrieving the parameters from that stream.

              rsearls r searls
              yousuf.raza Yousuf Haider (Inactive)
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: