Example usage for org.apache.http.client CredentialsProvider getClass

List of usage examples for org.apache.http.client CredentialsProvider getClass

Introduction

In this page you can find the example usage for org.apache.http.client CredentialsProvider getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.jets3t.service.utils.RestUtils.java

public static HttpClient initHttpsConnection(final JetS3tRequestAuthorizer requestAuthorizer,
        Jets3tProperties jets3tProperties, String userAgentDescription,
        CredentialsProvider credentialsProvider) {
    // Configure HttpClient properties based on Jets3t Properties.
    HttpParams params = createDefaultHttpParams();
    params.setParameter(Jets3tProperties.JETS3T_PROPERTIES_ID, jets3tProperties);

    params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, jets3tProperties.getStringProperty(
            ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, ConnManagerFactory.class.getName()));

    HttpConnectionParams.setConnectionTimeout(params,
            jets3tProperties.getIntProperty("httpclient.connection-timeout-ms", 60000));
    HttpConnectionParams.setSoTimeout(params,
            jets3tProperties.getIntProperty("httpclient.socket-timeout-ms", 60000));
    HttpConnectionParams.setStaleCheckingEnabled(params,
            jets3tProperties.getBoolProperty("httpclient.stale-checking-enabled", true));

    // Connection properties to take advantage of S3 window scaling.
    if (jets3tProperties.containsKey("httpclient.socket-receive-buffer")) {
        HttpConnectionParams.setSocketBufferSize(params,
                jets3tProperties.getIntProperty("httpclient.socket-receive-buffer", 0));
    }/*from w w  w.  ja v a  2  s.  c om*/

    HttpConnectionParams.setTcpNoDelay(params, true);

    // Set user agent string.
    String userAgent = jets3tProperties.getStringProperty("httpclient.useragent", null);
    if (userAgent == null) {
        userAgent = ServiceUtils.getUserAgentDescription(userAgentDescription);
    }
    if (log.isDebugEnabled()) {
        log.debug("Setting user agent string: " + userAgent);
    }
    HttpProtocolParams.setUserAgent(params, userAgent);

    boolean expectContinue = jets3tProperties.getBoolProperty("http.protocol.expect-continue", true);
    HttpProtocolParams.setUseExpectContinue(params, expectContinue);

    long connectionManagerTimeout = jets3tProperties.getLongProperty("httpclient.connection-manager-timeout",
            0);
    ConnManagerParams.setTimeout(params, connectionManagerTimeout);

    DefaultHttpClient httpClient = wrapClient(params);
    httpClient.setHttpRequestRetryHandler(new JetS3tRetryHandler(
            jets3tProperties.getIntProperty("httpclient.retry-max", 5), requestAuthorizer));

    if (credentialsProvider != null) {
        if (log.isDebugEnabled()) {
            log.debug("Using credentials provider class: " + credentialsProvider.getClass().getName());
        }
        httpClient.setCredentialsProvider(credentialsProvider);
        if (jets3tProperties.getBoolProperty("httpclient.authentication-preemptive", false)) {
            // Add as the very first interceptor in the protocol chain
            httpClient.addRequestInterceptor(new PreemptiveInterceptor(), 0);
        }
    }
    return httpClient;
}

From source file:org.jets3t.service.utils.RestUtils.java

/**
 * Initialises, or re-initialises, the underlying HttpConnectionManager and
 * HttpClient objects a service will use to communicate with an AWS service.
 * If proxy settings are specified in this service's {@link Jets3tProperties} object,
 * these settings will also be passed on to the underlying objects.
 *//*from w  ww .j  a  v  a  2 s .  com*/
public static HttpClient initHttpConnection(final JetS3tRequestAuthorizer requestAuthorizer,
        Jets3tProperties jets3tProperties, String userAgentDescription,
        CredentialsProvider credentialsProvider) {
    // Configure HttpClient properties based on Jets3t Properties.
    HttpParams params = createDefaultHttpParams();
    params.setParameter(Jets3tProperties.JETS3T_PROPERTIES_ID, jets3tProperties);

    params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, jets3tProperties.getStringProperty(
            ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, ConnManagerFactory.class.getName()));

    HttpConnectionParams.setConnectionTimeout(params,
            jets3tProperties.getIntProperty("httpclient.connection-timeout-ms", 60000));
    HttpConnectionParams.setSoTimeout(params,
            jets3tProperties.getIntProperty("httpclient.socket-timeout-ms", 60000));
    HttpConnectionParams.setStaleCheckingEnabled(params,
            jets3tProperties.getBoolProperty("httpclient.stale-checking-enabled", true));

    // Connection properties to take advantage of S3 window scaling.
    if (jets3tProperties.containsKey("httpclient.socket-receive-buffer")) {
        HttpConnectionParams.setSocketBufferSize(params,
                jets3tProperties.getIntProperty("httpclient.socket-receive-buffer", 0));
    }

    HttpConnectionParams.setTcpNoDelay(params, true);

    // Set user agent string.
    String userAgent = jets3tProperties.getStringProperty("httpclient.useragent", null);
    if (userAgent == null) {
        userAgent = ServiceUtils.getUserAgentDescription(userAgentDescription);
    }
    if (log.isDebugEnabled()) {
        log.debug("Setting user agent string: " + userAgent);
    }
    HttpProtocolParams.setUserAgent(params, userAgent);

    boolean expectContinue = jets3tProperties.getBoolProperty("http.protocol.expect-continue", true);
    HttpProtocolParams.setUseExpectContinue(params, expectContinue);

    long connectionManagerTimeout = jets3tProperties.getLongProperty("httpclient.connection-manager-timeout",
            0);
    ConnManagerParams.setTimeout(params, connectionManagerTimeout);

    DefaultHttpClient httpClient = new DefaultHttpClient(params);
    httpClient.setHttpRequestRetryHandler(new JetS3tRetryHandler(
            jets3tProperties.getIntProperty("httpclient.retry-max", 5), requestAuthorizer));

    if (credentialsProvider != null) {
        if (log.isDebugEnabled()) {
            log.debug("Using credentials provider class: " + credentialsProvider.getClass().getName());
        }
        httpClient.setCredentialsProvider(credentialsProvider);
        if (jets3tProperties.getBoolProperty("httpclient.authentication-preemptive", false)) {
            // Add as the very first interceptor in the protocol chain
            httpClient.addRequestInterceptor(new PreemptiveInterceptor(), 0);
        }
    }

    return httpClient;
}