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

Request with Content-Type= application/x-www-form-urlencoded throws "Cannot read request parameters due Invalid parameter, expected to be a pair but was " when body is empty.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.8.0
    • 2.9.1, 2.10.0
    • camel-http
    • None
    • Unknown

    Description

      ISSUE
      -----------
      When CAMEL Servlet component receiving request with Content-Type= application/x-www-form-urlencoded. as below it throws Cannot read request parameters due Invalid parameter, expected to be a pair but was " when body is empty.

      Request
      ------------
      <html>
      </head>

      <body>
      <form method="post" action="http://test/assertionConsumer/1.0">
      <div>
      <input type="hidden" name="ID" value="fim page" />
      <input type="hidden" name="RelayState" value="http://dev.ecosys.com?count=id-afc417c792b413bd0208e2f7454fd030" />
      <input type="hidden" name="SAMLResponse" value="PHNhbWxwOlJlc3=" />
      </div>
      </form>
      <span id="user_msg"></span>
      <script type="text/javascript">sso();</script>
      </body>
      </html>

      RESOLUTION
      -------------
      Added defensive check, body is not null and not blank, to avoid Invalid parameter exception. I've updated org.apache.camel.component.http.DefaultHttpBinding class for that.

      // Push POST form params into the headers to retain compatibility
      // with DefaultHttpBinding
      String body = message.getBody(String.class);
      //Added defensive check, body is not null and not blank, to avoid Invalid parameter exception. ( My changes)
      if (body != null && !body.equals("")) {
      for (String param : body.split("&")) {
      String[] pair = param.split("=", 2);
      if (pair.length == 2) {
      String name = URLDecoder.decode(pair[0], charset);
      String value = URLDecoder.decode(pair[1], charset);
      if (headerFilterStrategy != null
      && !headerFilterStrategy
      .applyFilterToExternalHeaders(name,
      value, message.getExchange()))

      { HttpHelper.appendHeader(headers, name, value); }

      } else

      { throw new IllegalArgumentException( "Invalid parameter, expected to be a pair but was " + param); }

      }
      }

      Attachments

        1. DefaultHttpBinding.java
          15 kB
          Amit Patel
        2. DefaultHttpBinding.java
          15 kB
          Amit Patel

        Activity

          People

            davsclaus Claus Ibsen
            amit1000 Amit Patel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: