Search in sources :

Example 31 with Response

use of feign.Response in project feign by OpenFeign.

the class WhatShouldWeCacheBenchmarks method setup.

@Setup
public void setup() {
    feignContract = new Contract.Default();
    cachedContact = new Contract() {

        private final List<MethodMetadata> cached = new Default().parseAndValidatateMetadata(FeignTestInterface.class);

        public List<MethodMetadata> parseAndValidatateMetadata(Class<?> declaring) {
            return cached;
        }
    };
    fakeClient = new Client() {

        public Response execute(Request request, Request.Options options) throws IOException {
            Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>();
            return Response.create(200, "ok", headers, (byte[]) null);
        }
    };
    cachedFakeFeign = Feign.builder().client(fakeClient).build();
    cachedFakeApi = cachedFakeFeign.newInstance(new HardCodedTarget<FeignTestInterface>(FeignTestInterface.class, "http://localhost"));
}
Also used : Request(feign.Request) HardCodedTarget(feign.Target.HardCodedTarget) IOException(java.io.IOException) Response(feign.Response) Collection(java.util.Collection) MethodMetadata(feign.MethodMetadata) List(java.util.List) Client(feign.Client) Contract(feign.Contract) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Setup(org.openjdk.jmh.annotations.Setup)

Example 32 with Response

use of feign.Response in project feign by OpenFeign.

the class LBClient method execute.

@Override
public RibbonResponse execute(RibbonRequest request, IClientConfig configOverride) throws IOException {
    Request.Options options;
    if (configOverride != null) {
        options = new Request.Options(configOverride.get(CommonClientConfigKey.ConnectTimeout, connectTimeout), (configOverride.get(CommonClientConfigKey.ReadTimeout, readTimeout)));
    } else {
        options = new Request.Options(connectTimeout, readTimeout);
    }
    Response response = request.client().execute(request.toRequest(), options);
    return new RibbonResponse(request.getUri(), response);
}
Also used : Response(feign.Response) IResponse(com.netflix.client.IResponse) ClientRequest(com.netflix.client.ClientRequest) Request(feign.Request)

Example 33 with Response

use of feign.Response in project feign by OpenFeign.

the class SAXDecoderTest method nullBodyDecodesToNull.

@Test
public void nullBodyDecodesToNull() throws Exception {
    Response response = Response.builder().status(204).reason("OK").headers(Collections.<String, Collection<String>>emptyMap()).build();
    assertNull(decoder.decode(response, String.class));
}
Also used : Response(feign.Response) Collection(java.util.Collection) Test(org.junit.Test)

Example 34 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)34 Test (org.junit.Test)32 Collection (java.util.Collection)9 MockResponse (okhttp3.mockwebserver.MockResponse)8 List (java.util.List)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)3 Request (feign.Request)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 LinkedHashMap (java.util.LinkedHashMap)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 ClientRequest (com.netflix.client.ClientRequest)1 IResponse (com.netflix.client.IResponse)1 Client (feign.Client)1 Contract (feign.Contract)1 FeignException (feign.FeignException)1 MethodMetadata (feign.MethodMetadata)1 HardCodedTarget (feign.Target.HardCodedTarget)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1