Search in sources :

Example 11 with Request

use of feign.Request in project feign by OpenFeign.

the class SpringContractTest method inheritance.

@Test
public void inheritance() {
    final Data data = resource.getData(new Data());
    assertThat(data, notNullValue());
    final Request request = mockClient.verifyOne(HttpMethod.GET, "/health/generic");
    assertThat(request.headers(), hasEntry("Content-Type", Arrays.asList("application/json")));
}
Also used : Request(feign.Request) Test(org.junit.Test)

Example 12 with Request

use of feign.Request in project feign by OpenFeign.

the class LBClient method execute.

@Override
public RibbonResponse execute(RibbonRequest request, IClientConfig configOverride) throws IOException, ClientException {
    Request.Options options;
    if (configOverride != null) {
        options = new Request.Options(configOverride.get(CommonClientConfigKey.ConnectTimeout, connectTimeout), TimeUnit.MILLISECONDS, (configOverride.get(CommonClientConfigKey.ReadTimeout, readTimeout)), TimeUnit.MILLISECONDS, configOverride.get(CommonClientConfigKey.FollowRedirects, followRedirects));
    } else {
        options = new Request.Options(connectTimeout, TimeUnit.MILLISECONDS, readTimeout, TimeUnit.MILLISECONDS, true);
    }
    Response response = request.client().execute(request.toRequest(), options);
    if (retryableStatusCodes.contains(response.status())) {
        response.close();
        throw new ClientException(ClientException.ErrorType.SERVER_THROTTLED);
    }
    return new RibbonResponse(request.getUri(), response);
}
Also used : Response(feign.Response) IResponse(com.netflix.client.IResponse) ClientRequest(com.netflix.client.ClientRequest) Request(feign.Request) ClientException(com.netflix.client.ClientException)

Example 13 with Request

use of feign.Request in project feign by OpenFeign.

the class JsonCodecTest method encodes.

@Test
public void encodes() {
    JSONObject contributor = new JSONObject();
    contributor.put("login", "radio-rogal");
    contributor.put("contributions", 0);
    mockClient.ok(HttpMethod.POST, "/repos/openfeign/feign/contributors", "{\"login\":\"radio-rogal\",\"contributions\":0}");
    JSONObject response = github.create("openfeign", "feign", contributor);
    Request request = mockClient.verifyOne(HttpMethod.POST, "/repos/openfeign/feign/contributors");
    assertNotNull(request.body());
    String json = new String(request.body());
    assertThat(json, containsString("\"login\":\"radio-rogal\""));
    assertThat(json, containsString("\"contributions\":0"));
    assertEquals("radio-rogal", response.getString("login"));
    assertEquals(0, response.getInt("contributions"));
}
Also used : JSONObject(org.json.JSONObject) Request(feign.Request) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

Request (feign.Request)13 Test (org.junit.Test)9 Response (feign.Response)7 Client (feign.Client)6 RequestLine (feign.RequestLine)5 Collection (java.util.Collection)5 IOException (java.io.IOException)4 Charset (java.nio.charset.Charset)4 MockWebServer (okhttp3.mockwebserver.MockWebServer)4 Rule (org.junit.Rule)4 Feign (feign.Feign)3 FeignException (feign.FeignException)3 Param (feign.Param)3 QueryMap (feign.QueryMap)3 QueryMapEncoder (feign.QueryMapEncoder)3 RequestInterceptor (feign.RequestInterceptor)3 RequestTemplate (feign.RequestTemplate)3 ResponseMapper (feign.ResponseMapper)3 Decoder (feign.codec.Decoder)3 HashMap (java.util.HashMap)3