Search in sources :

Example 1 with HardCodedTarget

use of feign.Target.HardCodedTarget in project feign by OpenFeign.

the class TargetTest method targetCanCreateCustomRequest.

/**
   * Per <a href="https://github.com/Netflix/feign/issues/227">#227</a>, some may want to opt out of
   * percent encoding. Here's how.
   */
@Test
public void targetCanCreateCustomRequest() throws InterruptedException {
    server.enqueue(new MockResponse());
    String baseUrl = server.url("/default").toString();
    Target<TestQuery> custom = new HardCodedTarget<TestQuery>(TestQuery.class, baseUrl) {

        @Override
        public Request apply(RequestTemplate input) {
            Request urlEncoded = super.apply(input);
            return Request.create(urlEncoded.method(), urlEncoded.url().replace("%2F", "/"), urlEncoded.headers(), urlEncoded.body(), urlEncoded.charset());
        }
    };
    Feign.builder().target(custom).get("slash/foo", "slash/bar");
    assertThat(server.takeRequest()).hasPath("/default/slash/foo?query=slash/bar");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HardCodedTarget(feign.Target.HardCodedTarget) Test(org.junit.Test)

Example 2 with HardCodedTarget

use of feign.Target.HardCodedTarget 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)

Aggregations

HardCodedTarget (feign.Target.HardCodedTarget)2 Client (feign.Client)1 Contract (feign.Contract)1 MethodMetadata (feign.MethodMetadata)1 Request (feign.Request)1 Response (feign.Response)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.junit.Test)1 Setup (org.openjdk.jmh.annotations.Setup)1