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

org.springframework.web.client.logger.ClientHttpResponseLogWrapper Maven / Gradle / Ivy

The newest version!
package org.springframework.web.client.logger;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.StreamUtils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

public class ClientHttpResponseLogWrapper implements ClientHttpResponse {

    private final ClientHttpResponse response;
    @Nullable
    private byte[] body;

    public ClientHttpResponseLogWrapper(ClientHttpResponse response) {
        super();
        this.response = response;
    }

    @Override
    public HttpStatus getStatusCode() throws IOException {
        return this.response.getStatusCode();
    }

    @Override
    public int getRawStatusCode() throws IOException {
        return this.response.getRawStatusCode();
    }

    @Override
    public String getStatusText() throws IOException {
        return this.response.getStatusText();
    }

    @Override
    public HttpHeaders getHeaders() {
        return this.response.getHeaders();
    }

    @Override
    public InputStream getBody() throws IOException {
        if (this.body == null) {
            this.body = StreamUtils.copyToByteArray(this.response.getBody());
        }
        return new ByteArrayInputStream(this.body);
    }

    @Override
    public void close() {
        this.response.close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy