use of com.canoo.platform.core.http.HttpHeader in project dolphin-platform by canoo.
the class HttpCallResponseBuilderImpl method handleRequest.
private <R> HttpResponse<R> handleRequest(final ResponseContentConverter<R> converter) throws HttpException {
Assert.requireNonNull(converter, "converter");
if (handled.get()) {
throw new DolphinRuntimeException("Http call already handled");
}
handled.set(true);
requestHandlers.forEach(h -> h.handle(connection.getConnection()));
final byte[] rawBytes = dataProvider.get();
try {
connection.writeRequestContent(rawBytes);
} catch (final IOException e) {
throw new ConnectionException("Can not connect to server", e);
}
try {
int responseCode = connection.readResponseCode();
final byte[] rawContent = connection.readResponseContent();
responseHandlers.forEach(h -> h.handle(connection.getConnection()));
final R content = converter.convert(rawContent);
final List<HttpHeader> headers = connection.getResponseHeaders();
return new HttpResponseImpl<R>(headers, responseCode, rawContent, content);
} catch (IOException e) {
throw new ConnectionException("No response from server", e);
} catch (Exception e) {
throw new HttpException("Can not handle response", e);
}
}
Aggregations