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

org.jose4j.http.Response Maven / Gradle / Ivy

The newest version!
package org.jose4j.http;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
public class Response implements SimpleResponse
{
    private int statusCode;
    private String statusMessage;
    private Map> headers;
    private String body;

    public Response(int statusCode, String statusMessage, Map> headers, String body)
    {
        this.statusCode = statusCode;
        this.statusMessage = statusMessage;
        this.headers = new HashMap<>();
        for (Map.Entry> header : headers.entrySet())
        {
            String name = normalizeHeaderName(header.getKey());
            this.headers.put(name, header.getValue());
        }
        this.body = body;
    }

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

    @Override
    public String getStatusMessage()
    {
        return statusMessage;
    }

    @Override
    public Collection getHeaderNames()
    {
        return headers.keySet();
    }

    @Override
    public List getHeaderValues(String name)
    {
        name = normalizeHeaderName(name);
        return headers.get(name);
    }

    @Override
    public String getBody()
    {
        return body;
    }

    private String normalizeHeaderName(String name)
    {
        return name != null ? name.toLowerCase().trim() : null;
    }

    @Override
    public String toString()
    {
        return "SimpleResponse{" +
                "statusCode=" + statusCode +
                ", statusMessage='" + statusMessage + '\'' +
                ", headers=" + headers +
                ", body='" + body + '\'' +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy