Package org.apache.http.impl.nio.client

Examples of org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute()


                HttpHost target = URIUtils.extractHost(get.getURI());
                BasicAsyncRequestProducer basicAsyncRequestProducer = new BasicAsyncRequestProducer(target, get);
                httpClient.start();
                try {
                    log.debug("sending request");
                    Future<HttpResponse> futureResponse = httpClient.execute(
                            basicAsyncRequestProducer,
                            new SSEResponseConsumer(requestHandler), new FutureCallback<HttpResponse>() {
                                public void completed(HttpResponse httpResponse) {
                                    log.debug("response received {}", httpResponse);
                                }
View Full Code Here


                    throw new AssertionError(ex);
                } catch (HttpException ex) {
                    throw new AssertionError(ex);
                }
                try {
                    return ac.execute(requestProducer, responseConsumer, context, callback);
                } finally {
                    timerContext.stop();
                }
            }
View Full Code Here

            public void run() throws SuspendExecution, InterruptedException {
                try {
                    // snippet future calls
                    ArrayList<Future<HttpResponse>> futures = new ArrayList<>();
                    for (int i = 0; i < concurrencyLevel; i++)
                        futures.add(client.execute(new HttpGet("http://localhost:8080"), null));
                    for (Future<HttpResponse> future : futures)
                        assertEquals("testGet", EntityUtils.toString(future.get().getEntity()));
                    // end of snippet
                } catch (ExecutionException | IOException | ParseException ex) {
                    fail(ex.getMessage());
View Full Code Here

                    timerContext = timer(requestProducer.generateRequest()).time();
                } catch (IOException | HttpException ex) {
                    throw new AssertionError();
                }
                try {
                    return ac.execute(requestProducer, responseConsumer, context, callback);
                } finally {
                    timerContext.stop();
                }
            }
View Full Code Here

    public static void main(final String[] args) throws Exception {
        final CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
        httpclient.start();
        try {
            final HttpGet request = new HttpGet("http://www.apache.org/");
            final Future<HttpResponse> future = httpclient.execute(request, null);
            final HttpResponse response = future.get();
            System.out.println("Response: " + response.getStatusLine());
            System.out.println("Shutting down");
        } finally {
            httpclient.close();
View Full Code Here

    public static void main(final String[] args) throws Exception {
        final CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
        httpclient.start();
        try {
            final Future<Boolean> future = httpclient.execute(
                    HttpAsyncMethods.createGet("http://localhost:8080/"),
                    new MyResponseConsumer(), null);
            final Boolean result = future.get();
            if (result != null && result.booleanValue()) {
                System.out.println("Request successfully executed");
View Full Code Here

                    }
                    return file;
                }

            };
            final Future<File> future = httpclient.execute(httpost, consumer, null);
            final File result = future.get();
            System.out.println("Response file length: " + result.length());
            System.out.println("Shutting down");
        } finally {
            httpclient.close();
View Full Code Here

                    new HttpGet("https://www.verisign.com/"),
                    new HttpGet("http://www.google.com/")
            };
            final CountDownLatch latch = new CountDownLatch(requests.length);
            for (final HttpGet request: requests) {
                httpclient.execute(request, new FutureCallback<HttpResponse>() {

                    public void completed(final HttpResponse response) {
                        latch.countDown();
                        System.out.println(request.getRequestLine() + "->" + response.getStatusLine());
                    }
View Full Code Here

      asyncHttpClient.start();
      AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR);
      asyncIdleConnectionMonitorThread.start();
    }

    final Future<org.apache.http.HttpResponse> future = asyncHttpClient.execute(requestObj,
        prepareCallback(responseClass, callback));

    return new Future<HttpResponse<T>>() {

      public boolean cancel(boolean mayInterruptIfRunning) {
View Full Code Here

    public static void main(final String[] args) throws Exception {
        CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
        try {
            httpclient.start();
            HttpGet request = new HttpGet("http://www.apache.org/");
            Future<HttpResponse> future = httpclient.execute(request, null);
            HttpResponse response = future.get();
            System.out.println("Response: " + response.getStatusLine());
            System.out.println("Shutting down");
        } finally {
            httpclient.close();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.