httpServletRequest.getContentType().contains(STRING_CONTENT_TYPE_FORM_URLENCODED)
&& httpServletRequest.getHeader("content-encoding") == null) {
requestByteArray = IOUtils.toByteArray(body);
// this is binary.. just return it as is
requestEntity = new ByteArrayRequestEntity(requestByteArray);
// Get the client POST data as a Map if content type is: application/x-www-form-urlencoded
// We do this manually since some data is not properly parseable by the servlet request
Map<String, String[]> mapPostParameters = HttpUtilities.mapUrlEncodedParameters(requestByteArray);
// Iterate the parameter names
for (String stringParameterName : mapPostParameters.keySet()) {
// Iterate the values for each parameter name
String[] stringArrayParameterValues = mapPostParameters
.get(stringParameterName);
for (String stringParameterValue : stringArrayParameterValues) {
// Create a NameValuePair and store in list
// add an & if there is already data
if (requestBody.length() > 0) {
requestBody.append("&");
}
requestBody.append(stringParameterName);
// not everything has a value so lets check
if (stringParameterValue.length() > 0) {
requestBody.append("=");
requestBody.append(stringParameterValue);
}
}
}
} else if (httpServletRequest.getContentType() != null &&
httpServletRequest.getContentType().contains(STRING_CONTENT_TYPE_MESSAGEPACK)) {
/**
* Convert input stream to bytes for it to be read by the deserializer
* Unpack and iterate the list to see the contents
*/
MessagePack msgpack = new MessagePack();
requestByteArray = IOUtils.toByteArray(body);
requestEntity = new ByteArrayRequestEntity(requestByteArray);
ByteArrayInputStream byteArrayIS = new ByteArrayInputStream(requestByteArray);
Unpacker unpacker = msgpack.createUnpacker(byteArrayIS);
for (Value message : unpacker) {
deserialisedMessages += message;
deserialisedMessages += "\n";
}
history.setRequestBodyDecoded(true);
} else {
requestByteArray = IOUtils.toByteArray(body);
// this is binary.. just return it as is
requestEntity = new ByteArrayRequestEntity(requestByteArray);
// decode this for history if it is encoded
String requestBodyString = PluginHelper.getByteArrayDataAsString(httpServletRequest.getHeader("content-encoding"), requestByteArray);
requestBody.append(requestBodyString);
// mark in history if the body has been decoded
if (! requestBodyString.equals(new String(requestByteArray)))
history.setRequestBodyDecoded(true);
}
// set post body in history object
history.setRequestPostData(requestBody.toString());
// set post body in proxy request object
methodProxyRequest.setRequestEntity(requestEntity);
/**
* Set the history to have decoded messagepack. Pass the byte data back to request
*/
if (httpServletRequest.getContentType() != null &&
httpServletRequest.getContentType().contains(STRING_CONTENT_TYPE_MESSAGEPACK)) {
history.setRequestPostData(deserialisedMessages);
ByteArrayRequestEntity byteRequestEntity = new ByteArrayRequestEntity(requestByteArray);
methodProxyRequest.setRequestEntity(byteRequestEntity);
}
}