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

camel restlet not populating body form parameters correctly for x-www-form-urlencoded

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.17.1
    • 2.17.2, 2.18.0
    • camel-restlet
    • None
    • Unknown

    Description

      Currently for x-www-form-urlencoded post request camel puts the body into a form key with a null value:

      if ((Method.PUT == method || Method.POST == method) && MediaType.APPLICATION_WWW_FORM.equals(mediaType, true)) {
                  form = new Form();
                  // must use string based for forms
                  String body = exchange.getIn().getBody(String.class);
                  if (body != null) {
                      form.add(body, null);
                  }
              }
      

      Which results in a body like this:

      name=jay&password=secret

      ending up with a form parameter looking like this:
      name%3Djay%26password%3Dsecret=null

      I think something like this should be used to correctly set the key values.

      if ((Method.PUT == method || Method.POST == method) && MediaType.APPLICATION_WWW_FORM.equals(mediaType, true)) {
                  form = new Form();
                  // must use string based for forms
                  String body = exchange.getIn().getBody(String.class);
                  if (body != null) {
                      List<NameValuePair> pairs = URLEncodedUtils.parse(body, Charset.forName("UTF-8"));
                      for(NameValuePair p : pairs){
                      	form.add(p.getName(), p.getValue());
                      }
                  }
              }
      

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            jmandawg Jay mann
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: