Search in sources :

Example 1 with CONTENT_TYPE

use of com.github.ljtfreitas.julian.http.HTTPHeader.CONTENT_TYPE in project julian-http-client by ljtfreitas.

the class DefaultHTTPRequestIO method deserialize.

private Optional<CompletableFuture<T>> deserialize(HTTPClientResponse response) {
    MediaType mediaType = response.headers().select(CONTENT_TYPE).map(h -> MediaType.valueOf(h.value())).orElseGet(MediaType::wildcard);
    HTTPResponseReader<?> reader = codecs.readers().select(mediaType, source.returnType()).orElseThrow(() -> new HTTPResponseReaderException(format("There is no a HTTPResponseReader able to convert {0} to {1}", mediaType, source.returnType())));
    return reader.read(response.body(), source.returnType()).map(c -> c.handleAsync(this::handle).toCompletableFuture());
}
Also used : HTTPClient(com.github.ljtfreitas.julian.http.client.HTTPClient) HTTPMessageException(com.github.ljtfreitas.julian.http.codec.HTTPMessageException) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) Message.format(com.github.ljtfreitas.julian.Message.format) HTTPResponseReaderException(com.github.ljtfreitas.julian.http.codec.HTTPResponseReaderException) HTTPResponseReader(com.github.ljtfreitas.julian.http.codec.HTTPResponseReader) ExecutionException(java.util.concurrent.ExecutionException) CONTENT_TYPE(com.github.ljtfreitas.julian.http.HTTPHeader.CONTENT_TYPE) HTTPMessageCodecs(com.github.ljtfreitas.julian.http.codec.HTTPMessageCodecs) HTTPClientException(com.github.ljtfreitas.julian.http.client.HTTPClientException) Promise(com.github.ljtfreitas.julian.Promise) Optional(java.util.Optional) HTTPClientResponse(com.github.ljtfreitas.julian.http.client.HTTPClientResponse) HTTPResponseReaderException(com.github.ljtfreitas.julian.http.codec.HTTPResponseReaderException)

Aggregations

Message.format (com.github.ljtfreitas.julian.Message.format)1 Promise (com.github.ljtfreitas.julian.Promise)1 CONTENT_TYPE (com.github.ljtfreitas.julian.http.HTTPHeader.CONTENT_TYPE)1 HTTPClient (com.github.ljtfreitas.julian.http.client.HTTPClient)1 HTTPClientException (com.github.ljtfreitas.julian.http.client.HTTPClientException)1 HTTPClientResponse (com.github.ljtfreitas.julian.http.client.HTTPClientResponse)1 HTTPMessageCodecs (com.github.ljtfreitas.julian.http.codec.HTTPMessageCodecs)1 HTTPMessageException (com.github.ljtfreitas.julian.http.codec.HTTPMessageException)1 HTTPResponseReader (com.github.ljtfreitas.julian.http.codec.HTTPResponseReader)1 HTTPResponseReaderException (com.github.ljtfreitas.julian.http.codec.HTTPResponseReaderException)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 ExecutionException (java.util.concurrent.ExecutionException)1