Java Code Examples for org.apache.http.entity.BasicHttpEntity#setChunked()

The following examples show how to use org.apache.http.entity.BasicHttpEntity#setChunked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConanClient.java    From nexus-repository-conan with Eclipse Public License 1.0 7 votes vote down vote up
public HttpResponse getHttpResponse(final String path) throws IOException {
  try (CloseableHttpResponse closeableHttpResponse = super.get(path)) {
    HttpEntity entity = closeableHttpResponse.getEntity();

    BasicHttpEntity basicHttpEntity = new BasicHttpEntity();
    String content = EntityUtils.toString(entity);
    basicHttpEntity.setContent(IOUtils.toInputStream(content));

    basicHttpEntity.setContentEncoding(entity.getContentEncoding());
    basicHttpEntity.setContentLength(entity.getContentLength());
    basicHttpEntity.setContentType(entity.getContentType());
    basicHttpEntity.setChunked(entity.isChunked());

    StatusLine statusLine = closeableHttpResponse.getStatusLine();
    HttpResponse response = new BasicHttpResponse(statusLine);
    response.setEntity(basicHttpEntity);
    response.setHeaders(closeableHttpResponse.getAllHeaders());
    response.setLocale(closeableHttpResponse.getLocale());
    return response;
  }
}
 
Example 2
Source File: AsyncHTTPConduit.java    From cxf with Apache License 2.0 6 votes vote down vote up
public AsyncWrappedOutputStream(Message message,
                                boolean needToCacheRequest,
                                boolean isChunking,
                                int chunkThreshold,
                                String conduitName,
                                URI uri) {
    super(message,
          needToCacheRequest,
          isChunking,
          chunkThreshold,
          conduitName,
          uri);
    csPolicy = getClient(message);
    entity = message.get(CXFHttpRequest.class);
    basicEntity = (BasicHttpEntity)entity.getEntity();
    basicEntity.setChunked(isChunking);
    HeapByteBufferAllocator allocator = new HeapByteBufferAllocator();
    int bufSize = csPolicy.getChunkLength() > 0 ? csPolicy.getChunkLength() : 16320;
    inbuf = new SharedInputBuffer(bufSize, allocator);
    outbuf = new SharedOutputBuffer(bufSize, allocator);
    isAsync = outMessage != null && outMessage.getExchange() != null
        && !outMessage.getExchange().isSynchronous();
}