Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
2.8.0
-
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()))
} else
{ throw new IllegalArgumentException( "Invalid parameter, expected to be a pair but was " + param); } }
}