List of usage examples for org.apache.http.client.methods CloseableHttpResponse getStatusLine
StatusLine getStatusLine();
From source file:com.networknt.health.HealthHandlerTest.java
@Test public void testHealth() throws Exception { String url = "http://localhost:8080/server/health"; CloseableHttpClient client = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(url); try {/*from ww w . ja v a 2s. c om*/ CloseableHttpResponse response = client.execute(httpGet); int statusCode = response.getStatusLine().getStatusCode(); Assert.assertEquals(200, statusCode); if (statusCode == 200) { String s = IOUtils.toString(response.getEntity().getContent(), "utf8"); Assert.assertNotNull(s); Assert.assertEquals("OK", s); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.anrisoftware.simplerest.core.AbstractSimpleGetWorker.java
/** * Makes the request and retrieves the data. * * @return the data./*from www .jav a 2 s . c o m*/ * * @throws SimpleRestException */ public T retrieveData() throws SimpleRestException { CloseableHttpClient httpclient = createHttpClient(); HttpGet httpget = createHttpGet(); CloseableHttpResponse response = executeRequest(httpclient, httpget); StatusLine statusLine = response.getStatusLine(); return parseResponse(response, httpget, statusLine); }
From source file:com.networknt.audit.ServerInfoHandlerTest.java
@Test public void testServerInfo() throws Exception { String url = "http://localhost:8080/server/info"; CloseableHttpClient client = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(url); try {//from w ww. j a v a2 s .com CloseableHttpResponse response = client.execute(httpGet); int statusCode = response.getStatusLine().getStatusCode(); Assert.assertEquals(200, statusCode); if (statusCode == 200) { String s = IOUtils.toString(response.getEntity().getContent(), "utf8"); Assert.assertNotNull(s); logger.debug(s); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jboss.integration.fuse.camel.test.KieCamelJbpmWorkitemsQuickstartTest.java
@Test public void test() throws Exception { int port = 8080; CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://localhost:" + port + "/jbpm-workitems-camel/mortgage"); CloseableHttpResponse response = httpclient.execute(httpGet); try {/*from www.j a va2 s .c om*/ System.out.println(response.getStatusLine()); assertTrue(response.getStatusLine().getStatusCode() == 200); HttpEntity entity1 = response.getEntity(); // do something useful with the response body // and ensure it is fully consumed StringWriter writer = new StringWriter(); IOUtils.copy(entity1.getContent(), writer); String content = writer.toString(); System.out.println("RESPONSE:\n" + content); assertTrue(content.contains("Accepted Applications")); assertTrue(content.contains("Rejected Applications")); } finally { response.close(); } }
From source file:org.wildfly.test.integration.microprofile.health.MicroProfileHealthSecuredHTTPEndpointEmptyMgmtUsersTestCase.java
@Test public void securedHTTPEndpointWithoutUserDefined() throws Exception { final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/health"; try (CloseableHttpClient client = HttpClients.createDefault()) { CloseableHttpResponse resp = client.execute(new HttpGet(healthURL)); assertEquals(500, resp.getStatusLine().getStatusCode()); String content = MicroProfileHealthHTTPEndpointTestCase.getContent(resp); resp.close();//from w w w . ja v a2s . co m assertTrue("'WFLYDMHTTP0016: Your Application Server is running. However ...' message is expected", content.contains("WFLYDMHTTP0016")); } }
From source file:guru.nidi.ramltester.loader.FormLoginUrlFetcher.java
@Override public InputStream fetchFromUrl(CloseableHttpClient client, String base, String name) { try {/* www. j ava 2s . c om*/ final HttpPost login = new HttpPost(base + "/" + loginUrl); List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair(loginField, this.login)); params.add(new BasicNameValuePair(passwordField, password)); postProcessLoginParameters(params); login.setEntity(new UrlEncodedFormEntity(params)); final CloseableHttpResponse getResult = client.execute(postProcessLogin(login)); if (getResult.getStatusLine().getStatusCode() != HttpStatus.SC_MOVED_TEMPORARILY) { throw new RamlLoader.ResourceNotFoundException(name, "Could not login: " + getResult.getStatusLine().toString()); } EntityUtils.consume(getResult.getEntity()); return super.fetchFromUrl(client, base + "/" + loadPath, name); } catch (IOException e) { throw new RamlLoader.ResourceNotFoundException(name, e); } }
From source file:com.nibss.util.Request.java
public void post(String url, List<NameValuePair> list) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try {// w ww . j a v a 2 s. com HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(list)); CloseableHttpResponse response2 = httpclient.execute(httpPost); try { System.out.println(response2.getStatusLine().getStatusCode()); HttpEntity entity2 = response2.getEntity(); EntityUtils.consume(entity2); } finally { response2.close(); } } finally { httpclient.close(); } }
From source file:com.anrisoftware.simplerest.core.AbstractSimplePutWorker.java
/** * Makes the request and sends the data and retrieves the response. * * @param entity//from w w w .j av a2s .c o m * the {@link HttpEntity} entity. * * @return the response. * * @throws SimpleRestException */ public T sendData(HttpEntity entity) throws SimpleRestException { CloseableHttpClient httpclient = createHttpClient(); HttpPut httpput = new HttpPut(requestUri); httpput.setEntity(entity); for (Header header : headers) { httpput.addHeader(header); } CloseableHttpResponse response = executeRequest(httpclient, httpput); StatusLine statusLine = response.getStatusLine(); return parseResponse(response, httpput, statusLine); }
From source file:io.crate.integrationtests.RestSQLActionIntegrationTest.java
@Test public void testSetCustomSchema() throws IOException { execute("create table custom.foo (id string)"); Header[] headers = new Header[] { new BasicHeader("Default-Schema", "custom") }; CloseableHttpResponse response = post("{\"stmt\": \"select * from foo\"}", headers); assertThat(response.getStatusLine().getStatusCode(), is(200)); response = post("{\"stmt\": \"select * from foo\"}"); assertThat(response.getStatusLine().getStatusCode(), is(404)); assertThat(EntityUtils.toString(response.getEntity()), containsString("TableUnknownException")); }
From source file:org.elasticsearch.river.solr.support.SolrIndexer.java
public void clearDocuments() throws IOException { HttpPost httpPost = new HttpPost(solrUrl + "?commit=true"); httpPost.setHeader("Content-type", "application/xml"); httpPost.setEntity(new StringEntity("<delete><query>*:*</query></delete>")); CloseableHttpResponse response = httpClient.execute(httpPost); try {/*from www . ja v a 2 s. c o m*/ if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("documents were not properly cleared"); } } finally { EntityUtils.consume(response.getEntity()); response.close(); } }