See code below. This logic _works_ in that it does extract the
request-body.
The problem is that further downstream the marshaling phase fails with this
message: "Stream closed".
I have modeled my code after the standard LoggingInterceptor from CXF.
Can anyone explain why the marshaling phase is getting a closed stream,
and how to resolve that error?
Thanks!
Charlie
private String extractRequestBody(Message message, HttpServletRequest
request)
throws WebApplicationException {
log.info("Inside TraceApiCall.extractRequestBody");
String requestBody = null;
if (request.getContentLength() > 0) {
log.info("Inside TraceApiCall.extractRequestBody: body is
non-empty");
try {
InputStream is = request.getInputStream();
if (is != null) {
log.info("Inside TraceApiCall.extractRequestBody:
processing input stream");
CachedOutputStream cos = new CachedOutputStream();
IOUtils.copy(is, cos);
cos.flush();
is.close();
message.setContent(InputStream.class,
cos.getInputStream());
byte[] b = cos.getBytes();
if (b != null) {
requestBody = new String(b, 0, b.length);
}
cos.close();
}
} catch (IOException ioe) {
throw new WebApplicationException(ioe);
}
}
return requestBody;
}
public TraceApiCall() {
super(Phase.RECEIVE);
}
public void handleMessage(Message message) throws Fault {
log.info("Inside TraceApiCall.handleMessage");
HttpServletRequest request = (HttpServletRequest)
message.get(AbstractHTTPDestination.HTTP_REQUEST);
log.info("TraceApiCall.handleMessage; request: " +
ServiceUtils.prettyPrintRequest(request));
String requestBody = extractRequestBody(message, request);
....
}