Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-18381

[GSS](7.2.z) JSF request is always handled as @MultipartConfig

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not a Bug
    • Major
    • None
    • 7.2.5.GA
    • JSF, Undertow
    • None
    • +
    • Hide

      Reproducer

      jsf-test.war
       ├── META-INF
       │   └── MANIFEST.MF
       ├── test1
       │   ├── view1.xhtml
       │   └── view2.xhtml
       ├── test2
       │   ├── view1.xhtml
       │   └── view2.xhtml
       └── WEB-INF
           ├── classes
           │   └── test
           │       └── filter
           │           ├── TestFilter1.class
           │           ├── TestFilter1.java
           │           ├── TestFilter2.class
           │           └── TestFilter2.java
           └── faces-config.xml
      

      view1.xhtml

      <h:form method="post" enctype="multipart/form-data">
      <input type="text" name ="test" value="Hello World" /><br />
      <h:commandButton action="view2?faces-redirect=true" value="OK" />
      </h:form>
      

      TestFilter1.java

      @WebFilter(filterName="/TestFilter1", urlPatterns="/test1/*")
      public class TestFilter1 implements Filter {
      
          public TestFilter1() {
          }
      
          @Override
      	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
      		String test = request.getParameter("test");
      		System.out.println("[TestFilter1] getParameter: " + test);
      		InputStream is = request.getInputStream();
      		BufferedReader br = new BufferedReader(new InputStreamReader(is));
      		StringBuilder sb = new StringBuilder();
      		String line;
      		while((line=br.readLine()) != null) {
      			sb.append(line);
      		}
      		System.out.println("[TestFilter1] data : " + sb.toString());
      		chain.doFilter(request, response);
      	}
      

      TestFilter2.java

      @WebFilter(filterName="/TestFilter2", urlPatterns="/test2/*")
      public class TestFilter2 implements Filter {
      
          public TestFilter2() {
          }
      
          @Override
      	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
      //		String test = request.getParameter("test");
      //		System.out.println("[TestFilter2] getParameter: " + test);
      		InputStream is = request.getInputStream();
      		BufferedReader br = new BufferedReader(new InputStreamReader(is));
      		StringBuilder sb = new StringBuilder();
      		String line;
      		while((line=br.readLine()) != null) {
      			sb.append(line);
      		}
      		System.out.println("[TestFilter2] data : " + sb.toString());
      		chain.doFilter(request, response);
      	}
      

      Steps to reproduce
      1. Install JBoss EAP 7.2.x.
      2. Deploy jsf-test.war.
      3. Start JBoss EAP 7.2.x.
      4. Open http://localhost:8080/jsf-test/test1/view1.jsf, and push the OK button.
      5. You can confirm following log. Cannot get data from the request.getInputStream after executing the request.getParameter.

      ... INFO  [stdout] (default task-1) [TestFilter1] getParameter: Hello World
      ... INFO  [stdout] (default task-1) [TestFilter1] data : 
      

      6. Open http://localhost:8080/jsf-test/test2/view1.jsf, and push the OK button.
      7. You can confirm following log. Can get data from the request.getInputStream.

      ... INFO  [stdout] (default task-2) [TestFilter2] data : -----------------------------102717302214260925561788403611Content-Disposition: form-data; name="j_idt2"j_idt2-----------------------------102717302214260925561788403611Con
      tent-Disposition: form-data; name="test"Hello World-----------------------------102717302214260925561788403611Content-Disposition: form-data; name="j_idt2:j_idt4"OK-----------------------------102717302214260925561788403611Content-Disposi
      tion: form-data; name="javax.faces.ViewState"6982119878971111865:-4806937494061635936-----------------------------102717302214260925561788403611--
      

      EAP 6.x was able to get data from the request.getInputStream on both sides.
      http://localhost:8080/jsf-test/test1/view1.jsf

      ... INFO  [stdout] (http-/127.0.0.1:8080-1) [TestFilter1] getParameter: null
      ... INFO  [stdout] (http-/127.0.0.1:8080-1) [TestFilter1] data : -----------------------------1244117181192881501337824920Content-Disposition: form-data; name="j_idt2"j_idt2-----------------------------124411718119288150133782492
      0Content-Disposition: form-data; name="test"Hello World-----------------------------1244117181192881501337824920Content-Disposition: form-data; name="j_idt2:j_idt4"OK-----------------------------1244117181192881501337824920Content-Disposi
      tion: form-data; name="javax.faces.ViewState"-277622239774063328:5178182055776598952-----------------------------1244117181192881501337824920--
      

      http://localhost:8080/jsf-test/test2/view1.jsf

      ... INFO  [stdout] (http-/127.0.0.1:8080-1) [TestFilter2] data : -----------------------------17689548225219902321857563999Content-Disposition: form-data; name="j_idt2"j_idt2-----------------------------17689548225219902321857563
      999Content-Disposition: form-data; name="test"Hello World-----------------------------17689548225219902321857563999Content-Disposition: form-data; name="j_idt2:j_idt4"OK-----------------------------17689548225219902321857563999Content-Dis
      position: form-data; name="javax.faces.ViewState"4797685529791050436:3755908304267196653-----------------------------17689548225219902321857563999--
      
      Show
      Reproducer jsf-test.war ├── META-INF │   └── MANIFEST.MF ├── test1 │   ├── view1.xhtml │   └── view2.xhtml ├── test2 │   ├── view1.xhtml │   └── view2.xhtml └── WEB-INF ├── classes │   └── test │   └── filter │   ├── TestFilter1.class │   ├── TestFilter1.java │   ├── TestFilter2.class │   └── TestFilter2.java └── faces-config.xml view1.xhtml <h:form method="post" enctype="multipart/form-data"> <input type="text" name ="test" value="Hello World" /><br /> <h:commandButton action="view2?faces-redirect=true" value="OK" /> </h:form> TestFilter1.java @WebFilter(filterName="/TestFilter1", urlPatterns="/test1/*") public class TestFilter1 implements Filter { public TestFilter1() { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String test = request.getParameter("test"); System.out.println("[TestFilter1] getParameter: " + test); InputStream is = request.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line; while((line=br.readLine()) != null) { sb.append(line); } System.out.println("[TestFilter1] data : " + sb.toString()); chain.doFilter(request, response); } TestFilter2.java @WebFilter(filterName="/TestFilter2", urlPatterns="/test2/*") public class TestFilter2 implements Filter { public TestFilter2() { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // String test = request.getParameter("test"); // System.out.println("[TestFilter2] getParameter: " + test); InputStream is = request.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line; while((line=br.readLine()) != null) { sb.append(line); } System.out.println("[TestFilter2] data : " + sb.toString()); chain.doFilter(request, response); } Steps to reproduce 1. Install JBoss EAP 7.2.x. 2. Deploy jsf-test.war . 3. Start JBoss EAP 7.2.x. 4. Open http://localhost:8080/jsf-test/test1/view1.jsf , and push the OK button. 5. You can confirm following log. Cannot get data from the request.getInputStream after executing the request.getParameter. ... INFO [stdout] (default task-1) [TestFilter1] getParameter: Hello World ... INFO [stdout] (default task-1) [TestFilter1] data : 6. Open http://localhost:8080/jsf-test/test2/view1.jsf , and push the OK button. 7. You can confirm following log. Can get data from the request.getInputStream. ... INFO [stdout] (default task-2) [TestFilter2] data : -----------------------------102717302214260925561788403611Content-Disposition: form-data; name="j_idt2"j_idt2-----------------------------102717302214260925561788403611Con tent-Disposition: form-data; name="test"Hello World-----------------------------102717302214260925561788403611Content-Disposition: form-data; name="j_idt2:j_idt4"OK-----------------------------102717302214260925561788403611Content-Disposi tion: form-data; name="javax.faces.ViewState"6982119878971111865:-4806937494061635936-----------------------------102717302214260925561788403611-- EAP 6.x was able to get data from the request.getInputStream on both sides. http://localhost:8080/jsf-test/test1/view1.jsf ... INFO [stdout] (http-/127.0.0.1:8080-1) [TestFilter1] getParameter: null ... INFO [stdout] (http-/127.0.0.1:8080-1) [TestFilter1] data : -----------------------------1244117181192881501337824920Content-Disposition: form-data; name="j_idt2"j_idt2-----------------------------124411718119288150133782492 0Content-Disposition: form-data; name="test"Hello World-----------------------------1244117181192881501337824920Content-Disposition: form-data; name="j_idt2:j_idt4"OK-----------------------------1244117181192881501337824920Content-Disposi tion: form-data; name="javax.faces.ViewState"-277622239774063328:5178182055776598952-----------------------------1244117181192881501337824920-- http://localhost:8080/jsf-test/test2/view1.jsf ... INFO [stdout] (http-/127.0.0.1:8080-1) [TestFilter2] data : -----------------------------17689548225219902321857563999Content-Disposition: form-data; name="j_idt2"j_idt2-----------------------------17689548225219902321857563 999Content-Disposition: form-data; name="test"Hello World-----------------------------17689548225219902321857563999Content-Disposition: form-data; name="j_idt2:j_idt4"OK-----------------------------17689548225219902321857563999Content-Dis position: form-data; name="javax.faces.ViewState"4797685529791050436:3755908304267196653-----------------------------17689548225219902321857563999--

    Description

      A request.getInputstream cannot get multipart data from JSF requests when after executing a request.getParameter.
      It seems that JSF request is always handled as @MultipartConfig. The process of request.getParameter try to get data from the request.getInputstream even if servlet does not mark the @MultipartConfig. Therefore the application cannot get data from request.getInputstream because the input stream already ended.

      https://download.oracle.com/otn-pub/jcp/servlet-3.0-fr-eval-oth-JSpec/servlet-3_0-final-spec.pdf

      3.2 File upload
      If a request is of type multipart/form-data and if the servlet handling the
      request is annotated using the @MultipartConfig as defined in Section 8.1.5,
      “@MultipartConfig” on page 8-64, the HttpServletRequest can make available
      the various parts of the multipart request via the following methods

      ■ public Collection<Part> getParts()
      ■ public Part getPart(String name).

      Each part provides access to the headers, content type related with it and also the
      content via the getInputStream method.

      For parts with form-data as the Content-Disposition, but without a filename,
      the string value of the part will also be available via the getParameter /
      getParameterValues methods on HttpServletRequest, using the name of the
      part.

      Attachments

        Activity

          People

            spyrkob Bartosz Spyrko-Smietanko
            rhn-support-enagai Eiichi Nagai (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: