All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bitpay.sdk.client.HttpResponseProvider Maven / Gradle / Ivy

Go to download

Full implementation of the BitPay Payment Gateway. This library implements BitPay's Cryptographically Secure RESTful API.

The newest version!
/*
 * Copyright (c) 2019 BitPay.
 * All rights reserved.
 */

package com.bitpay.sdk.client;

import com.bitpay.sdk.exceptions.BitPayApiException;
import com.bitpay.sdk.exceptions.BitPayExceptionProvider;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;

public class HttpResponseProvider {

    public static HttpResponse fromApacheHttpResponse(org.apache.http.HttpResponse apacheHttpResponse)
        throws BitPayApiException {
        try {
            final HttpEntity entity = apacheHttpResponse.getEntity();
            String body = EntityUtils.toString(entity, "UTF-8");

            return new HttpResponse(
                apacheHttpResponse.getStatusLine().getStatusCode(),
                body,
                Arrays.stream(apacheHttpResponse.getAllHeaders())
                    .collect(Collectors.toMap(Header::getName, Header::getValue)),
                apacheHttpResponse.getLocale().toString(),
                apacheHttpResponse.getStatusLine().getProtocolVersion().toString()
            );

        } catch (IOException e) {
            BitPayExceptionProvider.throwApiExceptionWithMessage(e.getMessage());
            throw new RuntimeException(e.getMessage());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy