Java Code Examples for io.reactivex.netty.protocol.http.client.HttpClientResponse#getStatus()

The following examples show how to use io.reactivex.netty.protocol.http.client.HttpClientResponse#getStatus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseUtils.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public static Single<StoreResponse> toStoreResponse(HttpClientResponse<ByteBuf> clientResponse) {

        HttpResponseHeaders httpResponseHeaders = clientResponse.getHeaders();
        HttpResponseStatus httpResponseStatus = clientResponse.getStatus();

        Observable<String> contentObservable;

        if (clientResponse.getContent() == null) {
            // for delete we don't expect any body
            contentObservable = Observable.just(null);
        } else {
            // transforms the observable<ByteBuf> to Observable<InputStream>
            contentObservable = toString(clientResponse.getContent(), clientResponse.getHeaders().getIntHeader(HttpConstants.HttpHeaders.CONTENT_LENGTH, -1));
        }

        Observable<StoreResponse> storeResponseObservable = contentObservable
                .flatMap(content -> {
                    try {
                        // transforms to Observable<StoreResponse>
                        StoreResponse rsp = new StoreResponse(httpResponseStatus.code(), HttpUtils.unescape(httpResponseHeaders.entries()), content);
                        return Observable.just(rsp);
                    } catch (Exception e) {
                        return Observable.error(e);
                    }
                });

        return storeResponseObservable.toSingle();
    }
 
Example 2
Source File: RecommendationServiceResponseValidator.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Override
public void validate(HttpClientResponse<ByteBuf> response) throws UnsuccessfulResponseException, ServerError {
    if (response.getStatus().code() / 100 != 2) {
        throw new UnsuccessfulResponseException("Unexpected HTTP status code " + response.getStatus());
    }
}