public class OAuthMessage extends Object
The parameters in this class are not percent-encoded. Methods like OAuthClient.invoke and OAuthResponseMessage.completeParameters are responsible for percent-encoding parameters before transmission and decoding them after reception.
| Modifier and Type | Field and Description |
|---|---|
static String |
AUTH_SCHEME |
static String |
DELETE |
static String |
GET |
String |
method |
static String |
POST |
static String |
PUT |
String |
URL |
| Constructor and Description |
|---|
OAuthMessage(String method,
String URL,
Collection<? extends Map.Entry> parameters) |
OAuthMessage(String method,
String URL,
Collection<? extends Map.Entry> parameters,
InputStream bodyAsStream) |
| Modifier and Type | Method and Description |
|---|---|
void |
addParameter(Map.Entry<String,String> parameter) |
void |
addParameter(String key,
String value) |
void |
addParameters(Collection<? extends Map.Entry<String,String>> parameters) |
void |
addRequiredParameters(OAuthAccessor accessor)
Add some of the parameters needed to request access to a protected
resource, if they aren't already in the message.
|
protected void |
completeParameters()
Finish adding parameters; for example read an HTTP response body and
parse parameters from it.
|
static List<OAuth.Parameter> |
decodeAuthorization(String authorization)
Parse the parameters from an OAuth Authorization or WWW-Authenticate
header.
|
protected void |
dump(Map<String,Object> into) |
String |
getAuthorizationHeader(String realm)
Construct a WWW-Authenticate or Authentication header value, containing
the given realm plus all the parameters whose names begin with "oauth_".
|
InputStream |
getBodyAsStream()
Get a stream from which to read the body of the HTTP request or response.
|
String |
getBodyEncoding()
The character encoding of the body of this message.
|
String |
getBodyType()
The MIME type of the body of this message.
|
String |
getConsumerKey() |
Map<String,Object> |
getDump()
Construct a verbose description of this message and its origins.
|
String |
getHeader(String name)
The value of the last HTTP header with the given name.
|
List<Map.Entry<String,String>> |
getHeaders()
All HTTP headers.
|
String |
getParameter(String name) |
protected Map<String,String> |
getParameterMap() |
List<Map.Entry<String,String>> |
getParameters() |
String |
getSignature() |
String |
getSignatureMethod() |
String |
getToken() |
static String |
readAll(InputStream from,
String encoding)
Read all the data from the given stream, and close it.
|
String |
readBodyAsString()
Read the body of the HTTP request or response and convert it to a String.
|
void |
requireParameters(String... names)
Verify that the required parameter names are contained in the actual
collection.
|
void |
sign(OAuthAccessor accessor)
Add a signature to the message.
|
HttpMessage |
toHttpRequest(OAuthClient.ParameterStyle style)
Deprecated.
use HttpMessage.newRequest
|
String |
toString() |
void |
validateMessage(OAuthAccessor accessor,
OAuthValidator validator)
Check that the message is valid.
|
public String method
public String URL
public static final String AUTH_SCHEME
public static final String GET
public static final String POST
public static final String PUT
public static final String DELETE
public OAuthMessage(String method, String URL, Collection<? extends Map.Entry> parameters)
public OAuthMessage(String method, String URL, Collection<? extends Map.Entry> parameters, InputStream bodyAsStream)
protected void completeParameters()
throws IOException
IOExceptionpublic List<Map.Entry<String,String>> getParameters() throws IOException
IOExceptionpublic void addParameters(Collection<? extends Map.Entry<String,String>> parameters)
public String getParameter(String name) throws IOException
IOExceptionpublic String getConsumerKey() throws IOException
IOExceptionpublic String getToken() throws IOException
IOExceptionpublic String getSignatureMethod() throws IOException
IOExceptionpublic String getSignature() throws IOException
IOExceptionprotected Map<String,String> getParameterMap() throws IOException
IOExceptionpublic String getBodyType()
public String getBodyEncoding()
public final String getHeader(String name)
public final List<Map.Entry<String,String>> getHeaders()
public final String readBodyAsString() throws IOException
IOExceptionpublic InputStream getBodyAsStream() throws IOException
IOExceptionpublic Map<String,Object> getDump() throws IOException
IOExceptionprotected void dump(Map<String,Object> into) throws IOException
IOExceptionpublic void requireParameters(String... names) throws OAuthProblemException, IOException
OAuthProblemException - one or more parameters are absent.IOExceptionpublic void addRequiredParameters(OAuthAccessor accessor) throws OAuthException, IOException, URISyntaxException
public void sign(OAuthAccessor accessor) throws IOException, OAuthException, URISyntaxException
public HttpMessage toHttpRequest(OAuthClient.ParameterStyle style) throws IOException
style - where to put the OAuth parameters, within the HTTP requestIOExceptionpublic void validateMessage(OAuthAccessor accessor, OAuthValidator validator) throws OAuthException, IOException, URISyntaxException
IOExceptionURISyntaxExceptionOAuthProblemException - the message is invalidOAuthExceptionpublic String getAuthorizationHeader(String realm) throws IOException
IOExceptionpublic static String readAll(InputStream from, String encoding) throws IOException
IOExceptionpublic static List<OAuth.Parameter> decodeAuthorization(String authorization)
Copyright 2015- Charles R. Severance and licensed CC-BY Attribution 4.0