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

com.adobe.platform.operation.internal.http.BaseHttpResponse Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2019 Adobe
 * All Rights Reserved.
 *
 * NOTICE: Adobe permits you to use, modify, and distribute this file in
 * accordance with the terms of the Adobe license agreement accompanying
 * it. If you have received this file from a source other than Adobe,
 * then your use, modification, or distribution of it requires the prior
 * written permission of Adobe.
 */

package com.adobe.platform.operation.internal.http;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import static com.adobe.platform.operation.internal.http.DefaultRequestHeaders.DC_REQUEST_ID_HEADER_KEY;

public class BaseHttpResponse implements HttpResponse {

    private int statusCode;
    private Map headers;
    private T baseResponseDto;
    private InputStream inputStream;

    public BaseHttpResponse(int statusCode, Map headers, T baseResponseDto) {
        this.statusCode = statusCode;
        this.headers = headers;
        this.baseResponseDto = baseResponseDto;
    }

    public BaseHttpResponse(int statusCode, Map headers) {
        this.statusCode = statusCode;
        this.headers = headers;
        this.inputStream = null;
        this.baseResponseDto = null;
    }

    @Override
    public Map getHeaders() {
        return headers;
    }

    @Override
    public int getStatusCode() {
        return statusCode;
    }

    @Override
    public String getRequestId() {
        if (headers != null) {
            return headers.get(DC_REQUEST_ID_HEADER_KEY);
        }
        return null;
    }

    @Override
    public T getBody() {
        return baseResponseDto;
    }

    @Override
    public InputStream getResponseAsStream() {
        return inputStream;
    }

    @Override
    public void consume() throws IOException {
        if (inputStream != null) {
            inputStream.close();
        }
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy