Skip to content

Commit

Permalink
Don't cache the input stream unless we have gotten through the servic…
Browse files Browse the repository at this point in the history
…e invoke phase. If there is an exception or similar on input, there is no need to cache it, just discard what we can.
  • Loading branch information
dkulp committed Mar 25, 2014
1 parent d2578fe commit 643b1bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Expand Up @@ -57,6 +57,10 @@ public OutgoingChainInterceptor() {
public void handleMessage(Message message) {
Exchange ex = message.getExchange();
BindingOperationInfo binding = ex.get(BindingOperationInfo.class);
//if we get this far, we're going to be outputting some valid content, but we COULD
//also be "echoing" some of the content from the input. Thus, we need to
//mark it as requiring the input to be cached.
message.put("cxf.io.cacheinput", Boolean.TRUE);
if (null != binding && null != binding.getOperationInfo() && binding.getOperationInfo().isOneWay()) {
closeInput(message);
return;
Expand Down
Expand Up @@ -523,21 +523,33 @@ private void cacheInput(Message outMessage) {
if (inMessage == null) {
return;
}
Collection<Attachment> atts = inMessage.getAttachments();
if (atts != null) {
for (Attachment a : atts) {
if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) {
try {
((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(inMessage);
} catch (IOException e) {
throw new Fault(e);
Object o = inMessage.get("cxf.io.cacheinput");
DelegatingInputStream in = inMessage.getContent(DelegatingInputStream.class);
if (MessageUtils.isTrue(o)) {
Collection<Attachment> atts = inMessage.getAttachments();
if (atts != null) {
for (Attachment a : atts) {
if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) {
try {
((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(inMessage);
} catch (IOException e) {
throw new Fault(e);
}
}
}
}
}
DelegatingInputStream in = inMessage.getContent(DelegatingInputStream.class);
if (in != null) {
in.cacheInput();
if (in != null) {
in.cacheInput();
}
} else if (in != null) {
//We don't need to cache it, but we may need to consume it in order for the client
// to be able to receive a response. (could be blocked sending)
//However, also don't want to consume indefinitely. We'll limit to 16M.
try {
IOUtils.consume(in, 16 * 1024 * 1024);
} catch (IOException ioe) {
//ignore
}
}
}

Expand Down

0 comments on commit 643b1bc

Please sign in to comment.