Search in sources :

Example 1 with DefaultApacheHttpClient4Config

use of com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config in project gfm_viewer by satyagraha.

the class WebServiceClientDefault method getClient.

private Client getClient(String endpoint) {
    // set up standard properties
    DefaultApacheHttpClient4Config clientConfig = new DefaultApacheHttpClient4Config();
    Map<String, Object> clientProperties = clientConfig.getProperties();
    clientProperties.put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
    clientConfig.getClasses().addAll(ConnUtilities.getJerseyProviders());
    // see if proxy needed
    URI uri;
    try {
        uri = new URI(endpoint);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    WebProxyData webProxyData = webProxyConfig.getWebProxyData(uri);
    if (webProxyData != null) {
        if (webProxyData.getProxyUri() != null) {
            clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_PROXY_URI, webProxyData.getProxyUri());
            if (webProxyData.getUserId() != null) {
                clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_PROXY_USERNAME, webProxyData.getUserId());
                if (webProxyData.getPassword() != null) {
                    clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD, webProxyData.getPassword());
                }
            }
        }
    }
    // set up client properties
    clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, connectionManager);
    LOGGER.fine("clientProperties(): " + clientProperties);
    // build client
    Client client = ApacheHttpClient4.create(clientConfig);
    return client;
}
Also used : DefaultApacheHttpClient4Config(com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config) WebProxyData(code.satyagraha.gfm.support.api.WebProxyConfig.WebProxyData) URISyntaxException(java.net.URISyntaxException) Client(com.sun.jersey.api.client.Client) WebServiceClient(code.satyagraha.gfm.support.api.WebServiceClient) URI(java.net.URI)

Example 2 with DefaultApacheHttpClient4Config

use of com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config in project ribbon by Netflix.

the class RestClient method initWithNiwsConfig.

@Override
public void initWithNiwsConfig(IClientConfig clientConfig) {
    super.initWithNiwsConfig(clientConfig);
    this.ncc = clientConfig;
    this.restClientName = ncc.getClientName();
    this.isSecure = getBooleanFromConfig(ncc, CommonClientConfigKey.IsSecure, this.isSecure);
    this.isHostnameValidationRequired = getBooleanFromConfig(ncc, CommonClientConfigKey.IsHostnameValidationRequired, this.isHostnameValidationRequired);
    this.isClientAuthRequired = getBooleanFromConfig(ncc, CommonClientConfigKey.IsClientAuthRequired, this.isClientAuthRequired);
    this.bFollowRedirects = getBooleanFromConfig(ncc, CommonClientConfigKey.FollowRedirects, true);
    this.ignoreUserToken = getBooleanFromConfig(ncc, CommonClientConfigKey.IgnoreUserTokenInConnectionPoolForSecureClient, this.ignoreUserToken);
    this.config = new DefaultApacheHttpClient4Config();
    this.config.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECT_TIMEOUT, Integer.parseInt(String.valueOf(ncc.getProperty(CommonClientConfigKey.ConnectTimeout))));
    this.config.getProperties().put(ApacheHttpClient4Config.PROPERTY_READ_TIMEOUT, Integer.parseInt(String.valueOf(ncc.getProperty(CommonClientConfigKey.ReadTimeout))));
    this.restClient = apacheHttpClientSpecificInitialization();
    this.setRetryHandler(new HttpClientLoadBalancerErrorHandler(ncc));
}
Also used : DefaultApacheHttpClient4Config(com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config)

Aggregations

DefaultApacheHttpClient4Config (com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config)2 WebProxyData (code.satyagraha.gfm.support.api.WebProxyConfig.WebProxyData)1 WebServiceClient (code.satyagraha.gfm.support.api.WebServiceClient)1 Client (com.sun.jersey.api.client.Client)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1