List of usage examples for org.apache.http.client.methods CloseableHttpResponse getFirstHeader
Header getFirstHeader(String str);
From source file:ch.ralscha.extdirectspring_itest.InfoControllerTest.java
@Test public void testApi() throws IOException { CloseableHttpClient client = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; try {//from ww w. j a va 2 s .com HttpGet g = new HttpGet("http://localhost:9998/controller/api.js?group=itest_info"); response = client.execute(g); String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, false); } finally { IOUtils.closeQuietly(response); IOUtils.closeQuietly(client); } }
From source file:ch.ralscha.extdirectspring_itest.InfoControllerTest.java
@Test public void testApiDebug() throws IOException { CloseableHttpClient client = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; try {// ww w.ja v a 2 s . c o m HttpGet g = new HttpGet("http://localhost:9998/controller/api-debug.js?group=itest_info"); response = client.execute(g); String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, false); } finally { IOUtils.closeQuietly(response); IOUtils.closeQuietly(client); } }
From source file:ch.ralscha.extdirectspring_itest.InfoControllerTest.java
@Test public void testApiFingerprinted() throws IOException { CloseableHttpClient client = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; try {/* w w w . ja va 2 s . co m*/ HttpGet g = new HttpGet("http://localhost:9998/controller/api-1.2.1.js?group=itest_info"); response = client.execute(g); String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, true); } finally { IOUtils.closeQuietly(response); IOUtils.closeQuietly(client); } }
From source file:org.apache.activemq.artemis.tests.integration.rest.util.QueueRestMessageContext.java
@Override public void initPullConsumers() throws IOException { String pullUri = getPullConsumerUri(); CloseableHttpResponse response = null; if (!this.autoAck) { response = connection.post(pullUri, "application/x-www-form-urlencoded", "autoAck=false"); } else {//from w w w. j a v a 2s . co m response = connection.post(pullUri); } try { int code = ResponseUtil.getHttpCode(response); if (code == 201) { Header header = response.getFirstHeader("Location"); contextMap.put(KEY_PULL_CONSUMERS_LOC, header.getValue()); header = response.getFirstHeader(KEY_MSG_CONSUME_NEXT); contextMap.put(KEY_MSG_CONSUME_NEXT, header.getValue()); header = response.getFirstHeader(KEY_MSG_ACK_NEXT); if (header != null) { contextMap.put(KEY_MSG_ACK_NEXT, header.getValue()); } } } finally { response.close(); } }
From source file:eu.fusepool.p3.proxy.ProxyHandler.java
/** * If uri is a transforming container returns the URI of the associated * container, otherwise null/*from w ww .j av a2s . c om*/ */ private String getTransformerUrl(String uri) throws IOException { HttpGet httpGet = new HttpGet(uri); httpGet.addHeader("Accept", "text/turtle"); CloseableHttpResponse response = httpclient.execute(httpGet); try { final Header contentTypeHeader = response.getFirstHeader("Content-Type"); if (contentTypeHeader == null) { return null; } final String contentType = contentTypeHeader.getValue(); if (!isRdf(contentType)) { return null; } HttpEntity entity = response.getEntity(); final UriRef baseUri = new UriRef(uri); final Graph graph = parser.parse(entity.getContent(), contentType, baseUri); EntityUtils.consume(entity); final Iterator<Triple> triples = graph.filter(baseUri, ELDP.transformer, null); while (triples.hasNext()) { Resource object = triples.next().getObject(); if (object instanceof UriRef) { return ((UriRef) object).getUnicodeString(); } } } finally { response.close(); } return null; }