Example usage for org.apache.http.impl.client HttpClientBuilder create

List of usage examples for org.apache.http.impl.client HttpClientBuilder create

Introduction

In this page you can find the example usage for org.apache.http.impl.client HttpClientBuilder create.

Prototype

public static HttpClientBuilder create() 

Source Link

Usage

From source file:com.scoopit.weedfs.client.WeedFSClientBuilder.java

public WeedFSClient build() {
    if (masterUrl == null) {
        try {/*from  www . j ava  2  s.  com*/
            // default url for testing purpose
            masterUrl = new URL("http://localhost:9333");
        } catch (MalformedURLException e) {
            // This cannot happen by construction
            throw new Error(e);
        }
    }

    if (httpClient == null) {
        // minimal http client
        RequestConfig config = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();

        httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
    }

    return new WeedFSClientImpl(masterUrl, httpClient, lookupCache);
}

From source file:de.perdian.apps.dashboard.support.clients.JsonClient.java

public JsonClient(String username, String password, int timeout) {
    RequestConfig.Builder requestBuilder = RequestConfig.custom();
    requestBuilder.setConnectTimeout(timeout);
    requestBuilder.setSocketTimeout(timeout);
    HttpClientBuilder clientBuilder = HttpClientBuilder.create();
    clientBuilder.setDefaultRequestConfig(requestBuilder.build());
    this.setHttpClient(clientBuilder.build());
    this.setDefaultHeaders(new Properties());
    this.setUsername(username);
    this.setPassword(password);
}

From source file:com.opentable.jaxrs.JaxRsClientFactoryImpl.java

private void configureHttpEngine(String clientName, ResteasyClientBuilder clientBuilder,
        JaxRsClientConfig config) {//from  w  w  w.  ja va  2 s.  c o m
    final HttpClientBuilder builder = HttpClientBuilder.create();
    if (config.isEtcdHacksEnabled()) {
        builder.setRedirectStrategy(new ExtraLaxRedirectStrategy())
                .addInterceptorFirst(new SwallowHeaderInterceptor(HttpHeaders.CONTENT_LENGTH));
    }
    final MonitoredPoolingHttpClientConnectionManager connectionManager = new MonitoredPoolingHttpClientConnectionManager(
            clientName);

    connectionManager.setCheckoutWarnTime(Duration.ofMillis(config.connectionPoolWarnTime().getMillis()));
    connectionManager.setMaxTotal(config.connectionPoolSize());
    connectionManager.setDefaultMaxPerRoute(config.httpClientDefaultMaxPerRoute());

    final HttpClient client = builder
            .setDefaultSocketConfig(
                    SocketConfig.custom().setSoTimeout((int) config.socketTimeout().getMillis()).build())
            .setDefaultRequestConfig(customRequestConfig(config, RequestConfig.custom()))
            .setConnectionManager(connectionManager).build();
    final ApacheHttpClient4Engine engine = new HackedApacheHttpClient4Engine(config, client);
    clientBuilder.httpEngine(engine);
}

From source file:org.apache.synapse.samples.framework.clients.BasicHttpClient.java

/**
 * Make a HTTP OPTIONS request on the specified URL.
 *
 * @param url A valid HTTP URL//w w  w .  ja  v a  2  s .co  m
 * @return A HttpResponse object
 * @throws Exception If an error occurs while making the HTTP call
 */
public HttpResponse doOptions(String url) throws Exception {
    CloseableHttpClient client = HttpClientBuilder.create().build();
    try {
        HttpOptions options = new HttpOptions(url);
        return new HttpResponse(client.execute(options));
    } finally {
        client.close();
    }
}

From source file:io.liveoak.keycloak.AuthInterceptorTest.java

@Before
public void before() throws Exception {
    System.err.println("** A");
    tokenUtil = new TokenUtil("liveoak-apps");
    System.err.println("** B");
    httpClient = HttpClientBuilder.create().build();
    System.err.println("** C");

    mock = (MockRootResource) system.service(Services.resource("testApp", "auth-test"));
}

From source file:de.unirostock.sems.cbarchive.web.importer.HttpImporter.java

public HttpImporter(String remoteUrl, UserManager user) {
    super(user);/* w  ww. j  a va  2s .  c o  m*/
    this.remoteUrl = remoteUrl;
    this.client = HttpClientBuilder.create().build();
}

From source file:com.jkoolcloud.tnt4j.streams.fields.ActivityCacheTest.java

@Test
public void runStreams() throws Exception {
    InputStreamListener streamListener = mock(InputStreamListener.class);
    StreamTasksListener streamTasksListener = mock(StreamTasksListener.class);
    StreamsAgent.runFromAPI(cfgFile, streamListener, streamTasksListener);

    Thread.sleep(3000);// w  w w  .j av a  2 s .  c o m

    HttpClientBuilder builder = HttpClientBuilder.create();
    HttpClient client = builder.build();

    Thread.sleep(500);

    sendRequest(client, PROGRESS_FILE);
    sendRequest(client, START_FILE);

    Thread.sleep(50000);

    verify(streamListener, times(2)).onStatusChange(any(TNTInputStream.class), (StreamStatus) any());
}

From source file:com.testlinkrestapi.restclient.RestClient.java

public RestClient(String username, String password) {
    this.username = username;
    this.password = password;
    httpClient = HttpClientBuilder.create().build();
}

From source file:org.apache.edgent.connectors.http.HttpClients.java

/**
 * Method to create a basic authentication HTTP client.
 * The functions {@code user} and {@code password} are called
 * when this method is invoked to obtain the user and password
 * and runtime./*from  w w  w.jav a  2  s  . co m*/
 * 
 * @param user Function that provides user for authentication
 * @param password  Function that provides password for authentication
 * @return HTTP client with basic authentication.
 * 
 * @see HttpStreams
 */
public static CloseableHttpClient basic(Supplier<String> user, Supplier<String> password) {

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user.get(), password.get()));

    return HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
}

From source file:org.fcrepo.auth.integration.AbstractResourceIT.java

public AbstractResourceIT() {
    client = HttpClientBuilder.create().setMaxConnPerRoute(5).setMaxConnTotal(Integer.MAX_VALUE).build();
}