use of feign.Response in project feign by OpenFeign.
the class DefaultErrorDecoderTest method retryAfterHeaderThrowsRetryableException.
@Test
public void retryAfterHeaderThrowsRetryableException() throws Throwable {
thrown.expect(FeignException.class);
thrown.expectMessage("[503 Service Unavailable] during [GET] to [/api] [Service#foo()]: []");
headers.put(RETRY_AFTER, Collections.singletonList("Sat, 1 Jan 2000 00:00:00 GMT"));
Response response = Response.builder().status(503).reason("Service Unavailable").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(headers).build();
throw errorDecoder.decode("Service#foo()", response);
}
use of feign.Response in project feign by OpenFeign.
the class StreamDecoderTest method shouldCloseIteratorWhenStreamClosed.
@Test
public void shouldCloseIteratorWhenStreamClosed() throws IOException {
Response response = Response.builder().status(200).reason("OK").headers(Collections.emptyMap()).request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).body("", UTF_8).build();
TestCloseableIterator it = new TestCloseableIterator();
StreamDecoder decoder = new StreamDecoder((r, t) -> it);
try (Stream<?> stream = (Stream) decoder.decode(response, new TypeReference<Stream<String>>() {
}.getType())) {
assertThat(stream.collect(Collectors.toList())).hasSize(1);
assertThat(it.called).isTrue();
} finally {
assertThat(it.closed).isTrue();
}
}
use of feign.Response in project pravega by pravega.
the class LoginClient method getAuthToken.
/**
* Fetch the token from the authentication service.
*
* @param loginURL Login Url.
* @return Auth token.
*/
public static String getAuthToken(final String loginURL) {
Login client = Feign.builder().client(getClientHostVerificationDisabled()).encoder(new GsonEncoder(ModelUtils.GSON)).target(Login.class, loginURL);
Response response = client.login(new AuthRequest(getUsername(), getPassword(), "LOCAL"));
if (response.status() == OK.getStatusCode()) {
Collection<String> headers = response.headers().get(TOKEN_HEADER_NAME);
return headers.toArray(new String[headers.size()])[0];
} else {
throw new TestFrameworkException(TestFrameworkException.Type.LoginFailed, "Exception while " + "logging into the cluster. Authentication service returned the following error: " + response);
}
}
use of feign.Response in project feign by OpenFeign.
the class GsonCodecTest method notFoundDecodesToEmpty.
/** Enabled via {@link feign.Feign.Builder#decode404()} */
@Test
public void notFoundDecodesToEmpty() throws Exception {
Response response = Response.builder().status(404).reason("NOT FOUND").headers(Collections.<String, Collection<String>>emptyMap()).build();
assertThat((byte[]) new GsonDecoder().decode(response, byte[].class)).isEmpty();
}
use of feign.Response in project feign by OpenFeign.
the class SAXDecoderTest method notFoundDecodesToEmpty.
/** Enabled via {@link feign.Feign.Builder#decode404()} */
@Test
public void notFoundDecodesToEmpty() throws Exception {
Response response = Response.builder().status(404).reason("NOT FOUND").headers(Collections.<String, Collection<String>>emptyMap()).build();
assertThat((byte[]) decoder.decode(response, byte[].class)).isEmpty();
}
Aggregations