|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.nimbusds.oauth2.sdk.http.HTTPResponse
@ThreadSafe public final class HTTPResponse
HTTP response with support for the parameters required to construct an
OAuth 2.0 response message
. This
class is thread-safe.
Provided HTTP status code constants:
Supported response headers:
Field Summary | |
---|---|
static int |
SC_BAD_REQUEST
HTTP status code (400) indicating a bad request. |
static int |
SC_FORBIDDEN
HTTP status code (403) indicating that access to the resource was forbidden. |
static int |
SC_FOUND
HTTP status code (302) indicating that the resource resides temporarily under a different URI (redirect). |
static int |
SC_OK
HTTP status code (200) indicating the request succeeded. |
static int |
SC_UNAUTHORIZED
HTTP status code (401) indicating that the request requires HTTP authentication. |
Constructor Summary | |
---|---|
HTTPResponse(int statusCode)
Creates a new minimal HTTP response with the specified status code. |
Method Summary | |
---|---|
void |
applyTo(javax.servlet.http.HttpServletResponse sr)
Applies the status code, headers and content of this HTTP response object to the specified HTTP servlet response. |
void |
ensureContentType()
Ensures this HTTP message has a Content-Type header value. |
void |
ensureContentType(javax.mail.internet.ContentType contentType)
Ensures this HTTP message has the specified Content-Type
header value. |
void |
ensureStatusCode(int statusCode)
Ensures this HTTP response has the specified status code . |
void |
ensureStatusCodeNotOK()
Ensures this HTTP response does not have a 200 OK
status code. |
String |
getCacheControl()
Gets the Cache-Control header value. |
String |
getContent()
Gets the raw response content. |
net.minidev.json.JSONObject |
getContentAsJSONObject()
Gets the response content as a JSON object. |
com.nimbusds.jwt.JWT |
getContentAsJWT()
Gets the response content as a JSON Web Token (JWT). |
javax.mail.internet.ContentType |
getContentType()
Gets the Content-Type header value. |
URL |
getLocation()
Gets the Location header value (for redirects). |
String |
getPragma()
Gets the Pragma header value. |
int |
getStatusCode()
Gets the HTTP status code. |
String |
getWWWAuthenticate()
Gets the WWW-Authenticate header value. |
void |
setCacheControl(String cacheControl)
Sets the Cache-Control header value. |
void |
setContent(String content)
Sets the raw response content. |
void |
setContentType(javax.mail.internet.ContentType ct)
Sets the Content-Type header value. |
void |
setContentType(String ct)
Sets the Content-Type header value. |
void |
setLocation(URL location)
Sets the Location header value (for redirects). |
void |
setPragma(String pragma)
Sets the Pragma header value. |
void |
setWWWAuthenticate(String wwwAuthenticate)
Sets the WWW-Authenticate header value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SC_OK
public static final int SC_FOUND
public static final int SC_BAD_REQUEST
public static final int SC_UNAUTHORIZED
public static final int SC_FORBIDDEN
Constructor Detail |
---|
public HTTPResponse(int statusCode)
statusCode
- The HTTP status code.Method Detail |
---|
public int getStatusCode()
public void ensureStatusCode(int statusCode) throws ParseException
status code
.
statusCode
- The expected status code.
ParseException
- If the status code of this HTTP response
doesn't match the expected.public void ensureStatusCodeNotOK() throws ParseException
200 OK
status code.
ParseException
- If the status code of this HTTP response is
200 OK.public URL getLocation()
Location
header value (for redirects).
null
if not specified.public void setLocation(URL location)
Location
header value (for redirects).
location
- The header value, null
if not specified.public String getCacheControl()
Cache-Control
header value.
null
if not specified.public void setCacheControl(String cacheControl)
Cache-Control
header value.
cacheControl
- The header value, null
if not specified.public String getPragma()
Pragma
header value.
null
if not specified.public void setPragma(String pragma)
Pragma
header value.
pragma
- The header value, null
if not specified.public String getWWWAuthenticate()
WWW-Authenticate
header value.
null
if not specified.public void setWWWAuthenticate(String wwwAuthenticate)
WWW-Authenticate
header value.
wwwAuthenticate
- The header value, null
if not
specified.public String getContent()
null
if none.public net.minidev.json.JSONObject getContentAsJSONObject() throws ParseException
ParseException
- If the Content-Type header isn't
application/json
, the response content
is null
, empty or couldn't be parsed
to a valid JSON object.public com.nimbusds.jwt.JWT getContentAsJWT() throws ParseException
ParseException
- If the Content-Type header isn't
application/jwt
, the response content
is null
, empty or couldn't be parsed
to a valid JSON Web Token (JWT).public void setContent(String content)
content
- The raw response content, null
if none.public void applyTo(javax.servlet.http.HttpServletResponse sr) throws IOException
sr
- The HTTP servlet response to have the properties of this
HTTP request applied to. Must not be null
.
IOException
- If the response content couldn't be written.public javax.mail.internet.ContentType getContentType()
Content-Type
header value.
Content-Type
header value, null
if not
specified.public void setContentType(javax.mail.internet.ContentType ct)
Content-Type
header value.
ct
- The Content-Type
header value, null
if not
specified.public void setContentType(String ct) throws ParseException
Content-Type
header value.
ct
- The Content-Type
header value, null
if not
specified.
ParseException
- If the header value couldn't be parsed to a
valid content type.public void ensureContentType() throws ParseException
Content-Type
header value.
ParseException
- If the Content-Type
header is
missing.public void ensureContentType(javax.mail.internet.ContentType contentType) throws ParseException
Content-Type
header value. This method compares only the primary type and
subtype; any content type parameters, such as charset
, are
ignored.
contentType
- The expected content type. Must not be
null
.
ParseException
- If the Content-Type
header is missing
or its primary and subtype don't match.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |