Package org.apache.http.impl.client

Examples of org.apache.http.impl.client.CloseableHttpClient


        } catch (URISyntaxException e) {
            LOG.error("Invalid version check URI.", e);
            return;
        }

        CloseableHttpClient http = HttpClients.createDefault();
        CloseableHttpResponse response = null;
        try {
            response = http.execute(get);

            if (response.getStatusLine().getStatusCode() != 200) {
                LOG.error("Expected version check HTTP status code [200] but got [{}]", response.getStatusLine().getStatusCode());
                return;
            }
View Full Code Here


        } catch (URISyntaxException e) {
            LOG.error("Invalid telemetry service endpoint URI.", e);
            return;
        }

        CloseableHttpClient http = HttpClients.createDefault();
        CloseableHttpResponse response = null;
        try {
            response = http.execute(post);

            if (response.getStatusLine().getStatusCode() != 202) {
                LOG.error("Telemetry is activated: Expected HTTP response status code [202] but got [{}]", response.getStatusLine().getStatusCode());
                return;
            }
View Full Code Here

            .httpMessageHeader(BraveHttpHeaders.SpanId.getName(), Long.toString(SPAN_ID, 16))
            .httpMessageHeader(BraveHttpHeaders.Sampled.getName(), "true");
        final HttpResponseImpl response = new HttpResponseImpl(200, null, null);
        responseProvider.set(request, response);

        final CloseableHttpClient httpclient =
            HttpClients.custom().addInterceptorFirst(new BraveHttpRequestInterceptor(clientTracer, Optional.<String>absent()))
                .addInterceptorFirst(new BraveHttpResponseInterceptor(clientTracer)).build();
        try {
            final HttpGet httpGet = new HttpGet(REQUEST);
            final CloseableHttpResponse httpClientResponse = httpclient.execute(httpGet);
            try {
                assertEquals(200, httpClientResponse.getStatusLine().getStatusCode());
            } finally {
                httpClientResponse.close();
            }
            mockServer.verify();

            final InOrder inOrder = inOrder(clientTracer);
            inOrder.verify(clientTracer).startNewSpan(PATH);
            inOrder.verify(clientTracer).setCurrentClientServiceName(CONTEXT);
            inOrder.verify(clientTracer).submitBinaryAnnotation("request", "GET " + FULL_PATH);
            inOrder.verify(clientTracer).setClientSent();
            inOrder.verify(clientTracer).submitBinaryAnnotation("http.responsecode", 200);
            inOrder.verify(clientTracer).setClientReceived();
            verifyNoMoreInteractions(clientTracer);
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

        final HttpRequestImpl request = new HttpRequestImpl();
        request.method(Method.GET).path(FULL_PATH).httpMessageHeader(BraveHttpHeaders.Sampled.getName(), "false");
        final HttpResponseImpl response = new HttpResponseImpl(200, null, null);
        responseProvider.set(request, response);

        final CloseableHttpClient httpclient =
            HttpClients.custom().addInterceptorFirst(new BraveHttpRequestInterceptor(clientTracer, Optional.<String>absent()))
                .addInterceptorFirst(new BraveHttpResponseInterceptor(clientTracer)).build();
        try {
            final HttpGet httpGet = new HttpGet(REQUEST);
            final CloseableHttpResponse httpClientResponse = httpclient.execute(httpGet);
            try {
                assertEquals(200, httpClientResponse.getStatusLine().getStatusCode());
            } finally {
                httpClientResponse.close();
            }
            mockServer.verify();

            final InOrder inOrder = inOrder(clientTracer);
            inOrder.verify(clientTracer).startNewSpan(PATH);
            inOrder.verify(clientTracer).setCurrentClientServiceName(CONTEXT);
            inOrder.verify(clientTracer).submitBinaryAnnotation("request", "GET " + FULL_PATH);
            inOrder.verify(clientTracer).setClientSent();
            inOrder.verify(clientTracer).submitBinaryAnnotation("http.responsecode", 200);
            inOrder.verify(clientTracer).setClientReceived();
            verifyNoMoreInteractions(clientTracer);
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

            .httpMessageHeader(BraveHttpHeaders.SpanId.getName(), Long.toString(SPAN_ID, 16))
            .httpMessageHeader(BraveHttpHeaders.Sampled.getName(), "true");
        final HttpResponseImpl response = new HttpResponseImpl(200, null, null);
        responseProvider.set(request, response);

        final CloseableHttpClient httpclient =
            HttpClients.custom().addInterceptorFirst(new BraveHttpRequestInterceptor(clientTracer, Optional.<String>absent()))
                .addInterceptorFirst(new BraveHttpResponseInterceptor(clientTracer)).build();
        try {
            final HttpGet httpGet = new HttpGet(REQUEST_WITH_QUERY_PARAMS);
            final CloseableHttpResponse httpClientResponse = httpclient.execute(httpGet);
            try {
                assertEquals(200, httpClientResponse.getStatusLine().getStatusCode());
            } finally {
                httpClientResponse.close();
            }
            mockServer.verify();

            final InOrder inOrder = inOrder(clientTracer);
            inOrder.verify(clientTracer).startNewSpan(PATH);
            inOrder.verify(clientTracer).setCurrentClientServiceName(CONTEXT);
            inOrder.verify(clientTracer).submitBinaryAnnotation("request", "GET " + FULL_PATH_WITH_QUERY_PARAMS);
            inOrder.verify(clientTracer).setClientSent();
            inOrder.verify(clientTracer).submitBinaryAnnotation("http.responsecode", 200);
            inOrder.verify(clientTracer).setClientReceived();
            verifyNoMoreInteractions(clientTracer);
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

                .httpMessageHeader(BraveHttpHeaders.SpanId.getName(), Long.toString(SPAN_ID, 16))
                .httpMessageHeader(BraveHttpHeaders.Sampled.getName(), "true");
        final HttpResponseImpl response = new HttpResponseImpl(200, null, null);
        responseProvider.set(request, response);

        final CloseableHttpClient httpclient =
                HttpClients.custom().addInterceptorFirst(new BraveHttpRequestInterceptor(clientTracer, Optional.of(SERVICE)))
                        .addInterceptorFirst(new BraveHttpResponseInterceptor(clientTracer)).build();
        try {
            final HttpGet httpGet = new HttpGet(REQUEST);
            final CloseableHttpResponse httpClientResponse = httpclient.execute(httpGet);
            try {
                assertEquals(200, httpClientResponse.getStatusLine().getStatusCode());
            } finally {
                httpClientResponse.close();
            }
            mockServer.verify();

            final InOrder inOrder = inOrder(clientTracer);
            inOrder.verify(clientTracer).startNewSpan(FULL_PATH);
            inOrder.verify(clientTracer).setCurrentClientServiceName(SERVICE);
            inOrder.verify(clientTracer).submitBinaryAnnotation("request", "GET " + FULL_PATH);
            inOrder.verify(clientTracer).setClientSent();
            inOrder.verify(clientTracer).submitBinaryAnnotation("http.responsecode", 200);
            inOrder.verify(clientTracer).setClientReceived();
            verifyNoMoreInteractions(clientTracer);
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

    }
   
    @Test
    public void testSetBodyRepresentation() throws Exception {
        HttpGet get = new HttpGet("http://0.0.0.0:" + portNum + "/images/123");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();
        InputStream is = null;
        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
            assertEquals("image/png", response.getEntity().getContentType().getValue());
            is = response.getEntity().getContent();
            assertEquals("Get wrong available size", 10, response.getEntity().getContentLength());
            byte[] buffer = new byte[10];
            is.read(buffer);
            for (int i = 0; i < 10; i++) {
                assertEquals(i + 1, buffer[i]);
            }
        } finally {
            httpclient.close();
            if (is != null) {
                is.close();
            }
        }
    }
View Full Code Here

   
    @Test
    public void testGetCustomer() throws Exception {     
        HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers/123");
        get.addHeader("Accept" , "application/json");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
            assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
                         EntityUtils.toString(response.getEntity()));
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

    @Test
    public void testGetCustomerWithQuery() throws Exception {     
        HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers?id=123");
        get.addHeader("Accept" , "application/json");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
            assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
                         EntityUtils.toString(response.getEntity()));
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

   
    @Test
    public void testGetCustomers() throws Exception {
        HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers/");
        get.addHeader("Accept" , "application/xml");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
            // order returned can differ on OS so match for both orders
            String s = EntityUtils.toString(response.getEntity());
            assertNotNull(s);
            boolean m1 = s.endsWith("<Customers><Customer><id>123</id><name>John</name></Customer><Customer><id>113</id><name>Dan</name></Customer></Customers>");
            boolean m2 = s.endsWith("<Customers><Customer><id>113</id><name>Dan</name></Customer><Customer><id>123</id><name>John</name></Customer></Customers>");

            if (!m1 && !m2) {
                fail("Not expected body returned: " + s);
            }
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.impl.client.CloseableHttpClient

Copyright © 2018 www.massapicom. 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.