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