Search in sources :

Example 1 with Body

use of feign.Body in project feign by OpenFeign.

the class Http2ClientAsyncTest method throwsFeignExceptionIncludingBody.

@Test
public void throwsFeignExceptionIncludingBody() throws Throwable {
    server.enqueue(new MockResponse().setBody("success!"));
    final TestInterfaceAsync api = newAsyncBuilder().decoder((response, type) -> {
        throw new IOException("timeout");
    }).target("http://localhost:" + server.getPort());
    final CompletableFuture<?> cf = api.body("Request body");
    server.takeRequest();
    try {
        unwrap(cf);
    } catch (final FeignException e) {
        Assertions.assertThat(e.getMessage()).isEqualTo("timeout reading POST http://localhost:" + server.getPort() + "/");
        Assertions.assertThat(e.contentUTF8()).isEqualTo("Request body");
        return;
    }
    fail();
}
Also used : ErrorDecoder(feign.codec.ErrorDecoder) Arrays(java.util.Arrays) Body(feign.Body) TypeToken(com.google.gson.reflect.TypeToken) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Decoder(feign.codec.Decoder) RequestInterceptor(feign.RequestInterceptor) FieldQueryMapEncoder(feign.querymap.FieldQueryMapEncoder) HttpMethod(feign.Request.HttpMethod) Gson(com.google.gson.Gson) AsyncFeign(feign.AsyncFeign) Map(java.util.Map) MockWebServer(okhttp3.mockwebserver.MockWebServer) Assertions(org.assertj.core.api.Assertions) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) AsyncClient(feign.AsyncClient) FeignException(feign.FeignException) BeanQueryMapEncoder(feign.querymap.BeanQueryMapEncoder) Collection(java.util.Collection) RequestLine(feign.RequestLine) PropertyPojo(feign.PropertyPojo) Feign(feign.Feign) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Encoder(feign.codec.Encoder) List(java.util.List) Type(java.lang.reflect.Type) MockWebServerAssertions.assertThat(feign.assertj.MockWebServerAssertions.assertThat) Http2Client(feign.http2client.Http2Client) ChildPojo(feign.ChildPojo) MockResponse(okhttp3.mockwebserver.MockResponse) MapEntry.entry(org.assertj.core.data.MapEntry.entry) RequestTemplate(feign.RequestTemplate) CoreMatchers.isA(org.hamcrest.CoreMatchers.isA) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Headers(feign.Headers) AtomicReference(java.util.concurrent.atomic.AtomicReference) ResponseMappingDecoder(feign.Feign.ResponseMappingDecoder) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) StringDecoder(feign.codec.StringDecoder) Util(feign.Util) NoSuchElementException(java.util.NoSuchElementException) ExpectedException(org.junit.rules.ExpectedException) ExecutorService(java.util.concurrent.ExecutorService) QueryMapEncoder(feign.QueryMapEncoder) ResponseMapper(feign.ResponseMapper) Response(feign.Response) Buffer(okio.Buffer) Target(feign.Target) HeaderMap(feign.HeaderMap) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) QueryMap(feign.QueryMap) HardCodedTarget(feign.Target.HardCodedTarget) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) Param(feign.Param) DecodeException(feign.codec.DecodeException) Request(feign.Request) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) EncodeException(feign.codec.EncodeException) MockResponse(okhttp3.mockwebserver.MockResponse) FeignException(feign.FeignException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 AsyncClient (feign.AsyncClient)1 AsyncFeign (feign.AsyncFeign)1 Body (feign.Body)1 ChildPojo (feign.ChildPojo)1 Feign (feign.Feign)1 ResponseMappingDecoder (feign.Feign.ResponseMappingDecoder)1 FeignException (feign.FeignException)1 HeaderMap (feign.HeaderMap)1 Headers (feign.Headers)1 Param (feign.Param)1 PropertyPojo (feign.PropertyPojo)1 QueryMap (feign.QueryMap)1 QueryMapEncoder (feign.QueryMapEncoder)1 Request (feign.Request)1 HttpMethod (feign.Request.HttpMethod)1 RequestInterceptor (feign.RequestInterceptor)1 RequestLine (feign.RequestLine)1 RequestTemplate (feign.RequestTemplate)1