Search in sources :

Example 16 with HttpRequestInterceptor

use of org.apache.http.HttpRequestInterceptor in project camel by apache.

the class HttpsAuthenticationTest method getBasicHttpProcessor.

@Override
protected HttpProcessor getBasicHttpProcessor() {
    List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>();
    requestInterceptors.add(new RequestBasicAuth());
    List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>();
    responseInterceptors.add(new ResponseContent());
    responseInterceptors.add(new ResponseBasicUnauthorized());
    ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors);
    return httpproc;
}
Also used : ResponseContent(org.apache.http.protocol.ResponseContent) HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) ResponseBasicUnauthorized(org.apache.http.localserver.ResponseBasicUnauthorized) ArrayList(java.util.ArrayList) HttpResponseInterceptor(org.apache.http.HttpResponseInterceptor) RequestBasicAuth(org.apache.http.localserver.RequestBasicAuth) ImmutableHttpProcessor(org.apache.http.protocol.ImmutableHttpProcessor)

Example 17 with HttpRequestInterceptor

use of org.apache.http.HttpRequestInterceptor in project brave by openzipkin.

the class ITTracingHttpAsyncClientBuilder method currentSpanVisibleToUserFilters.

@Test
public void currentSpanVisibleToUserFilters() throws Exception {
    server.enqueue(new MockResponse());
    closeClient(client);
    client = TracingHttpAsyncClientBuilder.create(httpTracing).addInterceptorLast((HttpRequestInterceptor) (request, context) -> request.setHeader("my-id", currentTraceContext.get().traceIdString())).build();
    client.start();
    get(client, "/foo");
    RecordedRequest request = server.takeRequest();
    assertThat(request.getHeader("x-b3-traceId")).isEqualTo(request.getHeader("my-id"));
    takeSpan();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ITHttpAsyncClient(brave.test.http.ITHttpAsyncClient) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) CloseableHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient) Test(org.junit.Test) EntityUtils(org.apache.http.util.EntityUtils) HttpGet(org.apache.http.client.methods.HttpGet) URI(java.net.URI) NStringEntity(org.apache.http.nio.entity.NStringEntity) MockResponse(okhttp3.mockwebserver.MockResponse) HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 18 with HttpRequestInterceptor

use of org.apache.http.HttpRequestInterceptor in project brave by openzipkin.

the class ITTracingHttpClientBuilder method currentSpanVisibleToUserFilters.

@Test
public void currentSpanVisibleToUserFilters() throws Exception {
    server.enqueue(new MockResponse());
    closeClient(client);
    client = TracingHttpClientBuilder.create(httpTracing).disableAutomaticRetries().addInterceptorFirst((HttpRequestInterceptor) (request, context) -> request.setHeader("my-id", currentTraceContext.get().traceIdString())).build();
    get(client, "/foo");
    RecordedRequest request = server.takeRequest();
    assertThat(request.getHeader("x-b3-traceId")).isEqualTo(request.getHeader("my-id"));
    takeSpan();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringEntity(org.apache.http.entity.StringEntity) IOException(java.io.IOException) Test(org.junit.Test) EntityUtils.consume(org.apache.http.util.EntityUtils.consume) ITHttpClient(brave.test.http.ITHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) URI(java.net.URI) MockResponse(okhttp3.mockwebserver.MockResponse) HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 19 with HttpRequestInterceptor

use of org.apache.http.HttpRequestInterceptor in project camel by apache.

the class HttpCompressionTest method getBasicHttpProcessor.

@Override
protected HttpProcessor getBasicHttpProcessor() {
    List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>();
    requestInterceptors.add(new RequestDecompressingInterceptor());
    List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>();
    responseInterceptors.add(new ResponseCompressingInterceptor());
    responseInterceptors.add(new ResponseBasicUnauthorized());
    ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors);
    return httpproc;
}
Also used : HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) ResponseBasicUnauthorized(org.apache.http.localserver.ResponseBasicUnauthorized) ArrayList(java.util.ArrayList) HttpResponseInterceptor(org.apache.http.HttpResponseInterceptor) ImmutableHttpProcessor(org.apache.http.protocol.ImmutableHttpProcessor)

Example 20 with HttpRequestInterceptor

use of org.apache.http.HttpRequestInterceptor in project camel by apache.

the class HttpAuthenticationTest method getBasicHttpProcessor.

@Override
protected HttpProcessor getBasicHttpProcessor() {
    List<HttpRequestInterceptor> requestInterceptors = new ArrayList<HttpRequestInterceptor>();
    requestInterceptors.add(new RequestBasicAuth());
    List<HttpResponseInterceptor> responseInterceptors = new ArrayList<HttpResponseInterceptor>();
    responseInterceptors.add(new ResponseContent());
    responseInterceptors.add(new ResponseBasicUnauthorized());
    ImmutableHttpProcessor httpproc = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors);
    return httpproc;
}
Also used : ResponseContent(org.apache.http.protocol.ResponseContent) HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) ResponseBasicUnauthorized(org.apache.http.localserver.ResponseBasicUnauthorized) ArrayList(java.util.ArrayList) HttpResponseInterceptor(org.apache.http.HttpResponseInterceptor) RequestBasicAuth(org.apache.http.localserver.RequestBasicAuth) ImmutableHttpProcessor(org.apache.http.protocol.ImmutableHttpProcessor)

Aggregations

HttpRequestInterceptor (org.apache.http.HttpRequestInterceptor)24 HttpRequest (org.apache.http.HttpRequest)11 HttpContext (org.apache.http.protocol.HttpContext)11 IOException (java.io.IOException)9 HttpResponseInterceptor (org.apache.http.HttpResponseInterceptor)8 ArrayList (java.util.ArrayList)6 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)6 Header (org.apache.http.Header)5 CredentialsProvider (org.apache.http.client.CredentialsProvider)5 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)5 Test (org.junit.Test)5 HttpResponse (org.apache.http.HttpResponse)4 AuthScope (org.apache.http.auth.AuthScope)4 HttpGet (org.apache.http.client.methods.HttpGet)4 ImmutableHttpProcessor (org.apache.http.protocol.ImmutableHttpProcessor)4 URI (java.net.URI)3 Map (java.util.Map)3 HttpException (org.apache.http.HttpException)3 HttpHost (org.apache.http.HttpHost)3 Credentials (org.apache.http.auth.Credentials)3