List of usage examples for org.apache.http.impl.client HttpClientBuilder create
public static HttpClientBuilder create()
From source file:com.jive.myco.seyren.core.service.notification.HubotNotificationService.java
@Override public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException { String hubotUrl = StringUtils.trimToNull(seyrenConfig.getHubotUrl()); if (hubotUrl == null) { LOGGER.warn("Hubot URL needs to be set before sending notifications to Hubot"); return;/*from w w w . j a v a 2 s .c o m*/ } Map<String, Object> body = new HashMap<String, Object>(); body.put("seyrenUrl", seyrenConfig.getBaseUrl()); body.put("check", check); body.put("subscription", subscription); body.put("alerts", alerts); body.put("rooms", subscription.getTarget().split(",")); HttpClient client = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(hubotUrl + "/seyren/alert"); try { HttpEntity entity = new StringEntity(MAPPER.writeValueAsString(body), ContentType.APPLICATION_JSON); post.setEntity(entity); client.execute(post); } catch (IOException e) { throw new NotificationFailedException("Sending notification to Hubot at " + hubotUrl + " failed.", e); } finally { HttpClientUtils.closeQuietly(client); } }
From source file:org.trustedanalytics.servicebroker.hdfs.config.hgm.HgmHttpsConfiguration.java
@Bean @Qualifier("hgmRestTemplate") public RestTemplate getHgmHttpsRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS() .build();//from www.j a va2s .c o m SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier()); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword())); HttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(connectionFactory) .setDefaultCredentialsProvider(credentialsProvider).build(); ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); return new RestTemplate(requestFactory); }
From source file:me.Aron.Heinecke.fbot.lib.Socket.java
/*** * Socket init/*from w ww. j a v a 2 s . c om*/ * No content compression, fixing download problematics, * no automatic retries, fixing undocumented loops, causing * hangups */ public Socket() { if (fbot.isDebug()) fbot.getLogger().debug("socket", "initializing"); hcbuilder = HttpClientBuilder.create(); hcbuilder.setConnectionManager(connManager); hcbuilder.disableContentCompression(); hcbuilder.disableAutomaticRetries(); client = hcbuilder.build(); }
From source file:org.wildfly.elytron.web.undertow.server.BasicAuthenticationTest.java
@Test public void testSuccessfulAuthentication() throws Exception { HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet get = new HttpGet(server.createUri()); get.addHeader(AUTHORIZATION.toString(), BASIC + " " + FlexBase64.encodeString("elytron:Coleoptera".getBytes(), false)); HttpResponse result = httpClient.execute(get); assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); assertSuccessfulResponse(result, "elytron"); }
From source file:org.apache.nifi.api.client.impl.AbstractNiFiAPIClient.java
protected void setupClient(String server, String port) { this.server = server; this.port = port; this.baseUrl = "http://" + this.server + ":" + this.port + "/nifi-api"; this.client = HttpClientBuilder.create().build(); this.mapper = new ObjectMapper(); this.mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); this.mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss Z"); this.mapper.setDateFormat(dateFormat); }
From source file:com.flipkart.flux.client.runtime.FluxRuntimeConnectorHttpImpl.java
public FluxRuntimeConnectorHttpImpl(Long connectionTimeout, Long socketTimeout, String fluxEndpoint) { objectMapper = new ObjectMapper(); this.fluxEndpoint = fluxEndpoint; RequestConfig clientConfig = RequestConfig.custom().setConnectTimeout((connectionTimeout).intValue()) .setSocketTimeout((socketTimeout).intValue()) .setConnectionRequestTimeout((socketTimeout).intValue()).build(); PoolingHttpClientConnectionManager syncConnectionManager = new PoolingHttpClientConnectionManager(); syncConnectionManager.setMaxTotal(MAX_TOTAL); syncConnectionManager.setDefaultMaxPerRoute(MAX_PER_ROUTE); closeableHttpClient = HttpClientBuilder.create().setDefaultRequestConfig(clientConfig) .setConnectionManager(syncConnectionManager).build(); Runtime.getRuntime().addShutdownHook(new Thread(() -> { HttpClientUtils.closeQuietly(closeableHttpClient); }));/*from w ww.j a v a 2 s . c o m*/ }
From source file:org.apache.camel.component.cxf.jaxrs.CxfRsSpringConsumerTest.java
@Test public void testMappingException() throws Exception { HttpGet get = new HttpGet( "http://localhost:" + port1 + "/CxfRsSpringConsumerTest/customerservice/customers/126"); get.addHeader("Accept", "application/json"); CloseableHttpClient httpclient = HttpClientBuilder.create().build(); try {// w w w . j a va 2s . co m HttpResponse response = httpclient.execute(get); assertEquals("Get a wrong status code", 500, response.getStatusLine().getStatusCode()); assertEquals("Get a worng message header", "exception: Here is the exception", response.getHeaders("exception")[0].toString()); } finally { httpclient.close(); } }
From source file:fi.aalto.drumbeat.apicalls.marmotta.MarmottaAPI.java
@SuppressWarnings("unchecked") public void httpGetMarmottaContexts(Table table) { try {/*from ww w .ja va 2s . c o m*/ if (table.isVisible()) table.removeAllItems(); } catch (Exception e) { //update before table initalization? return; } try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) { HttpGet request = new HttpGet(DrumbeatConstants.marmotta_context_query_url); HttpResponse http_result = httpClient.execute(request); String json = EntityUtils.toString(http_result.getEntity(), "UTF-8"); try { JSONParser parser = new JSONParser(); Object resultObject = parser.parse(json); if (resultObject instanceof JSONArray) { JSONArray result = (JSONArray) resultObject; if (result != null) { for (Object obj : result) { // Add a row the hard way Object newItemId = table.addItem(); Item row = table.getItem(newItemId); JSONObject project = (JSONObject) obj; String name = (String) project.get("label"); if (name != null) row.getItemProperty("Graph").setValue(name); else row.getItemProperty("Graph").setValue("-"); Long size = (Long) project.get("size"); if (size != null) row.getItemProperty("Size").setValue(size); else row.getItemProperty("Size").setValue("-"); } } } } catch (Exception e) { e.printStackTrace(); } } catch (IOException ex) { ex.printStackTrace(); } // Show exactly the currently contained rows (items) table.setPageLength(table.size()); }
From source file:org.codemucker.testserver.TestServerTest.java
@SuppressWarnings("serial") @Test// w w w . ja v a2s . co m public void ensure_custom_servlets_are_invoked() throws Exception { final Collection<CapturedRequest> capturedRequests = new Vector<CapturedRequest>(); server.addServlet("/my/test/path", new TestServlet() { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { capturedRequests.add(new CapturedRequest(req)); resp.setStatus(HttpServletResponse.SC_OK); } }); server.start(); final long paramX = System.currentTimeMillis(); final String url = "http://" + server.getHost() + ":" + server.getHttpPort() + "/my/test/path?x=" + paramX; //check we can hit the servlet, that it's run only once, and that we get the params passed to it final HttpClient client = HttpClientBuilder.create().build(); final HttpGet get = new HttpGet(url); final HttpResponse resp = client.execute(get); assertEquals(HttpServletResponse.SC_OK, resp.getStatusLine().getStatusCode()); assertEquals(1, capturedRequests.size()); final CapturedRequest req = capturedRequests.iterator().next(); assertEquals(paramX + "", req.getParameters().get("x").iterator().next()); }
From source file:org.jboss.as.test.integration.web.response.DefaultResponseCodeTestCase.java
@Before public void setup() { this.httpclient = HttpClientBuilder.create().build(); }