byte[] bodyBytes = null;
try {
bodyBytes = StreamUtils.readStream(request.getInputStream());
} catch (IOException e) {
throw new MessageDeliverException("Failed to read body data from http request", e);
}
String characterEncoding = request.getCharacterEncoding();
Charset charset;
if(characterEncoding == null) {
charset = Charset.defaultCharset();
} else {
charset = Charset.forName(characterEncoding);
}
if(payloadAs == null) {
String contentType = request.getContentType();
if(contentType != null && HttpContentTypeUtil.isTextMimetype(contentType)) {
try {
String payload = new String(bodyBytes, charset.name());
payloadProxy.setPayload(message, payload);
// In case it's a SOAP message, we need to check for WS-S info...
AuthenticationRequest authRequest = null;
try {
authRequest = ExtractorUtil.extract(payload, extractors);
} catch (final ExtractionException e) {
throw new MessageDeliverException(e.getMessage(), e);
}
if(authRequest != null) {
PublicCryptoUtil.INSTANCE.addAuthRequestToMessage(authRequest, message);
}
} catch (UnsupportedEncodingException e) {
throw new MessageDeliverException("Invalid Character encoding '" + characterEncoding + "' set on request.", e);
}
} else {
payloadProxy.setPayload(message, bodyBytes);
}
} else if(payloadAs.equals("STRING")) {
try {
payloadProxy.setPayload(message, new String(bodyBytes, charset.name()));
} catch (UnsupportedEncodingException e) {
throw new MessageDeliverException("Invalid Character encoding '" + characterEncoding + "' set on request.", e);
}
} else {
payloadProxy.setPayload(message, bodyBytes);
}