Examples of HttpClientBuilder


Examples of com.volantis.shared.net.http.client.HttpClientBuilder

     * Prepare HTTPClient for request,
     * Set headers if are pass in parameters
     */
    private HttpClient prepareHttpClient() {
        HttpClientFactory factory = HttpClientFactory.getDefaultInstance();
        HttpClientBuilder builder = factory.createClientBuilder();
        builder.setConnectionTimeout(CONNECTION_TIMEOUT);
        builder.setRoundTripTimeout(ROUNDTRIP_TIMEOUT);
        return builder.buildHttpClient();
    }
View Full Code Here

Examples of com.volantis.shared.net.http.client.HttpClientBuilder

        final HttpState state = new HttpState();
        state.setCookiePolicy(CookiePolicy.COMPATIBILITY);

        HttpClientFactory factory = HttpClientFactory.getDefaultInstance();
        HttpClientBuilder builder = factory.createClientBuilder();
        builder.setState(state);
        builder.setConnectionTimeout(timeout);
        builder.setRoundTripTimeout(timeout);

        // create the HTTPClient instance.
        final HttpClient httpClient = builder.buildHttpClient();

        // return an HTTPRequestExecutor that uses HttpClient to perform
        // the request
        return new HTTPRequestExecutor() {
View Full Code Here

Examples of com.volantis.shared.net.http.client.HttpClientBuilder

                               final HttpUrlConfiguration httpConfig)
            throws IOException {
        // Create a HTTP Client which will timeout connections and round trips
        // in the specified period.
        final HttpClientFactory factory = HttpClientFactory.getDefaultInstance();
        final HttpClientBuilder builder = factory.createClientBuilder();
        builder.setConnectionTimeout(timeout);
        builder.setRoundTripTimeout(timeout);
        final HttpClient httpClient = builder.buildHttpClient();

        final GetMethod method = new GetMethod(url.toExternalForm());
        final HostConfiguration configuration = new HostConfiguration();
        configuration.setHost(url.getHost(), url.getPort(), url.getProtocol());
        method.setHostConfiguration(configuration);
View Full Code Here

Examples of com.volantis.shared.net.http.client.HttpClientBuilder

        GetMethod method = new GetMethod(url);
        method.setHttp11(false);

        HttpClientFactory factory = HttpClientFactory.getDefaultInstance();
        HttpClientBuilder builder = factory.createClientBuilder();
        builder.setConnectionTimeout(connectionTimeout);
        builder.setRoundTripTimeout(connectionTimeout);
        HttpClient httpClient = builder.buildHttpClient();

        URL netURL = null;
        try {
            netURL = new URL(url);
        } catch (MalformedURLException e) {
View Full Code Here

Examples of com.volantis.shared.net.http.client.HttpClientBuilder

                method.addRequestHeader("Host",
                        url.getHost() + ":" + url.getPort());
            }

            HttpClientFactory factory = HttpClientFactory.getDefaultInstance();
            HttpClientBuilder builder = factory.createClientBuilder();
            HttpClient httpClient = builder.buildHttpClient();
            httpClient.executeMethod(method);
        }
        return method;
    }
View Full Code Here

Examples of com.yammer.dropwizard.client.HttpClientBuilder

    public DictionaryServiceFactory(Client jerseyClient) {
        _client = jerseyClient;
    }

    private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration) {
        HttpClient httpClient = new HttpClientBuilder().using(configuration).build();
        ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
        ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
        config.getSingletons().add(new JacksonMessageBodyProvider(new ObjectMapper(), new Validator()));
        return new ApacheHttpClient4(handler, config);
    }
View Full Code Here

Examples of io.dropwizard.client.HttpClientBuilder

        _client = jerseyClient;
    }

    private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration,
                                                               MetricRegistry metrics) {
        HttpClient httpClient = new HttpClientBuilder(metrics).using(configuration).build("dictionary");
        ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
        ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
        Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
        config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), validator));
        return new ApacheHttpClient4(handler, config);
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

* @author jamesdbloom
*/
public abstract class AbstractClientProxyIntegrationTest {

    protected HttpClient createHttpClient() throws Exception {
        HttpClientBuilder httpClientBuilder = HttpClients
                .custom()
                .setSslcontext(SSLFactory.getInstance().sslContext())
                .setHostnameVerifier(new AllowAllHostnameVerifier());
        if (Boolean.parseBoolean(System.getProperty("defaultProxySet"))) {
            httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())).build();
        } else if (Boolean.parseBoolean(System.getProperty("proxySet"))) {
            HttpHost httpHost = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
            DefaultProxyRoutePlanner defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(httpHost);
            httpClientBuilder.setRoutePlanner(defaultProxyRoutePlanner).build();
        } else {
            HttpHost httpHost = new HttpHost("localhost", getProxyPort());
            DefaultProxyRoutePlanner defaultProxyRoutePlanner = new DefaultProxyRoutePlanner(httpHost);
            httpClientBuilder.setRoutePlanner(defaultProxyRoutePlanner);
        }
        return httpClientBuilder.build();
    }
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

    @Override
    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
        Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters);
        // http client can be configured from URI options
        HttpClientBuilder clientBuilder = HttpClientBuilder.create();
        // allow the builder pattern
        IntrospectionSupport.setProperties(clientBuilder, parameters, "httpClient.", true);
        // set the Request configure this way and allow the builder pattern
        RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
        IntrospectionSupport.setProperties(requestConfigBuilder, parameters, "httpClient.", true);
        clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
       
        // validate that we could resolve all httpClient. parameters as this component is lenient
        validateParameters(uri, parameters, "httpClient.");
       
        // TODO cmueller: remove the "httpBindingRef" look up in Camel 3.0
View Full Code Here

Examples of org.apache.http.impl.client.HttpClientBuilder

    connManager.setMaxTotal(20);

    ConnectionConfig connectionConfig = ConnectionConfig.custom().setCharset(Consts.UTF_8).build();
    connManager.setDefaultConnectionConfig(connectionConfig);

    HttpClientBuilder clientBuilder = HttpClients.custom().setConnectionManager(connManager);

    Integer timeout = new Long(Utils.parseTimeValue(config, CFG_TIMEOUT, 5, TimeUnit.SECONDS)).intValue();

    if (timeout != null) {
      RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout).build();
      clientBuilder.setDefaultRequestConfig(requestConfig);
    }

    String remoteUsername = Utils.trimToNull(XContentMapValues.nodeStringValue(config.get(CFG_USERNAME), null));
    String remotePassword = XContentMapValues.nodeStringValue(config.get(CFG_PASSWORD), null);
    if (remoteUsername != null) {
      if (remotePassword == null && pwdLoader != null)
        remotePassword = pwdLoader.loadPassword(remoteUsername);
      if (remotePassword != null) {
        try {
          URL urlParsed = new URL(url);
          String host = urlParsed.getHost();
          CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
          credentialsProvider.setCredentials(new AuthScope(host, AuthScope.ANY_PORT), new UsernamePasswordCredentials(
              remoteUsername, remotePassword));
          clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
          isAuthConfigured = true;
        } catch (MalformedURLException e) {
          // this should never happen due validation before
        }
      } else {
        logger.warn("Password not found so authentication is not used!");
        remoteUsername = null;
      }
    } else {
      remoteUsername = null;
    }
    httpclient = clientBuilder.build();
    return remoteUsername;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.