Example usage for org.apache.http.params CoreConnectionPNames MIN_CHUNK_LIMIT

List of usage examples for org.apache.http.params CoreConnectionPNames MIN_CHUNK_LIMIT

Introduction

In this page you can find the example usage for org.apache.http.params CoreConnectionPNames MIN_CHUNK_LIMIT.

Prototype

String MIN_CHUNK_LIMIT

To view the source code for org.apache.http.params CoreConnectionPNames MIN_CHUNK_LIMIT.

Click Source Link

Usage

From source file:com.sun.jersey.client.apache4.ApacheHttpClient4Handler.java

private HttpUriRequest getUriHttpRequest(final ClientRequest cr) {
    final String strMethod = cr.getMethod();
    final URI uri = cr.getURI();

    final Boolean bufferingEnabled = isBufferingEnabled(cr);
    final HttpEntity entity = getHttpEntity(cr, bufferingEnabled);
    final HttpUriRequest request;

    if (strMethod.equals("GET")) {
        request = new HttpGet(uri);
    } else if (strMethod.equals("POST")) {
        request = new HttpPost(uri);
    } else if (strMethod.equals("PUT")) {
        request = new HttpPut(uri);
    } else if (strMethod.equals("DELETE")) {
        request = new HttpDelete(uri);
    } else if (strMethod.equals("HEAD")) {
        request = new HttpHead(uri);
    } else if (strMethod.equals("OPTIONS")) {
        request = new HttpOptions(uri);
    } else {/*from  w  w  w .  jav  a2s  .c  om*/
        request = new HttpEntityEnclosingRequestBase() {
            @Override
            public String getMethod() {
                return strMethod;
            }

            @Override
            public URI getURI() {
                return uri;
            }
        };
    }

    if (entity != null && request instanceof HttpEntityEnclosingRequestBase) {
        ((HttpEntityEnclosingRequestBase) request).setEntity(entity);
    } else if (entity != null) {
        throw new ClientHandlerException(
                "Adding entity to http method " + cr.getMethod() + " is not supported.");
    }

    // Set the read timeout
    final Integer readTimeout = (Integer) cr.getProperties().get(ApacheHttpClient4Config.PROPERTY_READ_TIMEOUT);
    if (readTimeout != null) {
        request.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT, readTimeout);
    }

    // Set chunk size
    final Integer chunkSize = (Integer) cr.getProperties().get(ClientConfig.PROPERTY_CHUNKED_ENCODING_SIZE);
    if (chunkSize != null && !bufferingEnabled) {
        client.getParams().setIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, chunkSize);
    }

    return request;
}