use of feign.Response in project feign by OpenFeign.
the class JAXBCodecTest 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.<String, Collection<String>>emptyMap()).build();
assertThat((byte[]) new JAXBDecoder(new JAXBContextFactory.Builder().build()).decode(response, byte[].class)).isNull();
}
use of feign.Response in project feign by OpenFeign.
the class JAXBCodecTest method decodeAnnotatedParameterizedTypes.
@Test
public void decodeAnnotatedParameterizedTypes() throws Exception {
JAXBContextFactory jaxbContextFactory = new JAXBContextFactory.Builder().withMarshallerFormattedOutput(true).build();
Encoder encoder = new JAXBEncoder(jaxbContextFactory);
Box<String> boxStr = new Box<>();
boxStr.set("hello");
Box<Box<String>> boxBoxStr = new Box<>();
boxBoxStr.set(boxStr);
RequestTemplate template = new RequestTemplate();
encoder.encode(boxBoxStr, Box.class, template);
Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.<String, Collection<String>>emptyMap()).body(template.body()).build();
new JAXBDecoder(new JAXBContextFactory.Builder().build()).decode(response, Box.class);
}
use of feign.Response in project feign by OpenFeign.
the class RibbonClientTest method testFeignOptionsFollowRedirect.
@Test
public void testFeignOptionsFollowRedirect() {
String expectedLocation = server2.url("").url().toString();
server1.enqueue(new MockResponse().setResponseCode(302).setHeader("Location", expectedLocation));
getConfigInstance().setProperty(serverListKey(), hostAndPort(server1.url("").url()));
Request.Options options = new Request.Options(1000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS, false);
TestInterface api = Feign.builder().options(options).client(RibbonClient.create()).retryer(Retryer.NEVER_RETRY).target(TestInterface.class, "http://" + client());
try {
Response response = api.get();
assertEquals(302, response.status());
Collection<String> location = response.headers().get("Location");
assertNotNull(location);
assertFalse(location.isEmpty());
assertEquals(expectedLocation, location.iterator().next());
} catch (Exception ignored) {
ignored.printStackTrace();
fail("Shouldn't throw ");
}
}
use of feign.Response in project feign by OpenFeign.
the class SAXDecoderTest 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.<String, Collection<String>>emptyMap()).build();
assertThat((byte[]) decoder.decode(response, byte[].class)).isNull();
}
use of feign.Response in project feign by OpenFeign.
the class SOAPFaultDecoderTest method errorDecoderReturnsFeignExceptionOn503Status.
@Test
public void errorDecoderReturnsFeignExceptionOn503Status() throws IOException {
Response response = Response.builder().status(503).reason("Service Unavailable").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body("Service Unavailable", UTF_8).build();
Exception error = new SOAPErrorDecoder().decode("Service#foo()", response);
Assertions.assertThat(error).isInstanceOf(FeignException.class).hasMessage("[503 Service Unavailable] during [GET] to [/api] [Service#foo()]: [Service Unavailable]");
}
Aggregations