List of usage examples for org.apache.http.impl.client HttpClients createMinimal
public static CloseableHttpClient createMinimal()
From source file:co.freeside.betamax.handler.DefaultHandlerChain.java
private static HttpClient newHttpClient() { return HttpClients.createMinimal(); }
From source file:org.apache.hyracks.tests.integration.TestUtil.java
static InputStream httpGetAsInputStream(URI uri) throws URISyntaxException, IOException { HttpClient client = HttpClients.createMinimal(); HttpResponse response = client.execute(new HttpGet(uri)); return response.getEntity().getContent(); }
From source file:net.oebs.jalos.Client.java
Client(String serviceUrl) { httpClient = HttpClients.createMinimal(); this.serviceUrl = serviceUrl; }
From source file:de.cuseb.bilderbuch.helpers.HttpClientProviderService.java
public HttpClient getHttpClient() { return HttpClients.createMinimal(); }
From source file:plugin.RESTAuthenticationPluginModule.java
@Override protected void configurePlugin() { bind(ObjectMapper.class).toInstance(new ObjectMapper()); bind(CloseableHttpClient.class).toInstance(HttpClients.createMinimal()); }
From source file:com.linecorp.armeria.server.http.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 www . 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>" + "</body></html>")); } } }
From source file:com.google.appengine.tck.byteman.DiffEntityGroupTest.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("p", "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", "EG2"); builder.addParameter("c", "2"); builder.addParameter("p", "2"); builder.addParameter("xg", String.valueOf(xg)); threads.add(execute(client, new HttpPost(builder.build()), h2)); join(threads);//from w ww . jav a 2 s.co m System.out.println("h1 = " + h1); System.out.println("h2 = " + h2); Assert.assertTrue("Expected ok: " + h1, h1.out.startsWith("OK1")); Assert.assertTrue("Expected ok: " + h2, h2.out.startsWith("OK2")); } }
From source file:org.basinmc.maven.plugins.minecraft.launcher.DownloadDescriptor.java
/** * Fetches the artifact from the server and stores it in a specified file. *//* w ww. j av a2 s . c o m*/ public void fetch(@Nonnull Path outputFile) throws IOException { HttpClient client = HttpClients.createMinimal(); try { HttpGet request = new HttpGet(this.url.toURI()); HttpResponse response = client.execute(request); StatusLine line = response.getStatusLine(); if (line.getStatusCode() != 200) { throw new IOException( "Unexpected status code: " + line.getStatusCode() + " - " + line.getReasonPhrase()); } try (InputStream inputStream = response.getEntity().getContent()) { try (FileChannel fileChannel = FileChannel.open(outputFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { try (ReadableByteChannel inputChannel = Channels.newChannel(inputStream)) { fileChannel.transferFrom(inputChannel, 0, Long.MAX_VALUE); } } } } catch (URISyntaxException ex) { throw new IOException("Received invalid URI from API: " + ex.getMessage(), ex); } }
From source file:io.joynr.messaging.bounceproxy.monitoring.BounceProxyStartupReporterTest.java
@Before public void setUp() { Properties properties = new Properties(); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_SEND_LIFECYCLE_REPORT_RETRY_INTERVAL_MS, "50"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_CONTROLLER_BASE_URL, "http://anyurl.com"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_ID, "X.Y"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCEPROXY_URL_FOR_BPC, "http://anyurl.com"); properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCEPROXY_URL_FOR_CC, "http://anyurl.com"); Injector injector = Guice.createInjector(new PropertyLoadingModule(properties), new AbstractModule() { @Override/*from w w w. j a v a 2 s . com*/ protected void configure() { bind(ExecutorService.class).toInstance(Executors.newSingleThreadExecutor()); bind(CloseableHttpClient.class).toInstance(HttpClients.createMinimal()); } }); startupReporter = injector.getInstance(BounceProxyStartupReporter.class); execService = injector.getInstance(ExecutorService.class); }
From source file:org.apache.hyracks.tests.integration.ApplicationDeploymentAPIIntegrationTest.java
protected void deployApplicationFile(int dataSize, String fileName) throws URISyntaxException, IOException { final String deployid = "testApp"; String path = "/applications/" + deployid + "&" + fileName; URI uri = uri(path);/*from w ww. j a va2 s . c o m*/ byte[] data = new byte[dataSize]; for (int i = 0; i < data.length; ++i) { data[i] = (byte) i; } HttpClient client = HttpClients.createMinimal(); // Put the data HttpPut put = new HttpPut(uri); HttpEntity entity = new ByteArrayEntity(data, ContentType.APPLICATION_OCTET_STREAM); put.setEntity(entity); client.execute(put); // Get it back HttpGet get = new HttpGet(uri); HttpResponse response = client.execute(get); HttpEntity respEntity = response.getEntity(); Header contentType = respEntity.getContentType(); // compare results Assert.assertEquals(ContentType.APPLICATION_OCTET_STREAM.getMimeType(), contentType.getValue()); InputStream is = respEntity.getContent(); for (int i = 0; i < dataSize; ++i) { Assert.assertEquals(data[i], (byte) is.read()); } Assert.assertEquals(-1, is.read()); is.close(); }