List of usage examples for org.apache.http.impl.client HttpClients createMinimal
public static CloseableHttpClient createMinimal()
From source file:com.linecorp.armeria.server.http.tomcat.UnmanagedTomcatServiceTest.java
@Test public void testUnconfiguredWebApp() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc.execute(new HttpGet(uri("/no-webapp/")))) { // as no webapp is configured inside tomcat, 404 will be thrown. System.err.println("Entity: " + EntityUtils.toString(res.getEntity())); assertThat(res.getStatusLine().toString(), is("HTTP/1.1 404 Not Found")); }//from w w w. j ava 2s . c o m } }
From source file:com.linecorp.armeria.server.composition.CompositeServiceTest.java
@Test public void testNonExistentMapping() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc.execute(new HttpGet(uri("/qux/Z/T")))) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 404 Not Found")); }//w w w .jav a2 s . c om } }
From source file:com.linecorp.armeria.server.http.WebAppContainerTest.java
@Test public void testPostQueryString() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { final HttpPost post = new HttpPost(uri("/jsp/query_string.jsp?foo=3")); post.setEntity(new UrlEncodedFormEntity(Collections.singletonList(new BasicNameValuePair("bar", "4")), StandardCharsets.UTF_8)); try (CloseableHttpResponse res = hc.execute(post)) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 200 OK")); assertThat(res.getFirstHeader(HttpHeaderNames.CONTENT_TYPE.toString()).getValue(), startsWith("text/html")); final String actualContent = CR_OR_LF.matcher(EntityUtils.toString(res.getEntity())).replaceAll(""); assertThat(actualContent,/*from w w w . j a va2s . com*/ is("<html><body>" + "<p>foo is 3</p>" + "<p>bar is 4</p>" + "</body></html>")); } } }
From source file:com.linecorp.armeria.server.http.jetty.JettyServiceTest.java
@Test public void testDefaultHandlerFavicon() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc.execute(new HttpGet(uri("/default/favicon.ico")))) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 200 OK")); assertThat(res.getFirstHeader(HttpHeaderNames.CONTENT_TYPE.toString()).getValue(), startsWith("image/x-icon")); assertThat(EntityUtils.toByteArray(res.getEntity()).length, is(greaterThan(0))); }/*from w ww. j a va2s. c om*/ } }
From source file:de.slub.fedora.oai.OaiHarvester.java
private void harvestLoop() throws URISyntaxException, InterruptedException { while (isRunning()) { Date timestamp = now();// ww w. jav a2s. com getLastrunParameters(); if (lastrun != null && timestamp.before(lastrun)) { TimeUnit.MILLISECONDS.sleep(interval.getMillis()); continue; } URI uri = buildOaiRequestURI(); HttpGet httpGet = new HttpGet(uri); CloseableHttpClient httpClient = HttpClients.createMinimal(); try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) { if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity != null) { handleXmlResult(httpEntity.getContent()); writeLastrun(timestamp); } else { logger.warn("Got empty response from OAI service."); } } else { logger.error("Unexpected OAI service response: {} {}", httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase()); } } catch (Exception ex) { logger.error(ex.getMessage()); } finally { if (resumptionTokenIsPresent()) { TimeUnit.SECONDS.sleep(1); } else { TimeUnit.MILLISECONDS.sleep(interval.getMillis()); } } } }
From source file:com.linecorp.armeria.test.webapp.WebAppContainerTest.java
@Test public void testJapanesePath() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc.execute(new HttpGet(uri("/jsp//index.jsp")))) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 200 OK")); assertThat(res.getFirstHeader(HttpHeaderNames.CONTENT_TYPE.toString()).getValue(), startsWith("text/html")); final String actualContent = CR_OR_LF.matcher(EntityUtils.toString(res.getEntity())).replaceAll(""); assertThat(actualContent,/* w w w . ja v a2 s.c o m*/ is("<html><body>" + "<p>Hello, Armerian World!</p>" + "<p>Have you heard about the class 'io.netty.buffer.ByteBuf'?</p>" + "<p>Context path: </p>" + // ROOT context path "<p>Request URI: /%E6%97%A5%E6%9C%AC%E8%AA%9E/index.jsp</p>" + "<p>Servlet Path: //index.jsp</p>" + "</body></html>")); } } }
From source file:org.talend.dataprofiler.help.RegexExpeHelpUrlTest.java
private StatusLine execute(String helpUrl) throws ClientProtocolException, IOException { StatusLine statusLine = null;// www . ja v a 2 s. c o m CloseableHttpClient httpclient = HttpClients.createMinimal(); try { HttpGet httpget = new HttpGet(helpUrl); CloseableHttpResponse execute = httpclient.execute(httpget); statusLine = execute.getStatusLine(); } finally { httpclient.close(); } return statusLine; }
From source file:com.linecorp.armeria.server.http.tomcat.UnmanagedTomcatServiceTest.java
@Test public void testOk() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc.execute(new HttpGet(uri("/some-webapp/")))) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 200 OK")); }/* ww w . jav a2 s . c o m*/ } }
From source file:com.linecorp.armeria.testing.server.webapp.WebAppContainerTest.java
@Test public void jsp() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc.execute(new HttpGet(server().uri("/jsp/index.jsp")))) { assertThat(res.getStatusLine().toString()).isEqualTo("HTTP/1.1 200 OK"); assertThat(res.getFirstHeader(HttpHeaderNames.CONTENT_TYPE.toString()).getValue()) .startsWith("text/html"); final String actualContent = CR_OR_LF.matcher(EntityUtils.toString(res.getEntity())).replaceAll(""); assertThat(actualContent).isEqualTo("<html><body>" + "<p>Hello, Armerian World!</p>" + "<p>Have you heard about the class 'io.netty.buffer.ByteBuf'?</p>" + "<p>Context path: </p>" + // ROOT context path "<p>Request URI: /index.jsp</p>" + "<p>Scheme: http</p>" + "</body></html>"); }//from ww w. ja va 2s. c o m } }
From source file:com.rylinaux.plugman.util.BukGetUtil.java
/** * Get the plugin data for a certain version. * * @param slug the plugin slug./*from w w w . ja v a2 s . co m*/ * @return the JSON encoded data. */ public static JSONObject getPluginData(String slug, String version) { HttpClient client = HttpClients.createMinimal(); HttpGet get = new HttpGet(API_BASE_URL + "plugins/bukkit/" + slug + "/" + version); try { HttpResponse response = client.execute(get); String body = IOUtils.toString(response.getEntity().getContent()); return (JSONObject) JSONValue.parse(body); } catch (IOException e) { } return null; }