Search in sources :

Example 1 with StreamingContent

use of com.google.api.client.util.StreamingContent in project scout.rt by eclipse.

the class ApacheHttpRequest method execute.

@Override
public LowLevelHttpResponse execute() throws IOException {
    final StreamingContent streamingContent = getStreamingContent();
    if (streamingContent != null) {
        if (!(m_request instanceof HttpEntityEnclosingRequest)) {
            throw new ProcessingException("This request {} does not support content.", m_request);
        }
        AbstractHttpEntity entity = new AbstractHttpEntity() {

            @Override
            public void writeTo(OutputStream outstream) throws IOException {
                streamingContent.writeTo(outstream);
            }

            @Override
            public boolean isStreaming() {
                return true;
            }

            @Override
            public boolean isRepeatable() {
                if (streamingContent instanceof HttpContent) {
                    return ((HttpContent) streamingContent).retrySupported();
                }
                return false;
            }

            @Override
            public long getContentLength() {
                return ApacheHttpRequest.this.getContentLength();
            }

            @Override
            public InputStream getContent() throws IOException {
                throw new UnsupportedOperationException("Streaming entity cannot be represented as an input stream.");
            }
        };
        ((HttpEntityEnclosingRequest) m_request).setEntity(entity);
        entity.setContentEncoding(getContentEncoding());
        entity.setContentType(getContentType());
    }
    return createResponseInternal();
}
Also used : HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) OutputStream(java.io.OutputStream) StreamingContent(com.google.api.client.util.StreamingContent) AbstractHttpEntity(org.apache.http.entity.AbstractHttpEntity) HttpContent(com.google.api.client.http.HttpContent) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

HttpContent (com.google.api.client.http.HttpContent)1 StreamingContent (com.google.api.client.util.StreamingContent)1 OutputStream (java.io.OutputStream)1 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)1 AbstractHttpEntity (org.apache.http.entity.AbstractHttpEntity)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1