Search in sources :

Example 6 with Client

use of feign.Client in project atlasdb by palantir.

the class CounterBackedRefreshingClientTest method createsClientOnlyOnceIfMakingMultipleRequests.

@Test
public void createsClientOnlyOnceIfMakingMultipleRequests() throws IOException {
    when(clientSupplier.get()).thenReturn(client);
    when(client.execute(request, options)).thenReturn(Response.create(204, "no content", ImmutableMap.of(), new byte[0]));
    Client refreshingClient = CounterBackedRefreshingClient.createRefreshingClient(clientSupplier);
    refreshingClient.execute(request, options);
    refreshingClient.execute(request, options);
    refreshingClient.execute(request, options);
    verify(clientSupplier).get();
    verify(client, times(3)).execute(request, options);
    verifyNoMoreInteractions(clientSupplier, client);
}
Also used : Client(feign.Client) Test(org.junit.Test)

Example 7 with Client

use of feign.Client in project atlasdb by palantir.

the class AtlasDbFeignTargetFactory method createProxyWithFailover.

private static <T> T createProxyWithFailover(Optional<SSLSocketFactory> sslSocketFactory, Optional<ProxySelector> proxySelector, Collection<String> endpointUris, Request.Options feignOptions, int maxBackoffMillis, Class<T> type, String userAgent) {
    FailoverFeignTarget<T> failoverFeignTarget = new FailoverFeignTarget<>(endpointUris, maxBackoffMillis, type);
    Client client = failoverFeignTarget.wrapClient(FeignOkHttpClients.newOkHttpClient(sslSocketFactory, proxySelector, userAgent));
    return Feign.builder().contract(contract).encoder(encoder).decoder(decoder).errorDecoder(errorDecoder).client(client).retryer(failoverFeignTarget).options(feignOptions).target(failoverFeignTarget);
}
Also used : Client(feign.Client)

Example 8 with Client

use of feign.Client in project feign by OpenFeign.

the class ReactiveFeignIntegrationTest method testClient.

@Test
public void testClient() throws Exception {
    Client client = mock(Client.class);
    given(client.execute(any(Request.class), any(Options.class))).willAnswer((Answer<Response>) invocation -> Response.builder().status(200).headers(Collections.emptyMap()).body("1.0", Charset.defaultCharset()).request((Request) invocation.getArguments()[0]).build());
    TestReactorService service = ReactorFeign.builder().client(client).target(TestReactorService.class, this.getServerUrl());
    StepVerifier.create(service.version()).expectNext("1.0").expectComplete().verify();
    verify(client, times(1)).execute(any(Request.class), any(Options.class));
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ErrorDecoder(feign.codec.ErrorDecoder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) GET(javax.ws.rs.GET) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Path(javax.ws.rs.Path) Decoder(feign.codec.Decoder) Client(feign.Client) Logger(feign.Logger) RequestInterceptor(feign.RequestInterceptor) Retryer(feign.Retryer) Mockito.spy(org.mockito.Mockito.spy) Level(feign.Logger.Level) RetryableException(feign.RetryableException) Answer(org.mockito.stubbing.Answer) Options(feign.Request.Options) Flowable(io.reactivex.Flowable) Charset(java.nio.charset.Charset) BDDMockito.given(org.mockito.BDDMockito.given) MockWebServer(okhttp3.mockwebserver.MockWebServer) JacksonDecoder(feign.jackson.JacksonDecoder) ExpectedException(org.junit.rules.ExpectedException) QueryMapEncoder(feign.QueryMapEncoder) ResponseMapper(feign.ResponseMapper) Response(feign.Response) RequestLine(feign.RequestLine) Mockito.times(org.mockito.Mockito.times) QueryMap(feign.QueryMap) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) JAXRSContract(feign.jaxrs.JAXRSContract) AdditionalAnswers(org.mockito.AdditionalAnswers) Mockito.verify(org.mockito.Mockito.verify) Flux(reactor.core.publisher.Flux) Rule(org.junit.Rule) Param(feign.Param) Type(java.lang.reflect.Type) JacksonEncoder(feign.jackson.JacksonEncoder) Request(feign.Request) MockResponse(okhttp3.mockwebserver.MockResponse) RequestTemplate(feign.RequestTemplate) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) Options(feign.Request.Options) Request(feign.Request) Client(feign.Client) Test(org.junit.Test)

Example 9 with Client

use of feign.Client in project nutzboot by nutzam.

the class FeignStarter method afterBorn.

@SuppressWarnings({ "unchecked", "rawtypes" })
public Object afterBorn(Object obj, String beanName) {
    try {
        Mirror mirror = Mirror.me(obj);
        for (Field field : obj.getClass().getDeclaredFields()) {
            FeignInject fc = field.getAnnotation(FeignInject.class);
            if (fc == null)
                continue;
            String url = Strings.sBlank(conf.get(PROP_URL), "http://127.0.0.1:8080");
            Encoder encoder = getEncoder(fc, field);
            Decoder decoder = getDecoder(fc, field);
            Client client = getClient(fc, field, url);
            Logger.Level level = Level.valueOf(conf.get(PROP_LOGLEVEL, "BASIC").toUpperCase());
            Class apiType = field.getType();
            Logger logger = new Slf4jLogger(apiType);
            boolean useHystrix = "true".equals(Strings.sBlank(fc.useHystrix(), conf.get(PROP_HYSTRIX_ENABLE)));
            Feign.Builder builder = useHystrix ? HystrixFeign.builder() : Feign.builder();
            if (encoder != null)
                builder.encoder(encoder);
            if (decoder != null)
                builder.decoder(decoder);
            if (client != null)
                builder.client(client);
            builder.logger(logger);
            builder.logLevel(level);
            Object t = null;
            if (useHystrix) {
                t = ((HystrixFeign.Builder) builder).target(apiType, url, getIocBean(apiType, fc.fallback()));
            } else {
                t = builder.target(apiType, url);
            }
            mirror.setValue(obj, field.getName(), t);
        }
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    return obj;
}
Also used : Slf4jLogger(feign.slf4j.Slf4jLogger) Decoder(feign.codec.Decoder) JacksonDecoder(feign.jackson.JacksonDecoder) JAXBDecoder(feign.jaxb.JAXBDecoder) GsonDecoder(feign.gson.GsonDecoder) Logger(feign.Logger) Slf4jLogger(feign.slf4j.Slf4jLogger) FeignInject(org.nutz.boot.starter.feign.annotation.FeignInject) Level(feign.Logger.Level) HystrixFeign(feign.hystrix.HystrixFeign) Field(java.lang.reflect.Field) GsonEncoder(feign.gson.GsonEncoder) JAXBEncoder(feign.jaxb.JAXBEncoder) Encoder(feign.codec.Encoder) JacksonEncoder(feign.jackson.JacksonEncoder) HystrixFeign(feign.hystrix.HystrixFeign) Feign(feign.Feign) Client(feign.Client) OkHttpClient(feign.okhttp.OkHttpClient) RibbonClient(feign.ribbon.RibbonClient) EurekaClient(com.netflix.discovery.EurekaClient) ApacheHttpClient(feign.httpclient.ApacheHttpClient) LBClient(feign.ribbon.LBClient) Mirror(org.nutz.lang.Mirror)

Example 10 with Client

use of feign.Client in project spring-cloud-sleuth by spring-cloud.

the class TraceFeignAspect method executeTraceFeignClient.

Object executeTraceFeignClient(Object bean, ProceedingJoinPoint pjp) throws IOException {
    Object[] args = pjp.getArgs();
    Request request = (Request) args[0];
    Request.Options options = (Request.Options) args[1];
    return ((Client) bean).execute(request, options);
}
Also used : Request(feign.Request) Client(feign.Client)

Aggregations

Client (feign.Client)12 Test (org.junit.Test)8 Request (feign.Request)5 Response (feign.Response)4 Feign (feign.Feign)3 RequestLine (feign.RequestLine)3 IOException (java.io.IOException)3 Charset (java.nio.charset.Charset)3 MockWebServer (okhttp3.mockwebserver.MockWebServer)3 Rule (org.junit.Rule)3 Tracing (brave.Tracing)2 HttpTracing (brave.http.HttpTracing)2 CurrentTraceContext (brave.propagation.CurrentTraceContext)2 FeignException (feign.FeignException)2 Logger (feign.Logger)2 Level (feign.Logger.Level)2 Decoder (feign.codec.Decoder)2 JacksonDecoder (feign.jackson.JacksonDecoder)2 JacksonEncoder (feign.jackson.JacksonEncoder)2 HashMap (java.util.HashMap)2