|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.nimbusds.oauth2.sdk.http.HTTPRequest
@ThreadSafe public final class HTTPRequest
HTTP request with support for the parameters required to construct an
OAuth 2.0 request message
. This
class is thread-safe.
Supported HTTP methods:
Supported request headers:
Nested Class Summary | |
---|---|
static class |
HTTPRequest.Method
Enumeration of the HTTP methods used in OAuth 2.0 requests. |
Constructor Summary | |
---|---|
HTTPRequest(HTTPRequest.Method method,
URL url)
Creates a new minimally specified HTTP request. |
|
HTTPRequest(javax.servlet.http.HttpServletRequest sr)
Creates a new HTTP request from the specified HTTP servlet request. |
Method Summary | |
---|---|
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 |
ensureMethod(HTTPRequest.Method expectedMethod)
Ensures this HTTP request has the specified method. |
String |
getAuthorization()
Gets the Authorization header value. |
javax.mail.internet.ContentType |
getContentType()
Gets the Content-Type header value. |
HTTPRequest.Method |
getMethod()
Gets the request method. |
String |
getQuery()
Gets the raw (undecoded) query string if the request is HTTP GET or the entity body if the request is HTTP POST. |
net.minidev.json.JSONObject |
getQueryAsJSONObject()
Gets the request query or entity body as a JSON Object. |
Map<String,String> |
getQueryParameters()
Gets the request query as a parameter map. |
URL |
getURL()
Gets the request URL. |
HTTPResponse |
send()
Sends this HTTP request to the request URL and retrieves the resulting HTTP response. |
void |
setAuthorization(String authz)
Sets the Authorization header value. |
void |
setContentType(javax.mail.internet.ContentType ct)
Sets the Content-Type header value. |
void |
setContentType(String ct)
Sets the Content-Type header value. |
void |
setQuery(String query)
Sets the raw (undecoded) query string if the request is HTTP GET or the entity body if the request is HTTP POST. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HTTPRequest(HTTPRequest.Method method, URL url)
method
- The HTTP request method. Must not be null
.url
- The HTTP request URL. Must not be null
.public HTTPRequest(javax.servlet.http.HttpServletRequest sr) throws IOException
sr
- The servlet request. Must not be null
.
IllegalArgumentException
- The the servlet request method is
not GET or POST, or the content type
header value couldn't be parsed.
IOException
- For a POST body that couldn't be
read due to an I/O exception.Method Detail |
---|
public HTTPRequest.Method getMethod()
public URL getURL()
public void ensureMethod(HTTPRequest.Method expectedMethod) throws ParseException
expectedMethod
- The expected method. Must not be null
.
ParseException
- If the method doesn't match the expected.public String getAuthorization()
Authorization
header value.
Authorization
header value, null
if not
specified.public void setAuthorization(String authz)
Authorization
header value.
authz
- The Authorization
header value, null
if
not specified.public String getQuery()
Note that the '?' character preceding the query string in GET requests is not included in the returned string.
Example query string (line breaks for clarity):
response_type=code &client_id=s6BhdRkqt3 &state=xyz &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
null
if not specified.public void setQuery(String query)
Note that the '?' character preceding the query string in GET requests must not be included.
Example query string (line breaks for clarity):
response_type=code &client_id=s6BhdRkqt3 &state=xyz &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
query
- For HTTP GET requests the URL query string, for HTTP
POST requests the body. null
if not specified.public Map<String,String> getQueryParameters()
application/x-www-form-urlencoded
.
public net.minidev.json.JSONObject getQueryAsJSONObject() throws ParseException
ParseException
- If the Content-Type header isn't
application/json
, the request query
or entity body is null
, empty or
couldn't be parsed to a valid JSON object.public HTTPResponse send() throws IOException
IOException
- If the HTTP request couldn't be made, due to a
network or other error.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 |