List of usage examples for org.apache.http.impl.client HttpClients createMinimal
public static CloseableHttpClient createMinimal()
From source file:com.linecorp.armeria.server.composition.CompositeServiceTest.java
@Test public void testMapping() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc.execute(new HttpGet(uri("/qux/foo/X")))) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 200 OK")); assertThat(EntityUtils.toString(res.getEntity()), is("A:/qux/foo/X:/X")); }/* w w w . j a va 2 s . c o m*/ try (CloseableHttpResponse res = hc.execute(new HttpGet(uri("/qux/bar/Y")))) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 200 OK")); assertThat(EntityUtils.toString(res.getEntity()), is("B:/qux/bar/Y:/Y")); } try (CloseableHttpResponse res = hc.execute(new HttpGet(uri("/qux/Z")))) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 200 OK")); assertThat(EntityUtils.toString(res.getEntity()), is("C:/qux/Z:/Z")); } } }
From source file:com.google.appengine.tck.byteman.SameEntityGroupTest.java
private void doTest(URI root, boolean xg) throws Exception { try (CloseableHttpClient client = HttpClients.createMinimal()) { List<Thread> threads = new ArrayList<>(); Holder h1 = new Holder(); URIBuilder builder = new URIBuilder(root + "/ctx"); builder.addParameter("eg", "EG1"); builder.addParameter("c", "1"); builder.addParameter("xg", String.valueOf(xg)); threads.add(execute(client, new HttpPost(builder.build()), h1)); Holder h2 = new Holder(); builder = new URIBuilder(root + "/ctx"); builder.addParameter("eg", "EG1"); builder.addParameter("c", "2"); builder.addParameter("xg", String.valueOf(xg)); threads.add(execute(client, new HttpPost(builder.build()), h2)); join(threads);/* w ww . j av a 2 s .c o m*/ System.out.println("h1 = " + h1); System.out.println("h2 = " + h2); if (h1.out.startsWith("ERROR1")) { Assert.assertTrue("Expected ok: " + h2, h2.out.startsWith("OK2")); Assert.assertTrue("Expected CME: " + h2, h1.out.contains(ConcurrentModificationException.class.getName())); } else { Assert.assertTrue("Expected ok: " + h1, h1.out.startsWith("OK1")); Assert.assertTrue("Expected error: " + h2, h2.out.startsWith("ERROR2")); Assert.assertTrue("Expected CME: " + h2, h2.out.contains(ConcurrentModificationException.class.getName())); } } }
From source file:com.linecorp.armeria.server.thrift.ThriftOverHttp1Test.java
@Test public void testNonPostRequest() throws Exception { final HttpUriRequest[] reqs = { new HttpGet(newUri("http", "/hello")), new HttpDelete(newUri("http", "/hello")) }; try (CloseableHttpClient hc = HttpClients.createMinimal()) { for (HttpUriRequest r : reqs) { try (CloseableHttpResponse res = hc.execute(r)) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 405 Method Not Allowed")); assertThat(EntityUtils.toString(res.getEntity()), is(not("Hello, world!"))); }//from ww w .java2 s . c o m } } }
From source file:org.basinmc.maven.plugins.minecraft.launcher.VersionIndex.java
/** * Fetches a version index from the Mojang servers. *///w w w .j a va2s . co m @Nonnull public static VersionIndex fetch() throws IOException { HttpClient client = HttpClients.createMinimal(); HttpGet request = new HttpGet(URL); HttpResponse response = client.execute(request); StatusLine line = response.getStatusLine(); if (line.getStatusCode() != 200) { throw new IOException( "Unexpected response code: " + line.getStatusCode() + " - " + line.getReasonPhrase()); } try (InputStream inputStream = response.getEntity().getContent()) { return READER.forType(VersionIndex.class).readValue(inputStream); } }
From source file:com.linecorp.armeria.test.webapp.WebAppContainerTest.java
@Test public void testJsp() 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,//from w w w.j a 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: /index.jsp</p>" + "<p>Scheme: http</p>" + "</body></html>")); } } }
From source file:com.linecorp.armeria.server.http.WebAppContainerTest.java
@Test public void testGetQueryString() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc .execute(new HttpGet(uri("/jsp/query_string.jsp?foo=%31&bar=%32")))) { 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 . jav a 2 s.c o m is("<html><body>" + "<p>foo is 1</p>" + "<p>bar is 2</p>" + "</body></html>")); } } }
From source file:com.linecorp.armeria.server.http.tomcat.TomcatServiceTest.java
@Test public void testJarBasedWebApp() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc .execute(new HttpGet(uri("/jar/io/netty/util/concurrent/Future.class")))) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 200 OK")); assertThat(res.getFirstHeader(HttpHeaderNames.CONTENT_TYPE.toString()).getValue(), startsWith("application/java")); }//from w w w. j a v a 2 s . co m } }
From source file:com.linecorp.armeria.server.http.tomcat.UnmanagedTomcatServiceTest.java
@Test public void testServiceUnavailable() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc.execute(new HttpGet(uri("/empty/")))) { // as connector is not configured, TomcatServiceInvocationHandler will throw. assertThat(res.getStatusLine().toString(), is("HTTP/1.1 503 Service Unavailable")); }/*from w w w. j a v a2 s. c o m*/ } }
From source file:com.rylinaux.plugman.util.BukGetUtil.java
/** * Get the slug of the plugin.// w w w . ja va 2 s .co m * * @param name the name of the plugin. * @return the slug of the plugin. */ public static String getPluginSlug(String name) { HttpClient client = HttpClients.createMinimal(); HttpGet get = new HttpGet(API_BASE_URL + "search/slug/like/" + name + "?fields=plugin_name,slug"); try { HttpResponse response = client.execute(get); String body = IOUtils.toString(response.getEntity().getContent()); JSONArray array = (JSONArray) JSONValue.parse(body); for (int i = 0; i < array.size(); i++) { JSONObject json = (JSONObject) array.get(i); String pluginName = (String) json.get("plugin_name"); if (name.equalsIgnoreCase(pluginName)) return (String) json.get("slug"); } } catch (IOException e) { } return null; }
From source file:com.linecorp.armeria.server.http.tomcat.TomcatServiceTest.java
@Test public void testJarBasedWebAppWithAlternativeRoot() throws Exception { try (CloseableHttpClient hc = HttpClients.createMinimal()) { try (CloseableHttpResponse res = hc.execute(new HttpGet(uri("/jar_altroot/Future.class")))) { assertThat(res.getStatusLine().toString(), is("HTTP/1.1 200 OK")); assertThat(res.getFirstHeader(HttpHeaderNames.CONTENT_TYPE.toString()).getValue(), startsWith("application/java")); }/*from ww w. j ava 2 s . c o m*/ } }