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

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

Go to download

The jose.4.j library is a robust and easy to use open source implementation of JSON Web Token (JWT) and the JOSE specification suite (JWS, JWE, and JWK). It is written in Java and relies solely on the JCA APIs for cryptography. Please see https://bitbucket.org/b_c/jose4j/wiki/Home for more info, examples, etc..

There is a newer version: 0.9.6
Show 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