use of org.apache.hc.core5.http.HttpResponse in project feign by OpenFeign.
the class AsyncApacheHttp5Client method toFeignResponse.
Response toFeignResponse(SimpleHttpResponse httpResponse, Request request) {
final int statusCode = httpResponse.getCode();
final String reason = httpResponse.getReasonPhrase();
final Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>();
for (final Header header : httpResponse.getHeaders()) {
final String name = header.getName();
final String value = header.getValue();
Collection<String> headerValues = headers.get(name);
if (headerValues == null) {
headerValues = new ArrayList<String>();
headers.put(name, headerValues);
}
headerValues.add(value);
}
return Response.builder().status(statusCode).reason(reason).headers(headers).request(request).body(httpResponse.getBodyBytes()).build();
}
use of org.apache.hc.core5.http.HttpResponse in project feign by OpenFeign.
the class AsyncApacheHttp5Client method execute.
@Override
public CompletableFuture<Response> execute(Request request, Options options, Optional<HttpClientContext> requestContext) {
final SimpleHttpRequest httpUriRequest = toClassicHttpRequest(request, options);
final CompletableFuture<Response> result = new CompletableFuture<>();
final FutureCallback<SimpleHttpResponse> callback = new FutureCallback<SimpleHttpResponse>() {
@Override
public void completed(SimpleHttpResponse httpResponse) {
result.complete(toFeignResponse(httpResponse, request));
}
@Override
public void failed(Exception ex) {
result.completeExceptionally(ex);
}
@Override
public void cancelled() {
result.cancel(false);
}
};
client.execute(httpUriRequest, configureTimeouts(options, requestContext.orElseGet(HttpClientContext::new)), callback);
return result;
}
use of org.apache.hc.core5.http.HttpResponse in project pact-jvm by DiUS.
the class ArticlesTest method testArticles.
@Test
@PactTestFor(pactMethod = "articles")
void testArticles(MockServer mockServer) throws IOException {
ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.get(mockServer.getUrl() + "/articles.json").execute().returnResponse();
assertThat(httpResponse.getCode(), is(equalTo(200)));
assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is(equalTo("{\"articles\":[{\"variants\":{\"0032\":{\"description\":\"sample description\"}}}]}")));
}
use of org.apache.hc.core5.http.HttpResponse in project pact-jvm by DiUS.
the class ArticlesTest method testArticlesDoNotExist.
@Test
@PactTestFor(pactMethod = "articlesDoNotExist")
void testArticlesDoNotExist(MockServer mockServer) throws IOException {
ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.get(mockServer.getUrl() + "/articles.json").execute().returnResponse();
assertThat(httpResponse.getCode(), is(equalTo(404)));
assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is(equalTo("")));
}
use of org.apache.hc.core5.http.HttpResponse in project pact-jvm by DiUS.
the class Defect1070Test method testApi.
@Test
@PactTestFor
void testApi(MockServer mockServer) throws IOException {
ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.get(mockServer.getUrl() + "/api/test/1234").execute().returnResponse();
assertThat(httpResponse.getCode(), is(equalTo(200)));
assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is(equalTo("[{\"id\":32432,\"name\":\"testId254\",\"size\":1445211}]")));
}
Aggregations