Search in sources :

Example 71 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method nullBodyDecodesToNull.

@Test
public void nullBodyDecodesToNull() throws Exception {
    Response response = Response.builder().status(204).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).build();
    assertNull(new JacksonDecoder().decode(response, String.class));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 72 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method decoderCharset.

@Test
public void decoderCharset() throws IOException {
    Zone zone = new Zone("denominator.io.", "ÁÉÍÓÚÀÈÌÒÙÄËÏÖÜÑ");
    Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>();
    headers.put("Content-Type", Arrays.asList("application/json;charset=ISO-8859-1"));
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(headers).body(new String(// 
    "" + "{" + System.lineSeparator() + "  \"name\" : \"DENOMINATOR.IO.\"," + System.lineSeparator() + "  \"id\" : \"ÁÉÍÓÚÀÈÌÒÙÄËÏÖÜÑ\"" + System.lineSeparator() + "}").getBytes(StandardCharsets.ISO_8859_1)).build();
    assertEquals(zone.get("id"), ((Zone) new JacksonDecoder().decode(response, new TypeReference<Zone>() {
    }.getType())).get("id"));
}
Also used : Response(feign.Response) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Collection(java.util.Collection) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 73 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method notFoundDecodesToNullIterator.

/**
 * Enabled via {@link feign.Feign.Builder#decode404()}
 */
@Test
public void notFoundDecodesToNullIterator() throws Exception {
    Response response = Response.builder().status(404).reason("NOT FOUND").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).build();
    assertThat((byte[]) JacksonIteratorDecoder.create().decode(response, byte[].class)).isNull();
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 74 with Response

use of feign.Response in project feign by OpenFeign.

the class RealRequestBenchmarks method setup.

@Setup
public void setup() {
    server = HttpServer.newServer(SERVER_PORT).start((request, response) -> null);
    client = new OkHttpClient();
    client.retryOnConnectionFailure();
    okFeign = Feign.builder().client(new feign.okhttp.OkHttpClient(client)).logLevel(Level.NONE).logger(new Logger.ErrorLogger()).retryer(new Retryer.Default()).target(FeignTestInterface.class, "http://localhost:" + SERVER_PORT);
    queryRequest = new Request.Builder().url("http://localhost:" + SERVER_PORT + "/?Action=GetUser&Version=2010-05-08&limit=1").build();
}
Also used : Response(feign.Response) Request(okhttp3.Request) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Setup(org.openjdk.jmh.annotations.Setup) Measurement(org.openjdk.jmh.annotations.Measurement) Mode(org.openjdk.jmh.annotations.Mode) Logger(feign.Logger) IOException(java.io.IOException) Scope(org.openjdk.jmh.annotations.Scope) Retryer(feign.Retryer) State(org.openjdk.jmh.annotations.State) Feign(feign.Feign) Level(feign.Logger.Level) Warmup(org.openjdk.jmh.annotations.Warmup) Benchmark(org.openjdk.jmh.annotations.Benchmark) TimeUnit(java.util.concurrent.TimeUnit) OkHttpClient(okhttp3.OkHttpClient) ByteBuf(io.netty.buffer.ByteBuf) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) Fork(org.openjdk.jmh.annotations.Fork) TearDown(org.openjdk.jmh.annotations.TearDown) HttpServer(io.reactivex.netty.protocol.http.server.HttpServer) OkHttpClient(okhttp3.OkHttpClient) Retryer(feign.Retryer) Request(okhttp3.Request) Setup(org.openjdk.jmh.annotations.Setup)

Example 75 with Response

use of feign.Response in project feign by OpenFeign.

the class SOAPCodecTest method notFoundDecodesToNull.

/**
 * Enabled via {@link feign.Feign.Builder#decode404()}
 */
@Test
public void notFoundDecodesToNull() throws Exception {
    Response response = Response.builder().status(404).reason("NOT FOUND").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).build();
    assertThat((byte[]) new JAXBDecoder(new JAXBContextFactory.Builder().build()).decode(response, byte[].class)).isNull();
}
Also used : Response(feign.Response) JAXBDecoder(feign.jaxb.JAXBDecoder) Test(org.junit.Test)

Aggregations

Response (feign.Response)169 Test (org.junit.Test)118 IOException (java.io.IOException)32 MockResponse (okhttp3.mockwebserver.MockResponse)26 KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)22 Test (org.testng.annotations.Test)20 Collection (java.util.Collection)19 HashMap (java.util.HashMap)16 OAuth2IntrospectionResponse (org.wso2.carbon.apimgt.core.auth.dto.OAuth2IntrospectionResponse)16 ArrayList (java.util.ArrayList)15 Gson (com.google.gson.Gson)13 FeignException (feign.FeignException)13 OAuth2ServiceStubs (org.wso2.carbon.apimgt.core.auth.OAuth2ServiceStubs)13 IdentityProviderException (org.wso2.carbon.apimgt.core.exception.IdentityProviderException)13 Request (feign.Request)11 RetryableException (feign.RetryableException)11 DecodeException (feign.codec.DecodeException)10 Map (java.util.Map)10 ExpectedException (org.junit.rules.ExpectedException)10 Type (java.lang.reflect.Type)9