Search in sources :

Example 6 with Target

use of feign.Target 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)

Example 7 with Target

use of feign.Target in project feign by OpenFeign.

the class Http2ClientAsyncTest method doesntRetryAfterResponseIsSent.

@Test
public void doesntRetryAfterResponseIsSent() throws Throwable {
    server.enqueue(new MockResponse().setBody("success!"));
    thrown.expect(FeignException.class);
    thrown.expectMessage("timeout reading POST http://");
    final TestInterfaceAsync api = newAsyncBuilder().decoder((response, type) -> {
        throw new IOException("timeout");
    }).target("http://localhost:" + server.getPort());
    final CompletableFuture<?> cf = api.post();
    server.takeRequest();
    unwrap(cf);
}
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) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Target (feign.Target)7 IOException (java.io.IOException)5 Gson (com.google.gson.Gson)4 TypeToken (com.google.gson.reflect.TypeToken)4 AsyncClient (feign.AsyncClient)4 AsyncFeign (feign.AsyncFeign)4 Body (feign.Body)4 ChildPojo (feign.ChildPojo)4 Feign (feign.Feign)4 ResponseMappingDecoder (feign.Feign.ResponseMappingDecoder)4 FeignException (feign.FeignException)4 HeaderMap (feign.HeaderMap)4 Headers (feign.Headers)4 Param (feign.Param)4 PropertyPojo (feign.PropertyPojo)4 QueryMap (feign.QueryMap)4 QueryMapEncoder (feign.QueryMapEncoder)4 Request (feign.Request)4 HttpMethod (feign.Request.HttpMethod)4 RequestInterceptor (feign.RequestInterceptor)4