Search in sources :

Example 1 with HttpMethod

use of feign.Request.HttpMethod in project feign by OpenFeign.

the class LBClientTest method testRibbonRequest.

@Test
public void testRibbonRequest() throws URISyntaxException {
    // test for RibbonRequest.toRequest()
    // the url has a query whose value is an encoded json string
    String urlWithEncodedJson = "http://test.feign.com/p?q=%7b%22a%22%3a1%7d";
    HttpMethod method = HttpMethod.GET;
    URI uri = new URI(urlWithEncodedJson);
    Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>();
    // create a Request for recreating another Request by toRequest()
    Request requestOrigin = Request.create(method, uri.toASCIIString(), headers, null, Charset.forName("utf-8"));
    RibbonRequest ribbonRequest = new RibbonRequest(null, requestOrigin, uri);
    // use toRequest() recreate a Request
    Request requestRecreate = ribbonRequest.toRequest();
    // test that requestOrigin and requestRecreate are same except the header 'Content-Length'
    // ps, requestOrigin and requestRecreate won't be null
    assertThat(requestOrigin.toString()).contains(String.format("%s %s HTTP/1.1\n", method, urlWithEncodedJson));
    assertThat(requestRecreate.toString()).contains(String.format("%s %s HTTP/1.1\nContent-Length: 0\n", method, urlWithEncodedJson));
}
Also used : Request(feign.Request) RibbonRequest(feign.ribbon.LBClient.RibbonRequest) Collection(java.util.Collection) RibbonRequest(feign.ribbon.LBClient.RibbonRequest) URI(java.net.URI) HttpMethod(feign.Request.HttpMethod) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

Request (feign.Request)1 HttpMethod (feign.Request.HttpMethod)1 RibbonRequest (feign.ribbon.LBClient.RibbonRequest)1 URI (java.net.URI)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Test (org.junit.Test)1