Search in sources :

Example 1 with HeapByteBufferAllocator

use of org.apache.http.nio.util.HeapByteBufferAllocator in project fc-java-sdk by aliyun.

the class AbstractResponseConsumer method onEntityEnclosed.

protected void onEntityEnclosed(HttpEntity entity, ContentType contentType) throws IOException {
    long len = entity.getContentLength();
    if (len > 2147483647L) {
        throw new ContentTooLongException("Entity content is too long: " + len);
    } else {
        if (len < 0L) {
            len = 4096L;
        }
        this.buf = new SimpleInputBuffer((int) len, new HeapByteBufferAllocator());
        this.httpResponse.setEntity(new ContentBufferEntity(entity, this.buf));
    }
}
Also used : SimpleInputBuffer(org.apache.http.nio.util.SimpleInputBuffer) HeapByteBufferAllocator(org.apache.http.nio.util.HeapByteBufferAllocator) ContentTooLongException(org.apache.http.ContentTooLongException) ContentBufferEntity(org.apache.http.nio.entity.ContentBufferEntity)

Example 2 with HeapByteBufferAllocator

use of org.apache.http.nio.util.HeapByteBufferAllocator in project wso2-synapse by wso2.

the class SourceHandler method getOutputStream.

/**
 * Create synapse.response-source-buffer for GET and HEAD Http methods
 * @param method  Http Method
 * @param request Source Request
 * @return OutputStream
 */
public OutputStream getOutputStream(String method, SourceRequest request) {
    OutputStream os = null;
    if (HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method)) {
        HttpContext context = request.getConnection().getContext();
        ContentOutputBuffer outputBuffer = new SimpleOutputBuffer(sourceConfiguration.getIOBufferSize(), new HeapByteBufferAllocator());
        context.setAttribute("synapse.response-source-buffer", outputBuffer);
        os = new ContentOutputStream(outputBuffer);
    }
    return os;
}
Also used : SimpleOutputBuffer(org.apache.http.nio.util.SimpleOutputBuffer) HeapByteBufferAllocator(org.apache.http.nio.util.HeapByteBufferAllocator) ContentOutputStream(org.apache.http.nio.entity.ContentOutputStream) OutputStream(java.io.OutputStream) HttpContext(org.apache.http.protocol.HttpContext) ContentOutputStream(org.apache.http.nio.entity.ContentOutputStream) ContentOutputBuffer(org.apache.http.nio.util.ContentOutputBuffer)

Example 3 with HeapByteBufferAllocator

use of org.apache.http.nio.util.HeapByteBufferAllocator in project wso2-synapse by wso2.

the class BaseConfiguration method build.

public void build() throws AxisFault {
    iOBufferSize = conf.getIOBufferSize();
    if (workerPool == null) {
        workerPool = WorkerPoolFactory.getWorkerPool(conf.getWorkerPoolCoreSize(), conf.getWorkerPoolMaxSize(), conf.getWorkerThreadKeepaliveSec(), conf.getWorkerPoolQueueLen(), PASSTHROUGH_THREAD_GROUP, PASSTHROUGH_THREAD_ID);
    }
    httpParams = buildHttpParams();
    ioReactorConfig = buildIOReactorConfig();
    String sysCorrelationStatus = System.getProperty(PassThroughConstants.CORRELATION_LOGS_SYS_PROPERTY);
    if (sysCorrelationStatus != null) {
        correlationLoggingEnabled = sysCorrelationStatus.equalsIgnoreCase("true");
    }
    bufferFactory = new BufferFactory(iOBufferSize, new HeapByteBufferAllocator(), 512);
}
Also used : HeapByteBufferAllocator(org.apache.http.nio.util.HeapByteBufferAllocator) BufferFactory(org.apache.synapse.transport.passthru.util.BufferFactory)

Aggregations

HeapByteBufferAllocator (org.apache.http.nio.util.HeapByteBufferAllocator)3 OutputStream (java.io.OutputStream)1 ContentTooLongException (org.apache.http.ContentTooLongException)1 ContentBufferEntity (org.apache.http.nio.entity.ContentBufferEntity)1 ContentOutputStream (org.apache.http.nio.entity.ContentOutputStream)1 ContentOutputBuffer (org.apache.http.nio.util.ContentOutputBuffer)1 SimpleInputBuffer (org.apache.http.nio.util.SimpleInputBuffer)1 SimpleOutputBuffer (org.apache.http.nio.util.SimpleOutputBuffer)1 HttpContext (org.apache.http.protocol.HttpContext)1 BufferFactory (org.apache.synapse.transport.passthru.util.BufferFactory)1