Search in sources :

Example 41 with Response

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

Example 42 with Response

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

Example 43 with Response

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 ");
    }
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Request(feign.Request) RetryableException(feign.RetryableException) IOException(java.io.IOException) Test(org.junit.Test)

Example 44 with Response

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

Example 45 with Response

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]");
}
Also used : Response(feign.Response) FeignException(feign.FeignException) IOException(java.io.IOException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ExpectedException(org.junit.rules.ExpectedException) FeignException(feign.FeignException) 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