Example usage for org.apache.http.client.methods RequestBuilder setVersion

List of usage examples for org.apache.http.client.methods RequestBuilder setVersion

Introduction

In this page you can find the example usage for org.apache.http.client.methods RequestBuilder setVersion.

Prototype

public RequestBuilder setVersion(final ProtocolVersion version) 

Source Link

Usage

From source file:org.apache.commons.jcs.auxiliary.remote.http.client.AbstractHttpClient.java

/**
 * Execute the web service call/*from w ww  . ja  v  a2  s  .c om*/
 * <p>
 * @param builder builder for the post request
 *
 * @return the call response
 *
 * @throws IOException on i/o error
 */
protected final HttpResponse doWebserviceCall(RequestBuilder builder) throws IOException {
    preProcessWebserviceCall(builder.setVersion(httpVersion));
    HttpUriRequest request = builder.build();
    HttpResponse httpResponse = this.httpClient.execute(request);
    postProcessWebserviceCall(request, httpResponse);

    return httpResponse;
}

From source file:org.dasein.cloud.qingcloud.util.requester.QingCloudRequestBuilder.java

private QingCloudRequestBuilder(QingCloud qingCloud, RequestBuilder requestBuilder) {
    this.qingCloud = qingCloud;
    this.requestBuilder = requestBuilder;

    byte[][] accessKey = (byte[][]) qingCloud.getContext().getConfigurationValue(QingCloud.DSN_ACCESS_KEY);

    requestBuilder.setVersion(new ProtocolVersion("HTTP", 1, 1));

    requestBuilder.setUri("https://api.qingcloud.com/iaas/");

    parameter("time_stamp", qingCloud.formatIso8601Date(new Date()));
    parameter("access_key_id", new String(accessKey[0]));
    parameter("version", "1");
    parameter("signature_method", SIGNATURE_ALGORITHM);
    parameter("signature_version", "1");
}

From source file:org.bonitasoft.connectors.rest.RESTConnector.java

/**
 * Execute a given request//from   ww  w . j  a v a 2  s.  c o  m
 * 
 * @param request The request to execute
 * @return The response of the executed request
 * @throws Exception any exception that might occur
 */
public void execute(final Request request) throws Exception {
    CloseableHttpClient httpClient = null;

    try {
        final URL url = request.getUrl();
        final String urlHost = url.getHost();

        final Builder requestConfigurationBuilder = RequestConfig.custom();
        requestConfigurationBuilder.setConnectionRequestTimeout(CONNECTION_TIMEOUT);
        requestConfigurationBuilder.setRedirectsEnabled(request.isRedirect());

        final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
        setSSL(request.getSsl(), httpClientBuilder);
        setProxy(request.getProxy(), httpClientBuilder, requestConfigurationBuilder);
        setCookies(requestConfigurationBuilder, httpClientBuilder, request.getCookies(), urlHost);

        final RequestBuilder requestBuilder = getRequestBuilderFromMethod(request.getRestMethod());
        requestBuilder.setVersion(
                new ProtocolVersion(HTTP_PROTOCOL, HTTP_PROTOCOL_VERSION_MAJOR, HTTP_PROTOCOL_VERSION_MINOR));
        int urlPort = url.getPort();
        if (url.getPort() == -1) {
            urlPort = url.getDefaultPort();
        }
        final String urlProtocol = url.getProtocol();
        final String urlStr = url.toString();
        requestBuilder.setUri(urlStr);
        setHeaders(requestBuilder, request.getHeaders());
        if (!HTTPMethod.GET.equals(HTTPMethod.valueOf(requestBuilder.getMethod()))) {
            final String body = request.getBody();
            if (body != null) {
                requestBuilder.setEntity(new StringEntity(request.getBody(), request.getContentType()));
            }
        }

        final HttpContext httpContext = setAuthorizations(requestConfigurationBuilder,
                request.getAuthorization(), request.getProxy(), urlHost, urlPort, urlProtocol,
                httpClientBuilder);

        requestBuilder.setConfig(requestConfigurationBuilder.build());
        httpClientBuilder.setDefaultRequestConfig(requestConfigurationBuilder.build());

        final HttpUriRequest httpRequest = requestBuilder.build();
        httpClient = httpClientBuilder.build();
        final CloseableHttpResponse httpResponse = httpClient.execute(httpRequest, httpContext);
        LOGGER.fine("Request sent.");
        setOutputs(httpResponse, request);
    } finally {
        try {
            if (httpClient != null) {
                httpClient.close();
            }
        } catch (final IOException ex) {
            logException(ex);
        }
    }
}