private <T> ResponseEntity<T> createResponse(Class<T> clazz, Object instance, Response response) {

    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    for (String key : response.headers().keySet()) {
      headers.put(key, new LinkedList<>(response.headers().get(key)));
    }

    return new ResponseEntity<T>(
        clazz.cast(instance), headers, HttpStatus.valueOf(response.status()));
  }
예제 #2
0
  @Test
  public void reasonPhraseIsOptional() throws IOException, InterruptedException {
    server.enqueue(new MockResponse().setStatus("HTTP/1.1 " + 200));

    TestInterface api =
        Feign.builder().target(TestInterface.class, "http://localhost:" + server.getPort());

    Response response = api.post("foo");

    assertThat(response.status()).isEqualTo(200);
    assertThat(response.reason()).isNull();
  }
 @Override
 protected Response logAndRebufferResponse(
     String configKey, feign.Logger.Level logLevel, Response response, long elapsedTime)
     throws IOException {
   String requestId = requestIdProvider.getRequestId();
   HttpData reqData = requestDataProvider.retrieve(requestId);
   if (requestTraceable(reqData) && isNotSkipped(reqData)) {
     byte[] bodyData = Util.toByteArray(response.body().asInputStream());
     String content = new String(bodyData, StandardCharsets.UTF_8.name());
     HttpData resData = new HttpData(extractHeaders(response), extractStatus(response), content);
     Response rebufferedResponse =
         Response.create(response.status(), response.reason(), response.headers(), bodyData);
     requestResponseLogger.logObfuscatedResponse(reqData, resData, TAG);
     requestDataProvider.remove(requestId);
     return super.logAndRebufferResponse(configKey, logLevel, rebufferedResponse, elapsedTime);
   } else {
     log.debug("Cannot obfuscate response, matching request data lost");
     return super.logAndRebufferResponse(configKey, logLevel, response, elapsedTime);
   }
 }
예제 #4
0
  @Test
  public void parsesRequestAndResponse() throws IOException, InterruptedException {
    server.enqueue(new MockResponse().setBody("foo").addHeader("Foo: Bar"));

    TestInterface api =
        Feign.builder().target(TestInterface.class, "http://localhost:" + server.getPort());

    Response response = api.post("foo");

    assertThat(response.status()).isEqualTo(200);
    assertThat(response.reason()).isEqualTo("OK");
    assertThat(response.headers())
        .containsEntry("Content-Length", asList("3"))
        .containsEntry("Foo", asList("Bar"));
    assertThat(response.body().asInputStream())
        .hasContentEqualTo(new ByteArrayInputStream("foo".getBytes(UTF_8)));

    assertThat(server.takeRequest())
        .hasMethod("POST")
        .hasPath("/?foo=bar&foo=baz&qux=")
        .hasHeaders("Foo: Bar", "Foo: Baz", "Qux: ", "Accept: */*", "Content-Length: 3")
        .hasBody("foo");
  }