org.jose4j.http.Response Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jose4j Show documentation
Show all versions of jose4j Show documentation
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..
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 + '\'' +
'}';
}
}