@ThreadSafe public class HTTPRequest extends java.lang.Object
OAuth 2.0 request message
.
Supported HTTP methods:
Supported request headers:
Supported timeouts:
Modifier and Type | Class and Description |
---|---|
static class |
HTTPRequest.Method
Enumeration of the HTTP methods used in OAuth 2.0 requests.
|
Constructor and Description |
---|
HTTPRequest(HTTPRequest.Method method,
java.net.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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
java.lang.String |
getAccept()
Gets the
Accept header value. |
java.lang.String |
getAuthorization()
Gets the
Authorization header value. |
int |
getConnectTimeout()
Gets the HTTP connect timeout.
|
javax.mail.internet.ContentType |
getContentType()
Gets the
Content-Type header value. |
HTTPRequest.Method |
getMethod()
Gets the request method.
|
java.lang.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.
|
java.util.Map<java.lang.String,java.lang.String> |
getQueryParameters()
Gets the request query as a parameter map.
|
int |
getReadTimeout()
Gets the HTTP response read timeout.
|
java.net.URL |
getURL()
Gets the request URL.
|
HTTPResponse |
send()
Sends this HTTP request to the request URL and retrieves the
resulting HTTP response.
|
void |
setAccept(java.lang.String accept)
Sets the
Accept header value. |
void |
setAuthorization(java.lang.String authz)
Sets the
Authorization header value. |
void |
setConnectTimeout(int connectTimeout)
Sets the HTTP connect timeout.
|
void |
setContentType(javax.mail.internet.ContentType ct)
Sets the
Content-Type header value. |
void |
setContentType(java.lang.String ct)
Sets the
Content-Type header value. |
void |
setQuery(java.lang.String query)
Sets the raw (undecoded) query string if the request is HTTP GET or
the entity body if the request is HTTP POST.
|
void |
setReadTimeout(int readTimeout)
Sets the HTTP response read timeout.
|
java.net.HttpURLConnection |
toHttpURLConnection()
Returns an established HTTP URL connection for this HTTP request.
|
public HTTPRequest(HTTPRequest.Method method, java.net.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 java.io.IOException
sr
- The servlet request. Must not be null
.java.lang.IllegalArgumentException
- The the servlet request method is
not GET, POST, PUT or DELETE or the
content type header value couldn't
be parsed.java.io.IOException
- For a POST or PUT body that
couldn't be read due to an I/O
exception.public HTTPRequest.Method getMethod()
public java.net.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 java.lang.String getAuthorization()
Authorization
header value.Authorization
header value, null
if not
specified.public void setAuthorization(java.lang.String authz)
Authorization
header value.authz
- The Authorization
header value, null
if
not specified.public java.lang.String getAccept()
Accept
header value.Accept
header value, null
if not
specified.public void setAccept(java.lang.String accept)
Accept
header value.accept
- The Accept
header value, null
if not
specified.public java.lang.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(java.lang.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 java.util.Map<java.lang.String,java.lang.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 int getConnectTimeout()
public void setConnectTimeout(int connectTimeout)
connectTimeout
- The HTTP connect timeout, in milliseconds.
Zero implies no timeout. Must not be negative.public int getReadTimeout()
public void setReadTimeout(int readTimeout)
readTimeout
- The HTTP response read timeout, in milliseconds.
Zero implies no timeout. Must not be negative.public java.net.HttpURLConnection toHttpURLConnection() throws java.io.IOException
java.io.IOException
- If the HTTP request couldn't be made, due to a
network or other error.public HTTPResponse send() throws java.io.IOException
java.io.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(java.lang.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.Copyright © 2014 Connect2id Ltd.. All Rights Reserved.