Search in sources :

Example 86 with Response

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);
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 87 with 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();
    }
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) Stream(java.util.stream.Stream) Test(org.junit.Test)

Example 88 with Response

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);
    }
}
Also used : Response(feign.Response) GsonEncoder(feign.gson.GsonEncoder)

Example 89 with 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();
}
Also used : Response(feign.Response) Collection(java.util.Collection) Test(org.junit.Test)

Example 90 with Response

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();
}
Also used : Response(feign.Response) Collection(java.util.Collection) 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