List of usage examples for org.apache.http.impl.client HttpClientBuilder create
public static HttpClientBuilder create()
From source file:rc.championship.platform.decoder.lap.publisher.JaxRSLapPublisher.java
private void send(String url, List<Lap> laps) { try {//from w w w . jav a 2 s .c o m String json = convertToJsonArray(laps); HttpClient client = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(url); StringEntity input = new StringEntity(json); post.setEntity(input); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
From source file:com.kenai.redminenb.repository.RedmineManagerFactoryHelper.java
public static HttpClient getTransportConfig() { /**/* w w w . j av a 2 s . c om*/ * Implement a minimal hostname verifier. This is needed to be able to use * hosts with certificates, that don't match the used hostname (VServer). * * This is implemented by first trying the "Browser compatible" hostname * verifier and if that fails, fall back to the default java hostname * verifier. * * If the default case the hostname verifier in java always rejects, but * for netbeans the "SSL Certificate Exception" module is available that * catches this and turns a failure into a request to the GUI user. */ X509HostnameVerifier hostnameverified = new X509HostnameVerifier() { @Override public void verify(String string, SSLSocket ssls) throws IOException { if (SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER.verify(string, ssls.getSession())) { return; } if (!HttpsURLConnection.getDefaultHostnameVerifier().verify(string, ssls.getSession())) { throw new SSLException("Hostname did not verify"); } } @Override public void verify(String string, X509Certificate xc) throws SSLException { throw new SSLException("Check not implemented yet"); } @Override public void verify(String string, String[] strings, String[] strings1) throws SSLException { throw new SSLException("Check not implemented yet"); } @Override public boolean verify(String string, SSLSession ssls) { if (SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER.verify(string, ssls)) { return true; } return HttpsURLConnection.getDefaultHostnameVerifier().verify(string, ssls); } }; try { SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(SSLContext.getDefault(), hostnameverified); HttpClient hc = HttpClientBuilder.create() .setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())) .setSSLSocketFactory(scsf).build(); return hc; } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } }
From source file:at.ac.tuwien.dsg.esperstreamprocessing.utils.RestHttpClient.java
public void callPostMethod(List<NameValuePair> paramList) { try {//from w w w . j a va2 s. c om HttpPost post = new HttpPost(url); // add header // post.setHeader("Host", "smartsoc.infosys.tuwien.ac.at"); //post.setHeader("User-Agent", USER_AGENT); //post.setHeader("Connection", "keep-alive"); post.setHeader("Content-Type", "application/x-www-form-urlencoded"); // set content post.setEntity(new UrlEncodedFormEntity(paramList)); // Logger.getLogger(EventHandler.class.getName()).log(Level.INFO, "\nSending 'POST' request to URL : " + url); // Logger.getLogger(EventHandler.class.getName()).log(Level.INFO, "Configuring.."); // Logger.getLogger(EventHandler.class.getName()).log(Level.INFO, "Post parameters : " + paramList); HttpClient client = HttpClientBuilder.create().build(); HttpResponse response = client.execute(post); int responseCode = response.getStatusLine().getStatusCode(); Logger.getLogger(RestHttpClient.class.getName()).log(Level.INFO, "Connection : " + url); Logger.getLogger(RestHttpClient.class.getName()).log(Level.INFO, "Response Code : " + responseCode); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } // Logger.getLogger(EventHandler.class.getName()).log(Level.INFO, result.toString()); } catch (Exception ex) { } }
From source file:org.qucosa.camel.component.sword.SwordConnection.java
private HttpClient prepareHttpClient() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); HttpClient client = HttpClientBuilder.create().setConnectionManager(connectionManager) .setDefaultCredentialsProvider(credentialsProvider).build(); return client; }
From source file:com.siblinks.ws.Notification.Helper.FireBaseNotification.java
public String sendMessage(final String toTokenId, final String title, final String dataType, final String dataId, final String content, final String icon, final String priority) { InputStreamReader in = null;/*ww w . j a v a 2 s .c o m*/ BufferedReader br = null; String lines = ""; try { // FirebaseOptions options = new FirebaseOptions.Builder() // .setServiceAccount(new // FileInputStream("path/to/serviceAccountCredentials.json")) // .setDatabaseUrl("https://databaseName.firebaseio.com/") // .build(); // FirebaseApp.initializeApp(options); HttpClient client = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(SibConstants.URL_SEND_NOTIFICATION_FIREBASE); post.setHeader("Content-type", "application/json"); post.setHeader("Authorization", "key=" + env.getProperty("firebase.server.key")); JSONObject message = new JSONObject(); message.put(Parameters.TO, toTokenId); message.put(Parameters.PRIORITY, priority); JSONObject notification = new JSONObject(); notification.put(Parameters.TITLE, title); notification.put(Parameters.BODY, content); // click action JSONObject clickAction = new JSONObject(); clickAction.put(Parameters.DATA_ID, dataId); clickAction.put(Parameters.DATA_TYPE, dataType); notification.put(Parameters.CLICK_ACTION, clickAction); // message.put(Parameters.NOTIFICATION, notification); StringEntity mesage = new StringEntity(message.toString(), "UTF-8"); logger.info("Message send Firebase: " + message.toString()); post.setEntity(mesage); HttpResponse response = client.execute(post); in = new InputStreamReader(response.getEntity().getContent(), "UTF-8"); br = new BufferedReader(in); String line = null; while ((line = br.readLine()) != null) { lines += line; } logger.info("Send Firebase result: " + lines.toString()); } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } finally { try { if (in != null) { in.close(); } if (br != null) { br.close(); } } catch (IOException e) { // Do nothing } } return lines; }
From source file:org.apache.commons.jcs.auxiliary.remote.http.client.AbstractHttpClient.java
/** * Sets the default Properties File and Heading, and creates the HttpClient and connection * manager.//from ww w . j a va 2 s . c om * <p> * @param remoteHttpCacheAttributes */ public AbstractHttpClient(RemoteHttpCacheAttributes remoteHttpCacheAttributes) { this.remoteHttpCacheAttributes = remoteHttpCacheAttributes; String httpVersion = getRemoteHttpCacheAttributes().getHttpVersion(); if ("1.1".equals(httpVersion)) { this.httpVersion = HttpVersion.HTTP_1_1; } else if ("1.0".equals(httpVersion)) { this.httpVersion = HttpVersion.HTTP_1_0; } else { log.warn("Unrecognized value for 'httpVersion': [" + httpVersion + "], defaulting to 1.1"); this.httpVersion = HttpVersion.HTTP_1_1; } HttpClientBuilder builder = HttpClientBuilder.create(); configureClient(builder); this.httpClient = builder.build(); }
From source file:org.craftercms.studio.impl.v1.deployment.PreviewDeployerImpl.java
public PreviewDeployerImpl() { RequestConfig requestConfig = RequestConfig.custom().setExpectContinueEnabled(true).build(); httpClient = HttpClientBuilder.create().setConnectionManager(new PoolingHttpClientConnectionManager()) .setDefaultRequestConfig(requestConfig).build(); }
From source file:org.jboss.additional.testsuite.jdkall.present.ejb.sfsb.SfsbTestCase.java
@Test @OperateOnDeployment(DEPLOYMENT)/*from w ww .j a v a 2s. c o m*/ public void sfsbTest(@ArquillianResource URL url) throws Exception { URL testURL = new URL(url.toString() + "sfsbCache?product=makaronia&quantity=10"); final HttpGet request = new HttpGet(testURL.toString()); CloseableHttpClient httpClient = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; try { response = httpClient.execute(request); Assert.assertEquals("Failed to access " + testURL, HttpURLConnection.HTTP_OK, response.getStatusLine().getStatusCode()); Thread.sleep(1000); response = httpClient.execute(request); Assert.assertEquals("Failed to access " + testURL, HttpURLConnection.HTTP_OK, response.getStatusLine().getStatusCode()); } finally { IOUtils.closeQuietly(response); httpClient.close(); } }