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);
}
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);
}
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));
}
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;
}
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);
}
Aggregations