use of feign.Response in project incubator-skywalking by apache.
the class DefaultHttpClientInterceptorTest method testMethodsAroundError.
@Test
public void testMethodsAroundError() throws Throwable {
defaultHttpClientInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, result);
Response response = mock(Response.class);
when(response.status()).thenReturn(404);
defaultHttpClientInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0);
assertSpan(finishedSpan);
List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
assertThat(tags.size(), is(3));
assertThat(tags.get(0).getValue(), is("GET"));
assertThat(tags.get(1).getValue(), is("http://skywalking.org/"));
assertThat(tags.get(2).getValue(), is("404"));
Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan));
}
use of feign.Response 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.Response in project feign by OpenFeign.
the class MeteredDecoder method decode.
@Override
public Object decode(Response response, Type type) throws IOException, FeignException {
final Optional<MeteredBody> body = Optional.ofNullable(response.body()).map(MeteredBody::new);
Response meteredResponse = body.map(b -> response.toBuilder().body(b).build()).orElse(response);
Object decoded;
final Timer.Sample sample = Timer.start(meterRegistry);
Timer timer = null;
try {
decoded = decoder.decode(meteredResponse, type);
timer = createTimer(response, type, null);
} catch (IOException | RuntimeException e) {
timer = createTimer(response, type, e);
createExceptionCounter(response, type, e).count();
throw e;
} catch (Exception e) {
timer = createTimer(response, type, e);
createExceptionCounter(response, type, e).count();
throw new IOException(e);
} finally {
if (timer == null) {
timer = createTimer(response, type, null);
}
sample.stop(timer);
}
body.ifPresent(b -> createSummary(response, type).record(b.count()));
return decoded;
}
use of feign.Response in project feign by OpenFeign.
the class OkHttpClientTest method testFollowRedirect.
@Test
public void testFollowRedirect() throws Exception {
String expectedBody = "Hello";
server.enqueue(new MockResponse().setResponseCode(302).addHeader("Location", server.url("redirect")));
server.enqueue(new MockResponse().setBody(expectedBody));
OkHttpClientTestInterface api = newBuilder().options(new Request.Options(10_000, TimeUnit.MILLISECONDS, 10_000, TimeUnit.MILLISECONDS, true)).target(OkHttpClientTestInterface.class, "http://localhost:" + server.getPort());
Response response = api.get();
// Response length should not be null
assertEquals(200, response.status());
String payload = Util.toString(response.body().asReader(StandardCharsets.UTF_8));
assertEquals(expectedBody, payload);
}
use of feign.Response in project feign by OpenFeign.
the class OkHttpClientTest method testContentTypeWithoutCharset.
@Test
public void testContentTypeWithoutCharset() throws Exception {
server.enqueue(new MockResponse().setBody("AAAAAAAA"));
OkHttpClientTestInterface api = newBuilder().target(OkHttpClientTestInterface.class, "http://localhost:" + server.getPort());
Response response = api.getWithContentType();
// Response length should not be null
assertEquals("AAAAAAAA", Util.toString(response.body().asReader(Util.UTF_8)));
MockWebServerAssertions.assertThat(server.takeRequest()).hasHeaders(MapEntry.entry("Accept", Collections.singletonList("text/plain")), MapEntry.entry("Content-Type", Collections.singletonList("text/plain"))).hasMethod("GET");
}
Aggregations