本文整理汇总了Java中net.oauth.OAuth.Parameter方法的典型用法代码示例。如果您正苦于以下问题:Java OAuth.Parameter方法的具体用法?Java OAuth.Parameter怎么用?Java OAuth.Parameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.oauth.OAuth
的用法示例。
在下文中一共展示了OAuth.Parameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParameters
import net.oauth.OAuth; //导入方法依赖的package包/类
public static List<OAuth.Parameter> getParameters(HttpServletRequest request) {
List<OAuth.Parameter> list = new ArrayList<OAuth.Parameter>();
for (Enumeration<String> headers = request.getHeaders("Authorization"); headers != null
&& headers.hasMoreElements();) {
String header = headers.nextElement();
for (OAuth.Parameter parameter : OAuthMessage
.decodeAuthorization(header)) {
if (!"realm".equalsIgnoreCase(parameter.getKey())) {
list.add(parameter);
}
}
}
for (Object e : request.getParameterMap().entrySet()) {
Map.Entry<String, String[]> entry = (Map.Entry<String, String[]>) e;
String name = entry.getKey();
for (String value : entry.getValue()) {
list.add(new OAuth.Parameter(name, value));
}
}
return list;
}
示例2: getParameters
import net.oauth.OAuth; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static List<OAuth.Parameter> getParameters(HttpServletRequest request) {
List<OAuth.Parameter> list = new ArrayList<OAuth.Parameter>();
for (Enumeration<String> headers = request.getHeaders("Authorization"); headers != null
&& headers.hasMoreElements();) {
String header = headers.nextElement();
for (OAuth.Parameter parameter : OAuthMessage
.decodeAuthorization(header)) {
if (!"realm".equalsIgnoreCase(parameter.getKey())) {
list.add(parameter);
}
}
}
for (Object e : request.getParameterMap().entrySet()) {
Map.Entry<String, String[]> entry = (Map.Entry<String, String[]>) e;
String name = entry.getKey();
for (String value : entry.getValue()) {
list.add(new OAuth.Parameter(name, value));
}
}
return list;
}
示例3: doGet
import net.oauth.OAuth; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
OAuthConsumer consumer = null;
try {
consumer = CookieConsumer.getConsumer(NAME, getServletContext());
OAuthAccessor accessor = CookieConsumer.getAccessor(request,
response, consumer);
List<OAuth.Parameter> parameters = HttpRequestMessage.getParameters(request);
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println(NAME + " said:");
// Try it twice:
out.println(echo(accessor, parameters));
out.println(echo(accessor, parameters));
} catch (Exception e) {
CookieConsumer.handleException(e, request, response, consumer);
}
}
示例4: doGet
import net.oauth.OAuth; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
OAuthConsumer consumer = null;
try {
consumer = CookieConsumer.getConsumer(NAME, getServletContext());
OAuthAccessor accessor = CookieConsumer.getAccessor(request,
response, consumer);
Collection<OAuth.Parameter> parameters = HttpRequestMessage.getParameters(request);
if (!OAuth.newMap(parameters).containsKey("echo")) {
parameters.add(new OAuth.Parameter("echo", "Hello."));
}
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println("Sample Provider said:");
// Try it twice:
out.println(invoke(accessor, parameters));
out.println(invoke(accessor, parameters));
} catch (Exception e) {
CookieConsumer.handleException(e, request, response, consumer);
}
}
示例5: prepareRequestMessage
import net.oauth.OAuth; //导入方法依赖的package包/类
private static OAuthMessage prepareRequestMessage(OAuthConsumer consumer,
String httpMethod,
URL url,
String signatureMethod) {
OAuthMessage message = new OAuthMessage(httpMethod,
url.toString(),
new ArrayList<OAuth.Parameter>());
message.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, signatureMethod);
message.addParameter(OAuth.OAUTH_VERSION, OAuth.VERSION_1_0);
message.addParameter(OAuth.OAUTH_CONSUMER_KEY, consumer.consumerKey );
long currentTime = System.currentTimeMillis() / 1000l;
message.addParameter(OAuth.OAUTH_TIMESTAMP,
Long.toString(currentTime, 10));
byte[] nonce = new byte[8];
random.nextBytes(nonce);
BigInteger nonceInt = new BigInteger(1, nonce);
message.addParameter(OAuth.OAUTH_NONCE,
nonceInt.toString(10));
return message;
}
示例6: getAuthorizationURL
import net.oauth.OAuth; //导入方法依赖的package包/类
private String getAuthorizationURL(String consumerKey, Token requestToken) throws Exception {
List<OAuth.Parameter> parameters = new ArrayList<OAuth.Parameter>();
//parameters.add(new OAuth.Parameter(OAuth.OAUTH_CONSUMER_KEY, consumerKey));
parameters.add(new OAuth.Parameter(OAuth.OAUTH_TOKEN, requestToken.getToken()));
return OAuth.addParameters(TokenAuthorizationURL, parameters);
}
示例7: OAuthResponseMessage
import net.oauth.OAuth; //导入方法依赖的package包/类
OAuthResponseMessage(HttpResponseMessage http) throws IOException
{
super(http.method, http.url.toExternalForm(), null);
this.http = http;
getHeaders().addAll(http.headers);
for (Map.Entry<String, String> header : http.headers) {
if ("WWW-Authenticate".equalsIgnoreCase(header.getKey())) {
for (OAuth.Parameter parameter : decodeAuthorization(header.getValue())) {
if (!"realm".equalsIgnoreCase(parameter.getKey())) {
addParameter(parameter);
}
}
}
}
}
示例8: OAuthResponseMessage
import net.oauth.OAuth; //导入方法依赖的package包/类
OAuthResponseMessage(HttpResponseMessage http) throws IOException {
super(http.method, http.url.toExternalForm(), null);
this.http = http;
getHeaders().addAll(http.headers);
for (Map.Entry<String, String> header : http.headers) {
if ("WWW-Authenticate".equalsIgnoreCase(header.getKey())) {
for (OAuth.Parameter parameter : decodeAuthorization(header
.getValue())) {
if (!"realm".equalsIgnoreCase(parameter.getKey())) {
addParameter(parameter);
}
}
}
}
}
示例9: getAccessToken
import net.oauth.OAuth; //导入方法依赖的package包/类
/**
* Get a fresh access token from the service provider.
* @throws IOException
* @throws URISyntaxException
*
* @throws RedirectException
* to obtain authorization
*/
private static void getAccessToken(HttpServletRequest request,
CookieMap cookies, OAuthAccessor accessor)
throws OAuthException, IOException, URISyntaxException
{
final String consumerName = (String) accessor.consumer.getProperty("name");
final String callbackURL = getCallbackURL(request, consumerName);
List<OAuth.Parameter> parameters = OAuth.newList(OAuth.OAUTH_CALLBACK, callbackURL);
// Google needs to know what you intend to do with the access token:
Object scope = accessor.consumer.getProperty("request.scope");
if (scope != null) {
parameters.add(new OAuth.Parameter("scope", scope.toString()));
}
OAuthMessage response = CLIENT.getRequestTokenResponse(accessor, null, parameters);
cookies.put(consumerName + ".requestToken", accessor.requestToken);
cookies.put(consumerName + ".tokenSecret", accessor.tokenSecret);
String authorizationURL = accessor.consumer.serviceProvider.userAuthorizationURL;
if (authorizationURL.startsWith("/")) {
authorizationURL = (new URL(new URL(request.getRequestURL()
.toString()), request.getContextPath() + authorizationURL))
.toString();
}
authorizationURL = OAuth.addParameters(authorizationURL //
, OAuth.OAUTH_TOKEN, accessor.requestToken);
if (response.getParameter(OAuth.OAUTH_CALLBACK_CONFIRMED) == null) {
authorizationURL = OAuth.addParameters(authorizationURL //
, OAuth.OAUTH_CALLBACK, callbackURL);
}
throw new RedirectException(authorizationURL);
}
示例10: doGet
import net.oauth.OAuth; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
OAuthConsumer consumer = null;
try {
consumer = CookieConsumer.getConsumer(NAME, getServletContext());
OAuthAccessor accessor = CookieConsumer.getAccessor(request, response, consumer);
List<OAuth.Parameter> parameters = HttpRequestMessage.getParameters(request);
response.setContentType("text/plain");
final String serviceURL = "http://oauth-sandbox.mediamatic.nl/services/rest/";
final String objectId = "117";
// Store some data into the object:
CookieConsumer.CLIENT.invoke(accessor //
, OAuthMessage.POST, serviceURL //
, OAuth.newList("method", "anymeta.predicates.set" //
, "id", objectId //
, "field", "text.body" //
, "value", OAuth.formEncode(parameters) //
));
// Read the data out again:
OAuthMessage result = CookieConsumer.CLIENT.invoke(accessor //
, OAuthMessage.GET, serviceURL //
, OAuth.newList("method", "anymeta.predicates.get" //
, "id", objectId //
, "field", "text.body" //
));
response.getWriter().println(result.readBodyAsString());
} catch (Exception e) {
CookieConsumer.handleException(e, request, response, consumer);
}
}
示例11: getQueryParam
import net.oauth.OAuth; //导入方法依赖的package包/类
public String getQueryParam(String name) {
for (OAuth.Parameter p : getParsedQuery()) {
if (p.getKey().equals(name)) {
return p.getValue();
}
}
return null;
}
示例12: echo
import net.oauth.OAuth; //导入方法依赖的package包/类
private static String echo(OAuthAccessor accessor, List<OAuth.Parameter> parameters)
throws OAuthException, IOException, URISyntaxException {
OAuthMessage result = CookieConsumer.CLIENT.invoke(accessor,
"http://term.ie/oauth/example/echo_api.php", parameters);
String responseBody = result.readBodyAsString();
return responseBody;
}
示例13: testNormalizeParameters
import net.oauth.OAuth; //导入方法依赖的package包/类
public void testNormalizeParameters() throws Exception {
for (int c = 0; c < NORMALS.length;) {
String[] normal = NORMALS[c++];
int n = 0;
String label = normal[n++];
List<OAuth.Parameter> parameters = OAuth.decodeForm(normal[n++]);
String expected = normal[n++];
String actual = OAuthSignatureMethod
.normalizeParameters(parameters);
assertEquals(label, expected, actual);
}
}
示例14: MessageWithBody
import net.oauth.OAuth; //导入方法依赖的package包/类
public MessageWithBody(String method, String URL,
Collection<OAuth.Parameter> parameters,
String contentType, byte[] body) {
super(method, URL, parameters);
this.body = body;
Collection<Map.Entry<String, String>> headers = getHeaders();
headers.add(new OAuth.Parameter(HttpMessage.ACCEPT_ENCODING, HttpMessageDecoder.ACCEPTED));
if (body != null) {
headers.add(new OAuth.Parameter(HttpMessage.CONTENT_LENGTH, String.valueOf(body.length)));
}
if (contentType != null) {
headers.add(new OAuth.Parameter(HttpMessage.CONTENT_TYPE, contentType));
}
}
示例15: sendResponse
import net.oauth.OAuth; //导入方法依赖的package包/类
private void sendResponse(ContextResource contextResource, List<OAuth.Parameter> parameters) throws IOException {
contextResource.setMediaType(MediaType.TEXT_PLAIN);
contextResource.append(OAuth.formEncode(parameters));
}