Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-19500

HttpMessage#getBody(Map.class) doesn't parse the regular web form POST

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Information Provided
    • 3.20.4
    • None
    • came-core, camel-jetty
    • None
    • Moderate

    Description

      In Camel 2, when the form was submitted, the payload was able to be presented as a java.util.Map like this:

       

      Map map = httpMessage.getBody(Map.class);

      In Camel 3.20.4 this doesn't work.

       

      I've created a little github project to demonstrate and reproduce the error. In the project's pom.xml file you can easily switch the Camel versions to see how version 2.24.0 behaves as expected in a true Camel manner, and 3.20.4 does not.

      In essence, the code to check the behavior is like below. form.html is a simplest POST web form.

      
                              HttpMessage http = exchange.getIn(HttpMessage.class);
                              HttpServletRequest request = http.getRequest();
                              String method = request.getMethod();
                              if ("POST".equals(method) || "PUT".equals(method)) {
                                  Map map = http.getBody(Map.class);
                                  String string = http.getBody(String.class);
                                  http.setHeader(Exchange.CONTENT_TYPE, "text/plain");
                                  http.setBody("json: " + mapper.writeValueAsString(map) + ", and string:" + string);
                              } else {
                                  http.setHeader(Exchange.CONTENT_TYPE, "text/html");
      http.setBody(this.getClass().getResourceAsStream("form.html"));
                              } 
      

      It should print the jsonified form POST payload, but doesn't for the Camel 3.

      Attachments

        Activity

          People

            Unassigned Unassigned
            fedd Fyodor Kravchenko
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: