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

me.vcoder.httplogger.TraceableHttpServletResponse Maven / Gradle / Ivy

The newest version!
package me.vcoder.httplogger;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

/**
 * @author baodn
 * Created on 11 Apr 2018
 */
final class TraceableHttpServletResponse implements TraceableResponse {

    private final CaptureBodyHttpServletResponse delegate;

    TraceableHttpServletResponse(CaptureBodyHttpServletResponse response) {
        this.delegate = response;
    }

    @Override
    public int getStatus() {
        return this.delegate.getStatus();
    }

    @Override
    public Map> getHeaders() {
        return extractHeaders();
    }

    private Map> extractHeaders() {
        Map> headers = new LinkedHashMap<>();
        for (String name : this.delegate.getHeaderNames()) {
            headers.put(name, new ArrayList<>(this.delegate.getHeaders(name)));
        }
        return headers;
    }

    @Override
    public String getBody() {
        try {
            return this.delegate.getBody();
        } catch (UnsupportedEncodingException ex) {
            return "";
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy