use of com.github.ljtfreitas.julian.Promise in project julian-http-client by ljtfreitas.
the class DefaultHTTP method run.
@Override
public <T> Promise<HTTPResponse<T>> run(RequestDefinition definition) {
URI uri = definition.path();
HTTPHeaders headers = definition.headers().all().stream().map(h -> new HTTPHeader(h.name(), h.values())).reduce(HTTPHeaders.empty(), HTTPHeaders::join, (a, b) -> b);
HTTPRequestBody body = definition.body().map(b -> body(b.content(), b.javaType(), headers)).orElse(null);
HTTPMethod method = HTTPMethod.select(definition.method()).orElseThrow(() -> new IllegalArgumentException(format("Unsupported HTTP method: {0}", definition.method())));
HTTPRequest<T> request = new DefaultHTTPRequest<>(uri, method, body, headers, definition.returnType(), httpClient, codecs, failure);
return intercepts(Promise.pending(() -> request, executor)).bind(HTTPRequest::execute);
}
Aggregations