feign.httpclient.ApacheHttpClient Java Examples

The following examples show how to use feign.httpclient.ApacheHttpClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProtobufSpringEncoderTest.java    From spring-cloud-openfeign with Apache License 2.0 6 votes vote down vote up
private HttpEntity toApacheHttpEntity(RequestTemplate requestTemplate)
		throws IOException, URISyntaxException {
	final List<HttpUriRequest> request = new ArrayList<>(1);
	BDDMockito.given(this.httpClient.execute(ArgumentMatchers.<HttpUriRequest>any()))
			.will(new Answer<HttpResponse>() {
				@Override
				public HttpResponse answer(InvocationOnMock invocationOnMock)
						throws Throwable {
					request.add((HttpUriRequest) invocationOnMock.getArguments()[0]);
					return new BasicHttpResponse(new BasicStatusLine(
							new ProtocolVersion("http", 1, 1), 200, null));
				}
			});
	new ApacheHttpClient(this.httpClient).execute(
			requestTemplate.resolve(new HashMap<>()).request(),
			new feign.Request.Options());
	HttpUriRequest httpUriRequest = request.get(0);
	return ((HttpEntityEnclosingRequestBase) httpUriRequest).getEntity();
}
 
Example #2
Source File: TracingConfiguration.java    From hola with Apache License 2.0 6 votes vote down vote up
/**
 * This is were the "magic" happens: it creates a Feign, which is a proxy interface for remote calling a REST endpoint with
 * Hystrix fallback support.
 *
 * @return The feign pointing to the service URL and with Hystrix fallback.
 */
@Produces
@Singleton
private AlohaService alohaService(Tracer tracer) {
    // bind current span to Hystrix thread
    TracingConcurrencyStrategy.register();

    return HystrixFeign.builder()
            // Use apache HttpClient which contains the ZipKin Interceptors
            .client(new TracingClient(new ApacheHttpClient(HttpClientBuilder.create().build()), tracer))

            // Bind Zipkin Server Span to Feign Thread
            .logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC)
            .decoder(new JacksonDecoder())
            .target(AlohaService.class,"http://aloha:8080/",
                    () -> Collections.singletonList("Aloha response (fallback)"));
}
 
Example #3
Source File: HttpClientFeignLoadBalancerConfiguration.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public Client feignClient(LoadBalancerClient loadBalancerClient,
		HttpClient httpClient) {
	ApacheHttpClient delegate = new ApacheHttpClient(httpClient);
	return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient);
}
 
Example #4
Source File: FeignLoadBalancerAutoConfigurationTests.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldInstantiateHttpFeignClientWhenEnabled() {
	ConfigurableApplicationContext context = initContext(
			"spring.cloud.loadbalancer.ribbon.enabled=false");
	assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
	assertLoadBalanced(context, ApacheHttpClient.class);
}
 
Example #5
Source File: FeignCompressionTests.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
@Bean
public ApacheHttpClient client() {
	/*
	 * We know our client is an AppacheHttpClient because we disabled the OK HTTP
	 * client. FeignAcceptGzipEncodingAutoConfiguration won't load unless there is
	 * a bean of type ApacheHttpClient (not Client) in this test because the bean
	 * is not yet created and so the application context doesnt know that the
	 * Client bean is actually an instance of ApacheHttpClient, therefore
	 * FeignAcceptGzipEncodingAutoConfiguration will not be loaded. We just create
	 * a bean here of type ApacheHttpClient so that the configuration will be
	 * loaded correctly.
	 */
	return (ApacheHttpClient) this.client;
}
 
Example #6
Source File: ApacheHttpClientConfigurationTests.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
@Test
public void testHttpClientWithFeign() {
	Client delegate = this.feignClient.getDelegate();
	assertThat(ApacheHttpClient.class.isInstance(delegate)).isTrue();
	ApacheHttpClient apacheHttpClient = (ApacheHttpClient) delegate;
	HttpClient httpClient = getField(apacheHttpClient, "client");
	MockingDetails httpClientDetails = mockingDetails(httpClient);
	assertThat(httpClientDetails.isMock()).isTrue();
}
 
Example #7
Source File: RaptorClientAutoConfiguration.java    From raptor with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(Client.class)
public Client createRaptorFeignClient() {

    HttpClient httpClient = applicationContext.getBean(HttpClient.class);
    if (httpClient != null) {
        return new ApacheHttpClient(httpClient);
    } else {
        return new ApacheHttpClient();
    }
}
 
Example #8
Source File: TracingConfiguration.java    From ola with Apache License 2.0 5 votes vote down vote up
/**
 *
 * This is were the "magic" happens: it creates a Feign, which is a proxy interface for remote calling a
 * REST endpoint with Hystrix fallback support.
 */
@Bean
public HolaService holaService(Tracer tracer) {
    // bind current span to Hystrix thread
    TracingConcurrencyStrategy.register();

    return HystrixFeign.builder()
            .client(new TracingClient(new ApacheHttpClient(HttpClientBuilder.create().build()), tracer))
            .logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC)
            .decoder(new JacksonDecoder())
            .target(HolaService.class, "http://hola:8080/",
                    () -> Collections.singletonList("Hola response (fallback)"));
}
 
Example #9
Source File: Catalog.java    From cxf with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/search")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject search(@QueryParam("q") final String query, @Context final TracerContext tracing) throws Exception {
    final GoogleBooksApi api = Feign
        .builder()
        .client(new TracingClient(new ApacheHttpClient(), tracing.unwrap(Tracer.class)))
        .target(GoogleBooksApi.class, "https://www.googleapis.com");
 
    final feign.Response response = api.search(query);
    try (final Reader reader = response.body().asReader()) {
        return Json.createReader(reader).readObject();
    }
}
 
Example #10
Source File: FeignAutoConfiguration.java    From spring-cloud-openfeign with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean(Client.class)
public Client feignClient(HttpClient httpClient) {
	return new ApacheHttpClient(httpClient);
}