Wicket
  1. Wicket
  2. WICKET-4375

Reading body of the request in AbstractDefaultAjaxBehavior

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Not a Problem
    • Affects Version/s: 1.5.4
    • Fix Version/s: None
    • Component/s: wicket
    • Labels:

      Description

      If you want to read the body of the request you will get null from 1.5.4 (I've tried 1.5.4 and 1.5-SNAPSHOT). In 1.5.3 it works as expected. I'll upload a quickstart.

      1. myproject.zip
        22 kB
        Bálint Kriván

        Issue Links

          Activity

          Hide
          Martin Grigorov added a comment -

          Wicket reads the servlet input stream for you. Now you can use Request#getRequestParameters() to read both GET and POST parameters, or #getQueryParameters() to read just GET/query string parameters, or #getPostParameters() to read all POST (coming from the servlet input stream).
          Since the input stream is already read it is empty when you try to read it again.
          All these methods return an object from which you can read name/value pairs.

          Show
          Martin Grigorov added a comment - Wicket reads the servlet input stream for you. Now you can use Request#getRequestParameters() to read both GET and POST parameters, or #getQueryParameters() to read just GET/query string parameters, or #getPostParameters() to read all POST (coming from the servlet input stream). Since the input stream is already read it is empty when you try to read it again. All these methods return an object from which you can read name/value pairs.
          Hide
          Bálint Kriván added a comment -

          So basically now I only can read the request body as the key of the last item of PostParameters?
          Is this the expected behavior?

          Show
          Bálint Kriván added a comment - So basically now I only can read the request body as the key of the last item of PostParameters? Is this the expected behavior?
          Hide
          Martin Grigorov added a comment -

          The reason is that now you can read POST parameters in PageParameters: https://issues.apache.org/jira/browse/WICKET-4338.

          Here is a solution for your need:

          @Override
          protected void respond(final AjaxRequestTarget target) {
          HttpServletRequest req = (HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest();
          try {
          Request request = RequestCycle.get().getRequest();
          IRequestParameters requestParameters = request.getPostParameters();
          for (String paramName : requestParameters.getParameterNames())
          {
          List<StringValue> parameterValues = requestParameters.getParameterValues(paramName);
          for (StringValue value : parameterValues)

          { System.err.println(paramName + " -> " + value); }

          }
          BufferedReader in = new BufferedReader(new InputStreamReader(req.getInputStream()));
          target.appendJavaScript("alert('" + in.readLine() + "')");
          } catch (IOException ex)

          { Logger.getLogger(AjaxBehavior.class.getName()).log(Level.SEVERE, null, ex); }

          }

          Show
          Martin Grigorov added a comment - The reason is that now you can read POST parameters in PageParameters: https://issues.apache.org/jira/browse/WICKET-4338 . Here is a solution for your need: @Override protected void respond(final AjaxRequestTarget target) { HttpServletRequest req = (HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest(); try { Request request = RequestCycle.get().getRequest(); IRequestParameters requestParameters = request.getPostParameters(); for (String paramName : requestParameters.getParameterNames()) { List<StringValue> parameterValues = requestParameters.getParameterValues(paramName); for (StringValue value : parameterValues) { System.err.println(paramName + " -> " + value); } } BufferedReader in = new BufferedReader(new InputStreamReader(req.getInputStream())); target.appendJavaScript("alert('" + in.readLine() + "')"); } catch (IOException ex) { Logger.getLogger(AjaxBehavior.class.getName()).log(Level.SEVERE, null, ex); } }
          Hide
          Bálint Kriván added a comment -

          The quickstart project which shows the problem. If you use 1.5.3 when you click the button you'll see an alert with '1.5.3', if you use 1.5.4+ you will see null.

          Show
          Bálint Kriván added a comment - The quickstart project which shows the problem. If you use 1.5.3 when you click the button you'll see an alert with '1.5.3', if you use 1.5.4+ you will see null.

            People

            • Assignee:
              Unassigned
              Reporter:
              Bálint Kriván
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development