Repository: cxf Updated Branches: refs/heads/2.7.x-fixes 22b612ffc -> 9c11b61bc
[CXF-5842] Make sure the cache gets cleaned up if it fails to cache the input Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/9c11b61b Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/9c11b61b Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/9c11b61b Branch: refs/heads/2.7.x-fixes Commit: 9c11b61bcbc9553a4220a345d7195889c3f697d5 Parents: 22b612f Author: Daniel Kulp <[email protected]> Authored: Wed Jul 9 10:58:33 2014 -0400 Committer: Daniel Kulp <[email protected]> Committed: Wed Jul 9 11:55:58 2014 -0400 ---------------------------------------------------------------------- .../cxf/attachment/AttachmentDataSource.java | 28 +++++++++++++++----- .../cxf/jaxrs/ext/MessageContextImpl.java | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/9c11b61b/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java b/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java index 42194f5..d1b64b8 100644 --- a/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java +++ b/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java @@ -26,6 +26,7 @@ import java.io.OutputStream; import javax.activation.DataSource; import org.apache.cxf.helpers.IOUtils; +import org.apache.cxf.io.CacheSizeExceededException; import org.apache.cxf.io.CachedOutputStream; import org.apache.cxf.message.Message; @@ -49,12 +50,27 @@ public class AttachmentDataSource implements DataSource { if (cache == null) { cache = new CachedOutputStream(); AttachmentUtil.setStreamedAttachmentProperties(message, cache); - IOUtils.copy(ins, cache); - cache.lockOutputStream(); - ins.close(); - ins = null; - if (delegate != null) { - delegate.setInputStream(cache.getInputStream()); + try { + IOUtils.copy(ins, cache); + cache.lockOutputStream(); + if (delegate != null) { + delegate.setInputStream(cache.getInputStream()); + } + } catch (CacheSizeExceededException cee) { + cache.close(); + cache = null; + throw cee; + } catch (IOException cee) { + cache.close(); + cache = null; + throw cee; + } finally { + try { + ins.close(); + } catch (Exception ex) { + //ignore + } + ins = null; } } } http://git-wip-us.apache.org/repos/asf/cxf/blob/9c11b61b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java index 80449f6..f3ed0fd 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java @@ -77,7 +77,7 @@ public class MessageContextImpl implements MessageContext { return createAttachments(key.toString()); } catch (CacheSizeExceededException e) { m.getExchange().put("cxf.io.cacheinput", Boolean.FALSE); - throw new WebApplicationException(413); + throw new WebApplicationException(e, 413); } } if (keyValue.equals("WRITE-" + Message.ATTACHMENTS)) {
