Search in sources :

Example 1 with CacheSizeExceededException

use of org.apache.cxf.io.CacheSizeExceededException in project cxf by apache.

the class MessageContextImpl method get.

public Object get(Object key) {
    String keyValue = key.toString();
    if (MultipartBody.INBOUND_MESSAGE_ATTACHMENTS.equals(keyValue) || (MultipartBody.INBOUND_MESSAGE_ATTACHMENTS + ".embedded").equals(keyValue)) {
        try {
            return createAttachments(key.toString());
        } catch (CacheSizeExceededException e) {
            m.getExchange().put("cxf.io.cacheinput", Boolean.FALSE);
            throw new WebApplicationException(e, 413);
        } catch (HeaderSizeExceededException e) {
            throw new WebApplicationException(e, 413);
        }
    }
    if (keyValue.equals("WRITE-" + Message.ATTACHMENTS)) {
        return m.getExchange().getOutMessage().get(Message.ATTACHMENTS);
    }
    Message currentMessage = getCurrentMessage();
    Object value = currentMessage.get(key);
    if (value == null) {
        if (Message.class.getName().equals(key)) {
            return currentMessage;
        }
        Exchange exchange = currentMessage.getExchange();
        if (exchange != null) {
            Message otherMessage = exchange.getInMessage() == currentMessage ? exchange.getOutMessage() : exchange.getInMessage();
            if (otherMessage != null) {
                value = otherMessage.get(key);
            }
            if (value == null) {
                value = m.getExchange().get(key);
            }
        }
    }
    return value;
}
Also used : Exchange(org.apache.cxf.message.Exchange) WebApplicationException(javax.ws.rs.WebApplicationException) Message(org.apache.cxf.message.Message) CacheSizeExceededException(org.apache.cxf.io.CacheSizeExceededException) HeaderSizeExceededException(org.apache.cxf.attachment.HeaderSizeExceededException)

Example 2 with CacheSizeExceededException

use of org.apache.cxf.io.CacheSizeExceededException in project cxf by apache.

the class AttachmentDataSource method cache.

public void cache(Message message) throws IOException {
    if (cache == null) {
        cache = new CachedOutputStream();
        AttachmentUtil.setStreamedAttachmentProperties(message, cache);
        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;
        }
    }
}
Also used : CacheSizeExceededException(org.apache.cxf.io.CacheSizeExceededException) IOException(java.io.IOException) IOException(java.io.IOException) CacheSizeExceededException(org.apache.cxf.io.CacheSizeExceededException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 3 with CacheSizeExceededException

use of org.apache.cxf.io.CacheSizeExceededException in project tomee by apache.

the class AttachmentDataSource method cache.

public void cache(Message message) throws IOException {
    if (cache == null) {
        cache = new CachedOutputStream();
        AttachmentUtil.setStreamedAttachmentProperties(message, cache);
        try {
            IOUtils.copyAndCloseInput(ins, cache);
            cache.lockOutputStream();
            if (delegate != null) {
                delegate.setInputStream(cache.getInputStream());
            }
        } catch (CacheSizeExceededException | IOException cee) {
            cache.close();
            cache = null;
            throw cee;
        } finally {
            ins = null;
        }
    }
}
Also used : CacheSizeExceededException(org.apache.cxf.io.CacheSizeExceededException) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Aggregations

CacheSizeExceededException (org.apache.cxf.io.CacheSizeExceededException)3 IOException (java.io.IOException)2 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)2 WebApplicationException (javax.ws.rs.WebApplicationException)1 HeaderSizeExceededException (org.apache.cxf.attachment.HeaderSizeExceededException)1 Exchange (org.apache.cxf.message.Exchange)1 Message (org.apache.cxf.message.Message)1