Search in sources :

Example 1 with Promise

use of com.canoo.platform.core.functional.Promise in project dolphin-platform by canoo.

the class HttpCallResponseBuilderImpl method readString.

@Override
public Promise<HttpResponse<String>, HttpException> readString() {
    connection.addRequestHeader(new HttpHeaderImpl(ACCEPT_CHARSET_HEADER, CHARSET));
    final ResponseContentConverter<String> converter = b -> new String(b, CHARSET);
    return createExecutor(converter);
}
Also used : HttpHeaderImpl(com.canoo.dp.impl.platform.core.http.HttpHeaderImpl) ByteArrayProvider(com.canoo.platform.core.http.ByteArrayProvider) HttpException(com.canoo.platform.core.http.HttpException) Assert(com.canoo.dp.impl.platform.core.Assert) ConnectionException(com.canoo.platform.core.http.ConnectionException) HttpResponse(com.canoo.platform.core.http.HttpResponse) HttpClientConnection(com.canoo.dp.impl.platform.core.http.HttpClientConnection) HttpHeader(com.canoo.platform.core.http.HttpHeader) HttpCallResponseBuilder(com.canoo.platform.core.http.HttpCallResponseBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) CHARSET(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.CHARSET) API(org.apiguardian.api.API) INTERNAL(org.apiguardian.api.API.Status.INTERNAL) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) Promise(com.canoo.platform.core.functional.Promise) List(java.util.List) ACCEPT_CHARSET_HEADER(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_CHARSET_HEADER) HttpURLConnectionHandler(com.canoo.platform.core.http.HttpURLConnectionHandler) Gson(com.google.gson.Gson) JSON_MIME_TYPE(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.JSON_MIME_TYPE) Collections(java.util.Collections) ClientConfiguration(com.canoo.platform.client.ClientConfiguration) ACCEPT_HEADER(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_HEADER) HttpHeaderImpl(com.canoo.dp.impl.platform.core.http.HttpHeaderImpl)

Example 2 with Promise

use of com.canoo.platform.core.functional.Promise in project dolphin-platform by canoo.

the class HttpCallResponseBuilderImpl method readObject.

@Override
public <R> Promise<HttpResponse<R>, HttpException> readObject(final Class<R> responseType) {
    Assert.requireNonNull(responseType, "responseType");
    connection.addRequestHeader(new HttpHeaderImpl(ACCEPT_CHARSET_HEADER, CHARSET));
    connection.addRequestHeader(new HttpHeaderImpl(ACCEPT_HEADER, JSON_MIME_TYPE));
    final ResponseContentConverter<R> converter = b -> gson.fromJson(new String(b, CHARSET), responseType);
    return createExecutor(converter);
}
Also used : HttpHeaderImpl(com.canoo.dp.impl.platform.core.http.HttpHeaderImpl) ByteArrayProvider(com.canoo.platform.core.http.ByteArrayProvider) HttpException(com.canoo.platform.core.http.HttpException) Assert(com.canoo.dp.impl.platform.core.Assert) ConnectionException(com.canoo.platform.core.http.ConnectionException) HttpResponse(com.canoo.platform.core.http.HttpResponse) HttpClientConnection(com.canoo.dp.impl.platform.core.http.HttpClientConnection) HttpHeader(com.canoo.platform.core.http.HttpHeader) HttpCallResponseBuilder(com.canoo.platform.core.http.HttpCallResponseBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) CHARSET(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.CHARSET) API(org.apiguardian.api.API) INTERNAL(org.apiguardian.api.API.Status.INTERNAL) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) Promise(com.canoo.platform.core.functional.Promise) List(java.util.List) ACCEPT_CHARSET_HEADER(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_CHARSET_HEADER) HttpURLConnectionHandler(com.canoo.platform.core.http.HttpURLConnectionHandler) Gson(com.google.gson.Gson) JSON_MIME_TYPE(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.JSON_MIME_TYPE) Collections(java.util.Collections) ClientConfiguration(com.canoo.platform.client.ClientConfiguration) ACCEPT_HEADER(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_HEADER) ACCEPT_CHARSET_HEADER(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_CHARSET_HEADER) ACCEPT_HEADER(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_HEADER) HttpHeaderImpl(com.canoo.dp.impl.platform.core.http.HttpHeaderImpl)

Aggregations

Assert (com.canoo.dp.impl.platform.core.Assert)2 HttpClientConnection (com.canoo.dp.impl.platform.core.http.HttpClientConnection)2 ACCEPT_CHARSET_HEADER (com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_CHARSET_HEADER)2 ACCEPT_HEADER (com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.ACCEPT_HEADER)2 CHARSET (com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.CHARSET)2 JSON_MIME_TYPE (com.canoo.dp.impl.platform.core.http.HttpHeaderConstants.JSON_MIME_TYPE)2 HttpHeaderImpl (com.canoo.dp.impl.platform.core.http.HttpHeaderImpl)2 ClientConfiguration (com.canoo.platform.client.ClientConfiguration)2 DolphinRuntimeException (com.canoo.platform.core.DolphinRuntimeException)2 Promise (com.canoo.platform.core.functional.Promise)2 ByteArrayProvider (com.canoo.platform.core.http.ByteArrayProvider)2 ConnectionException (com.canoo.platform.core.http.ConnectionException)2 HttpCallResponseBuilder (com.canoo.platform.core.http.HttpCallResponseBuilder)2 HttpException (com.canoo.platform.core.http.HttpException)2 HttpHeader (com.canoo.platform.core.http.HttpHeader)2 HttpResponse (com.canoo.platform.core.http.HttpResponse)2 HttpURLConnectionHandler (com.canoo.platform.core.http.HttpURLConnectionHandler)2 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2