List of usage examples for org.apache.http.impl.client HttpClients createDefault
public static CloseableHttpClient createDefault()
From source file:com.github.patrickianwilson.blogs.testing.induction.integration.JaxRsIntegrationRunner.java
@Test public void verifyServiceHealthy() throws IOException { CloseableHttpClient client = HttpClients.createDefault(); HttpGet getStatus = new HttpGet("http://localhost:8080/status"); CloseableHttpResponse statusResp = client.execute(getStatus); Assert.assertThat("Non 200 status response received", statusResp.getStatusLine().getStatusCode(), is(200)); }
From source file:org.wuspba.ctams.ws.ITBandContestEntryController.java
@Test public void testListAll() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); LOG.info("Connecting to " + uri.toString()); HttpGet httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getBandContestEntry().size(), 1); testEquality(doc.getBandContestEntry().get(0), TestFixture.INSTANCE.bandContestEntry); EntityUtils.consume(entity);/* w ww.ja v a 2 s . c o m*/ } }
From source file:org.wuspba.ctams.ws.ITSoloContestEntryController.java
@Test public void testListAll() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); LOG.info("Connecting to " + uri.toString()); HttpGet httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getSoloContestEntry().size(), 1); testEquality(doc.getSoloContestEntry().get(0), TestFixture.INSTANCE.soloContestEntry); EntityUtils.consume(entity);/*from w ww .j a va2s. c o m*/ } }
From source file:ru.iris.noolite4j.gateway.HTTPCommand.java
/** * ? R1132/*from w w w .j a va2 s. co m*/ * @return ? */ public boolean send() { String buildUrl = "http://" + PR1132.getHost() + "/api.htm?ch=" + channel + "&cmd=" + cmd.ordinal(); if (br != 0) buildUrl += "&br=" + (br & 0xff); if (fmt != null) buildUrl += "&fmt=" + fmt.ordinal(); if (d0 != 0) buildUrl += "&d0=" + (d0 & 0xff); if (d1 != 0) buildUrl += "&d1=" + (d1 & 0xff); if (d2 != 0) buildUrl += "&d2=" + (d2 & 0xff); if (d3 != 0) buildUrl += "&d3=" + (d3 & 0xff); try { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpget = new HttpGet(buildUrl); CloseableHttpResponse response = httpclient.execute(httpget); return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK; } catch (IOException e) { LOGGER.error(" PR1132: " + e.getMessage()); e.printStackTrace(); } return false; }
From source file:org.wso2.carbon.identity.application.authentication.endpoint.client.AuthAPIServiceClient.java
/** * Constructor to initialize service client. * * @param apiBasePath base bath of the API. *///from ww w . ja v a 2 s.c om public AuthAPIServiceClient(String apiBasePath) { httpClient = HttpClients.createDefault(); basePath = apiBasePath; }
From source file:com.amazonaws.devicefarm.DeviceFarmUploader.java
/** * Upload a single file, waits for upload to complete. * @param file the file//from w ww . ja v a 2 s . co m * @param project the project * @param uploadType the upload type * @return upload object */ public Upload upload(final File file, final Project project, final UploadType uploadType) { if (!(file.exists() && file.canRead())) { throw new DeviceFarmException(String.format("File %s does not exist or is not readable", file)); } final CreateUploadRequest appUploadRequest = new CreateUploadRequest().withName(file.getName()) .withProjectArn(project.getArn()).withContentType("application/octet-stream") .withType(uploadType.toString()); final Upload upload = api.createUpload(appUploadRequest).getUpload(); final CloseableHttpClient httpClient = HttpClients.createDefault(); final HttpPut httpPut = new HttpPut(upload.getUrl()); httpPut.setHeader("Content-Type", upload.getContentType()); final FileEntity entity = new FileEntity(file); httpPut.setEntity(entity); writeToLog(String.format("Uploading %s to S3", file.getName())); final HttpResponse response; try { response = httpClient.execute(httpPut); } catch (IOException e) { throw new DeviceFarmException(String.format("Error uploading artifact %s", file), e); } if (response.getStatusLine().getStatusCode() != 200) { throw new DeviceFarmException(String.format("Upload returned non-200 responses: %s", response.getStatusLine().getStatusCode())); } waitForUpload(file, upload); return upload; }
From source file:com.github.caldav4j.support.HttpClientTestUtils.java
public static <R, M extends HttpRequestBase, E extends Exception> R executeMethod(int expectedStatus, M method, HttpMethodCallback<R, M, E> methodCallback) throws IOException, E { HttpHost host = new HttpHost("localhost", 80); HttpClient client = HttpClients.createDefault(); return executeMethod(expectedStatus, method, client, host, methodCallback); }
From source file:it.av.fac.driver.APIClient.java
public boolean storageRequest(String userToken, JSONObject resource) { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost(endpoint + ADMIN_PATH); List<NameValuePair> nvps = new ArrayList<>(); nvps.add(new BasicNameValuePair("resource", URLEncoder.encode(resource.toString(), "UTF-8"))); nvps.add(new BasicNameValuePair("token", URLEncoder.encode(userToken, "UTF-8"))); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); // Create a custom response handler ResponseHandler<Boolean> responseHandler = (final HttpResponse response) -> { int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { return status == 200; } else { throw new ClientProtocolException("Unexpected response status: " + status); }// w w w . j a va 2 s .co m }; return httpclient.execute(httpPost, responseHandler); } catch (IOException ex) { Logger.getLogger(APIClient.class.getName()).log(Level.SEVERE, null, ex); return false; } }
From source file:twister.rpc.TwisterPeer.java
public CloseableHttpClient newClient() { //return HttpClients.custom().setConnectionManager(conman).build(); return HttpClients.createDefault(); }
From source file:com.vmware.identity.rest.core.client.BaseClient.java
/** * Constructs a client with a {@code host} and {@code secure} flag. * This will use the default {@link HttpClient} and a {@link SimpleHostRetriever}. * The port is assumed to be the default port (-1). * * @see HttpClients#createDefault()/* w w w .j av a 2 s . c om*/ * @param host the hostname of the remote REST server. * @param secure a flag indicating whether the connection is secure or not. */ protected BaseClient(String host, boolean secure) { this(new SimpleHostRetriever(host, secure), HttpClients.createDefault()); }