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:nl.ivonet.io.WebResource.java

private WebResource() {
    client = HttpClientBuilder.create().build();
}

From source file:com.dtstack.jlogstash.distributed.http.cilent.HttpClient.java

private static CloseableHttpClient getHttpClient() {
    return HttpClientBuilder.create().build();
}

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

/**
 * Create HTTP client with no authentication.
 * @return HTTP client with basic authentication.
 * /*from  w w  w.j a  va  2s .c  om*/
 * @see HttpStreams
 */
public static CloseableHttpClient noAuthentication() {
    return HttpClientBuilder.create().build();
}

From source file:com.oracle.jes.samples.hellostorage.SendToServlet.java

public String sendRecord(String data, String srvName) {
    mode = false;/*w w w .  j av a2  s  .  c om*/
    String out = null;

    //   DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpClient httpclient = HttpClientBuilder.create().build();

    HttpPost httppostreq;
    if (!mode) {

        httppostreq = new HttpPost("http://192.168.1.5:8080/pichrony/" + srvName);

    } else {
        httppostreq = new HttpPost("http://security.netmaxjava.com/phlogin");

    }

    StringEntity se = null;

    try {
        se = new StringEntity(data);
    } catch (UnsupportedEncodingException ex) {
        //Logger.getLogger(RegisterDevice.class.getName()).log(Level.SEVERE, null, ex);
    }

    //   se.setContentType("application/json;");

    httppostreq.setEntity(se);

    try {
        HttpResponse respo = httpclient.execute(httppostreq);
        if (respo != null) {
            out = "";
            InputStream inputstream = respo.getEntity().getContent();
            out = convertStreamToString(inputstream);

        } else {

        }
    } catch (ClientProtocolException e) {

    } catch (IOException | IllegalStateException e) {
    }
    return out;
}

From source file:com.cisco.cta.taxii.adapter.httpclient.HttpClientFactory.java

public HttpClient create() {
    HttpClientBuilder clientBuilder = HttpClientBuilder.create();
    if (proxySettings.getUrl() != null) {
        URL proxyUrl = proxySettings.getUrl();
        HttpHost proxyHost = new HttpHost(proxyUrl.getHost(), proxyUrl.getPort(), proxyUrl.getProtocol());
        clientBuilder.setProxy(proxyHost);
    }/* ww  w  .j ava  2 s  . c  om*/
    return clientBuilder.build();
}

From source file:com.mycompany.internalservicecontrollerbatch.ServerCall.java

@Override
public void run() {
    String url = list.getCallToPerform();
    try {//w w  w.ja  va 2s . c om
        HttpClient client = HttpClientBuilder.create().build();
        if (url != null) {

            //HttpPost post = new HttpPost(url);
            //StringEntity entity = new StringEntity("");
            //post.setEntity(entity);

            HttpGet request = new HttpGet(url);
            long start = System.currentTimeMillis();
            HttpResponse response = client.execute(request);
            long end = System.currentTimeMillis();
            //System.out.println("Response Code : "+ response.getStatusLine().getStatusCode() + " index: " +index + " start: " + start + " end: " +end+ " thread name: "+ Thread.currentThread().getName());
            double r = Math.random();
            long wait = Math.round(r * 250);
            HttpEntity entity = response.getEntity();
            String responseString = EntityUtils.toString(entity, "UTF-8");
            String printout = "Server Call: " + url + " Response Code : "
                    + response.getStatusLine().getStatusCode() + " Response content: " + responseString;
            list.resolveCall(printout, true);
            Thread.sleep(wait);
        }
    } catch (Exception ex) {
        Logger.getLogger(ServerCall.class.getName()).log(Level.SEVERE, null, ex);
        list.resolveCall("ERROR PERFORMING: " + url, false);
    }

}

From source file:com.oracle.jes.samples.hellostorage.httpcPoster1.java

public String putMessage(int i, String vel, String ser) {

    String out = null;// ww w  .  j a v a  2 s .co m

    HttpClient httpclient = HttpClientBuilder.create().build();

    HttpPost httppostreq = new HttpPost("http://192.168.1.5:8080/async-request-war/AjaxCometServlet");
    //HttpPost httppostreq = new HttpPost("http://192.168.1.5:8080/pichrony/AjaxCometServlet");

    //HttpPost httppostreq = new HttpPost("http://192.168.1.5:8080/async-request-war/AjServlet");

    List<NameValuePair> pairs = new ArrayList<NameValuePair>();

    if (i == 1) {
        pairs.add(new BasicNameValuePair("action", "login"));
        pairs.add(new BasicNameValuePair("name", ser));
    } else {
        FindMac fm = new FindMac();

        String m = fm.getAddr();

        pairs.add(new BasicNameValuePair("action", "post"));
        pairs.add(new BasicNameValuePair("name", ser));
        pairs.add(new BasicNameValuePair("message", vel));

    }

    try {
        httppostreq.setEntity(new UrlEncodedFormEntity(pairs));
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        //e1.printStackTrace();
    }

    /*
    StringEntity se=null;
    try {
       se = new StringEntity(jsono.toString());
    } catch (UnsupportedEncodingException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }
            
            
            
    se.setContentType("application/json;charset=UTF-8");
    se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8"));
    httppostreq.setEntity(se);
    */

    //HttpGet httpget = new HttpGet("http://192.168.1.5:8080/async-request-war/AjServlet");

    try {
        HttpResponse response = httpclient.execute(httppostreq);

        if (response != null) {
            out = "";
            InputStream inputstream = response.getEntity().getContent();
            out = convertStreamToString(inputstream);

        } else {

        }
    } catch (ClientProtocolException e) {

    } catch (IOException e) {
    } catch (Exception e) {
    }
    return out;
}

From source file:org.dspace.app.sherpa.SHERPAService.java

public SHERPAService() {
    HttpClientBuilder builder = HttpClientBuilder.create();
    // httpclient 4.3+ doesn't appear to have any sensible defaults any more. Setting conservative defaults as not to hammer the SHERPA service too much.
    client = builder.disableAutomaticRetries().setMaxConnTotal(5).build();
}

From source file:uk.gov.hmrc.service.ServiceConnector.java

public ServiceConnector() {
    client = HttpClientBuilder.create().build();
}

From source file:com.helpers.ServiceLocationsHelper.java

public static String getLocations(String opportunityId) throws Exception {
    String accountId = getAccountId(opportunityId);

    final String soql = "SELECT+Id,Name,pricesenz__Account__c,pricesenz__Door_Number__c,pricesenz__Street_Name__c,pricesenz__City__c,pricesenz__State__c+FROM+pricesenz__Service_Location__c+where+pricesenz__Account__c+=+'"
            + accountId + "'";

    HttpClient httpClient = HttpClientBuilder.create().build();
    if (loginInstanceUrl == null) {
        try {/*from  w w  w  .  jav a2 s .  c  o  m*/
            LoginHelper.getAccessToken("");
        } catch (Exception ex) {
        }
    }
    baseUri = loginInstanceUrl + SOAP_ENDPOINT;
    oauthHeader = new BasicHeader("Authorization", "Bearer " + accessToken);

    String uri = baseUri + "/query?q=" + soql;
    //        System.out.println("Query URL: " + uri);
    HttpGet httpGet = new HttpGet(uri);
    httpGet.addHeader(oauthHeader);
    httpGet.addHeader(prettyPrintHeader);

    // Make the request.
    HttpResponse httpResponse = httpClient.execute(httpGet);
    String getResponse = EntityUtils.toString(httpResponse.getEntity());
    //        System.out.println("Query Result:\n" + getResponse);
    return getResponse;
}