Search in sources :

Example 1 with CatalogTracing

use of demo.jaxrs.tracing.server.CatalogTracing in project cxf by apache.

the class ApacheHttpClient method main.

public static void main(final String[] args) throws Exception {
    try (final CatalogTracing tracing = new CatalogTracing("catalog-client")) {
        final CloseableHttpClient httpclient = TracingHttpClientBuilder.create(tracing.getHttpTracing()).build();
        final HttpGet request = new HttpGet("http://localhost:9000/catalog");
        request.setHeader("Accept", "application/json");
        final HttpResponse response = httpclient.execute(request);
        System.out.println(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
        httpclient.close();
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) CatalogTracing(demo.jaxrs.tracing.server.CatalogTracing)

Example 2 with CatalogTracing

use of demo.jaxrs.tracing.server.CatalogTracing in project cxf by apache.

the class ApacheHttpAsyncClient method main.

public static void main(final String[] args) throws Exception {
    try (final CatalogTracing tracing = new CatalogTracing("catalog-client")) {
        final CloseableHttpAsyncClient httpclient = TracingHttpAsyncClientBuilder.create(tracing.getHttpTracing()).build();
        final HttpGet request = new HttpGet("http://localhost:9000/catalog");
        request.setHeader("Accept", "application/json");
        httpclient.start();
        final Future<HttpResponse> response = httpclient.execute(request, new FutureCallback<HttpResponse>() {

            @Override
            public void completed(HttpResponse result) {
                try {
                    System.out.println(EntityUtils.toString(result.getEntity(), StandardCharsets.UTF_8));
                } catch (final IOException ex) {
                    System.out.println(ex);
                }
            }

            @Override
            public void failed(Exception ex) {
                System.out.println(ex);
            }

            @Override
            public void cancelled() {
            }
        });
        response.get(1000, TimeUnit.MILLISECONDS);
        httpclient.close();
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient) HttpResponse(org.apache.http.HttpResponse) CatalogTracing(demo.jaxrs.tracing.server.CatalogTracing) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with CatalogTracing

use of demo.jaxrs.tracing.server.CatalogTracing in project cxf by apache.

the class OkHttp3Client method main.

public static void main(final String[] args) throws Exception {
    try (final CatalogTracing tracing = new CatalogTracing("catalog-client")) {
        final OkHttpClient client = new OkHttpClient();
        final Call.Factory factory = TracingCallFactory.create(tracing.getHttpTracing(), client);
        final Request request = new Request.Builder().url("http://localhost:9000/catalog").header("Accept", "application/json").build();
        try (final Response response = factory.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) CatalogTracing(demo.jaxrs.tracing.server.CatalogTracing)

Aggregations

CatalogTracing (demo.jaxrs.tracing.server.CatalogTracing)3 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 IOException (java.io.IOException)1 Call (okhttp3.Call)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 CloseableHttpAsyncClient (org.apache.http.impl.nio.client.CloseableHttpAsyncClient)1