Search in sources :

Example 51 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnectionTest method assertRequestConfig.

private static void assertRequestConfig(DefaultConnection connection, int connectTimeout, int socketTimeout) {
    RequestConfig requestConfig = connection.requestConfig;
    Assert.assertEquals(connectTimeout, requestConfig.getConnectTimeout());
    Assert.assertEquals(socketTimeout, requestConfig.getSocketTimeout());
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig)

Example 52 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project ecf by eclipse.

the class RestClientService method setupHttpMethod.

protected void setupHttpMethod(HttpRequestBase httpMethod, IRemoteCall call, IRemoteCallable callable) {
    RequestConfig defaultRequestConfig = httpMethod.getConfig();
    RequestConfig.Builder updatedRequestConfigBuilder = (defaultRequestConfig == null) ? RequestConfig.custom() : RequestConfig.copy(defaultRequestConfig);
    // setup to allow regular and circular redirects
    updatedRequestConfigBuilder.setCircularRedirectsAllowed(true);
    updatedRequestConfigBuilder.setRedirectsEnabled(true);
    int sTimeout = socketTimeout;
    int scTimeout = connectTimeout;
    int scrTimeout = connectRequestTimeout;
    long callTimeout = call.getTimeout();
    if (callTimeout == IRemoteCall.DEFAULT_TIMEOUT)
        callTimeout = callable.getDefaultTimeout();
    if (callTimeout != IRemoteCall.DEFAULT_TIMEOUT) {
        sTimeout = scTimeout = scrTimeout = new Long(callTimeout).intValue();
    }
    updatedRequestConfigBuilder.setSocketTimeout(sTimeout);
    updatedRequestConfigBuilder.setConnectTimeout(scTimeout);
    updatedRequestConfigBuilder.setConnectionRequestTimeout(scrTimeout);
    httpMethod.setConfig(updatedRequestConfigBuilder.build());
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig)

Example 53 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project ma-core-public by infiniteautomation.

the class StoreLatestSnapshotTest method getHttpClient.

protected HttpClient getHttpClient(int timeout) {
    // Create global request configuration
    RequestConfig defaultRequestConfig = RequestConfig.custom().setExpectContinueEnabled(true).setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST)).setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC)).setSocketTimeout(timeout).setConnectTimeout(timeout).build();
    // Create an HttpClient with the given custom dependencies and configuration.
    CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
    return httpclient;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient)

Example 54 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project ma-core-public by infiniteautomation.

the class Common method getHttpClient.

public static HttpClient getHttpClient(int timeout) {
    // Create global request configuration
    RequestConfig defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).setExpectContinueEnabled(true).setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST)).setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC)).setSocketTimeout(timeout).setConnectTimeout(timeout).build();
    if (SystemSettingsDao.getBooleanValue(SystemSettingsDao.HTTP_CLIENT_USE_PROXY)) {
        String proxyHost = SystemSettingsDao.getValue(SystemSettingsDao.HTTP_CLIENT_PROXY_SERVER);
        int proxyPort = SystemSettingsDao.getIntValue(SystemSettingsDao.HTTP_CLIENT_PROXY_PORT);
        String username = SystemSettingsDao.getValue(SystemSettingsDao.HTTP_CLIENT_PROXY_USERNAME, "");
        String password = SystemSettingsDao.getValue(SystemSettingsDao.HTTP_CLIENT_PROXY_PASSWORD, "");
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(username, password));
        // Create an HttpClient with the given custom dependencies and configuration.
        CloseableHttpClient httpclient = HttpClients.custom().setProxy(new HttpHost(proxyHost, proxyPort)).setDefaultRequestConfig(defaultRequestConfig).setDefaultCredentialsProvider(credentialsProvider).build();
        return httpclient;
    } else {
        // Create an HttpClient with the given custom dependencies and configuration.
        CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
        return httpclient;
    }
// LEGACY CODE LEFT HERE UNTIL Testing of above code is confirmed as working
// DefaultHttpClient client = new DefaultHttpClient();
// client.getParams().setParameter("http.socket.timeout", timeout);
// client.getParams().setParameter("http.connection.timeout", timeout);
// client.getParams().setParameter("http.connection-manager.timeout", timeout);
// client.getParams().setParameter("http.protocol.head-body-timeout", timeout);
// 
// if (SystemSettingsDao.getBooleanValue(SystemSettingsDao.HTTP_CLIENT_USE_PROXY)) {
// String proxyHost = SystemSettingsDao.getValue(SystemSettingsDao.HTTP_CLIENT_PROXY_SERVER);
// int proxyPort = SystemSettingsDao.getIntValue(SystemSettingsDao.HTTP_CLIENT_PROXY_PORT);
// String username = SystemSettingsDao.getValue(SystemSettingsDao.HTTP_CLIENT_PROXY_USERNAME, "");
// String password = SystemSettingsDao.getValue(SystemSettingsDao.HTTP_CLIENT_PROXY_PASSWORD, "");
// 
// client.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, proxyPort),
// new UsernamePasswordCredentials(username, password));
// 
// }
// 
// return client;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 55 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project neo-java by coranos.

the class TestRpcServerUtil method getCityOfZionResponse.

/**
 * @param input
 *            the input to use.
 * @param method
 *            the method to call.
 * @return the reseponse.
 */
public static String getCityOfZionResponse(final String input, final String method) {
    try {
        final String url = CityOfZionUtil.MAINNET_API + method + input;
        LOG.debug("url:{}", url);
        final HttpGet httpRequest = new HttpGet(url);
        final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIMEOUT_MILLIS).setConnectTimeout(TIMEOUT_MILLIS).setConnectionRequestTimeout(TIMEOUT_MILLIS).build();
        httpRequest.setConfig(requestConfig);
        final CloseableHttpClient client = HttpClients.createDefault();
        final String responseStr;
        try {
            final CloseableHttpResponse response = client.execute(httpRequest);
            logDebugStatus(response);
            final HttpEntity entity = response.getEntity();
            responseStr = EntityUtils.toString(entity);
        } catch (final ConnectTimeoutException | SocketTimeoutException | NoHttpResponseException | SocketException e) {
            throw new RuntimeException(CONNECTION_EXCEPTION, e);
        }
        final JSONObject responseJson = new JSONObject(responseStr);
        final String actualStr = responseJson.toString(2);
        return actualStr;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) SocketException(java.net.SocketException) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) NoHttpResponseException(org.apache.http.NoHttpResponseException) SocketException(java.net.SocketException) JSONException(org.json.JSONException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) JSONObject(org.json.JSONObject) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Aggregations

RequestConfig (org.apache.http.client.config.RequestConfig)344 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)146 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)97 HttpGet (org.apache.http.client.methods.HttpGet)94 IOException (java.io.IOException)78 HttpEntity (org.apache.http.HttpEntity)67 HttpPost (org.apache.http.client.methods.HttpPost)65 HttpResponse (org.apache.http.HttpResponse)60 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)55 URI (java.net.URI)46 StringEntity (org.apache.http.entity.StringEntity)43 Map (java.util.Map)41 Test (org.junit.Test)41 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)33 HttpHost (org.apache.http.HttpHost)32 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)32 HttpClient (org.apache.http.client.HttpClient)31 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)27 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)24 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)24