本文整理汇总了Java中oauth.signpost.http.HttpParameters类的典型用法代码示例。如果您正苦于以下问题:Java HttpParameters类的具体用法?Java HttpParameters怎么用?Java HttpParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpParameters类属于oauth.signpost.http包,在下文中一共展示了HttpParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sign
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
@Override
public HttpRequest sign(HttpRequest request, String key, String secret) throws LtiSigningException {
CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
try {
String body = getRequestBody(request);
String bodyHash = new String(Base64.encodeBase64(md.digest(body.getBytes())));
HttpParameters params = new HttpParameters();
params.put("oauth_body_hash", URLEncoder.encode(bodyHash, "UTF-8"));
signer.setAdditionalParameters(params);
signer.sign(request);
} catch (OAuthMessageSignerException|OAuthExpectationFailedException|OAuthCommunicationException|IOException e) {
throw new LtiSigningException("Exception encountered while singing Lti request...", e);
}
return request;
}
示例2: buildReplaceResult
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
public static HttpPost buildReplaceResult(String url, String key, String secret, String sourcedid, String score, String resultData, Boolean isUrl) throws IOException, OAuthException, GeneralSecurityException {
String dataXml = "";
if (resultData != null) {
String format = isUrl ? resultDataUrl : resultDataText;
dataXml = String.format(format, StringEscapeUtils.escapeXml(resultData));
}
//*LAMS* the following line was added by LAMS and also messageIdentifier was added to the line after it
String messageIdentifier = UUID.randomUUID().toString();
String xml = String.format(replaceResultMessage, messageIdentifier, StringEscapeUtils.escapeXml(sourcedid),
StringEscapeUtils.escapeXml(score), dataXml);
HttpParameters parameters = new HttpParameters();
String hash = getBodyHash(xml);
parameters.put("oauth_body_hash", URLEncoder.encode(hash, "UTF-8"));
CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
HttpPost request = new HttpPost(url);
request.setHeader("Content-Type", "application/xml");
request.setEntity(new StringEntity(xml, "UTF-8"));
signer.setAdditionalParameters(parameters);
signer.sign(request);
return request;
}
示例3: sign
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
@Override
public String sign(HttpRequest request, HttpParameters requestParams)
throws OAuthMessageSignerException {
final OAuthRsaSigner signer = new OAuthRsaSigner();
final byte[] privateBytes = Base64.decodeBase64(getConsumerSecret());
final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateBytes);
try {
signer.privateKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
final String signatureBaseString = new SignatureBaseString(request, requestParams).generate();
return signer.computeSignature(signatureBaseString);
} catch (GeneralSecurityException e) {
throw new OAuthMessageSignerException(e);
}
}
示例4: getIpnParamsFromUrl
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
/**
*
* @param url - The URL, no callback
* @return - the map of the parameter, can be empty or not contain key
* @throws IpnRequestException - if the URL is empty or not contain parameters
*/
public static Map<String,String> getIpnParamsFromUrl(String url) throws IpnRequestException{
Map<String,String> map = new HashMap<String,String>();
if(url==null || url.isEmpty())
throw new IpnRequestException("Callback is Empty");
int pos = url.indexOf('?');
if(pos == -1 || pos+1>url.length())
throw new IpnRequestException("Invalid Callback or Parameter absents");
url = url.substring(pos+1);
HttpParameters params = OAuth.decodeForm(url);
if(params==null || params.isEmpty())
throw new IpnRequestException("Invalid Callback or Parameter absents");
if(params.containsKey(AbIpnRequest.PARAM_TARCK_ID))
map.put(AbIpnRequest.PARAM_TARCK_ID, params.getFirst(AbIpnRequest.PARAM_TARCK_ID));
if(params.containsKey(AbIpnRequest.PARAM_MERCHANT_REFERECE))
map.put(AbIpnRequest.PARAM_MERCHANT_REFERECE, params.getFirst(AbIpnRequest.PARAM_MERCHANT_REFERECE));
return map;
}
示例5: sign
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
@Override
public String sign(HttpRequest request, HttpParameters requestParams) throws OAuthMessageSignerException {
byte[] decodedPrivateKey;
try {
decodedPrivateKey = Base64.decode(getConsumerSecret());
String baseString = new SignatureBaseString(request, requestParams).generate();
Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_TYPE);
EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decodedPrivateKey);
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
signature.initSign(privateKey);
signature.update(baseString.getBytes());
byte[] rsasha1 = signature.sign();
return Base64.encode(rsasha1);
} catch (IOException | NoSuchAlgorithmException | InvalidKeyException | InvalidKeySpecException | SignatureException e) {
throw new OAuthMessageSignerException(e);
}
}
示例6: getOAuthUri
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
private static final String getOAuthUri(String uri, List<NameValuePair> params, String key, String secret) {
final OAuthConsumer consumer = new DefaultOAuthConsumer(key, secret);
HttpParameters additionalParameters = new HttpParameters();
additionalParameters.put("oauth_timestamp", String.valueOf(getDate().getTime() / 1000));
consumer.setAdditionalParameters(additionalParameters);
try {
return consumer.sign(uri + "?" + URLEncodedUtils.format(params, "UTF-8"));
} catch (OAuthException e) {
try {
return uri + "web/error.html?message=" + URLEncoder.encode(e.getMessage(), "UTF-8");
} catch (UnsupportedEncodingException f) {
return uri + "web/error.html?message=Unknown%20Error";
}
}
}
示例7: parseRequestTokenResponse
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
/**
* Parses the request_token response from an initial oauth1 initiate request.
*
* @param requestTokenResponse - Response from external data provider
* @return - Map with token and token secret.
* @throws ShimException
*/
public static Map<String, String> parseRequestTokenResponse(
HttpResponse requestTokenResponse) throws ShimException {
String tokenString;
try {
tokenString = IOUtils.toString(requestTokenResponse.getEntity().getContent(), "UTF-8");
} catch (IOException e) {
throw new ShimException("Error reading request token", e);
}
HttpParameters responseParams = OAuth.decodeForm(tokenString);
Map<String, String> token = new HashMap<>();
token.put(
OAuth.OAUTH_TOKEN,
responseParams.getFirst(OAuth.OAUTH_TOKEN));
token.put(
OAuth.OAUTH_TOKEN_SECRET,
responseParams.getFirst(OAuth.OAUTH_TOKEN_SECRET));
return token;
}
示例8: oAuth
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
@Override
public OAuthRequest oAuth(String consumerKey, String consumerSecret, String redirectUrl) throws ConnectionException,
AuthorizationException {
HttpParameters params = new HttpParameters();
if (redirectUrl != null) {
// check if the redirect URL is valid
try {
new URL(redirectUrl);
params.put(OAuth.OAUTH_CALLBACK, OAuth.percentEncode(redirectUrl));
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid redirect URL", e);
}
}
TokenHolder tokenHolder = new TokenHolder(consumerKey, consumerSecret);
client.postToken("oauth/requestToken", tokenHolder, params);
return new OAuthRequestImpl(client, tokenHolder);
}
示例9: sign
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
@Override
public String sign(HttpRequest request, HttpParameters requestParams) throws OAuthMessageSignerException {
final OAuthRsaSigner signer = new OAuthRsaSigner();
final byte[] privateBytes = Base64.decodeBase64(getConsumerSecret());
final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateBytes);
try {
signer.privateKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
final String signatureBaseString = new SignatureBaseString(request, requestParams).generate();
return signer.computeSignature(signatureBaseString);
} catch (GeneralSecurityException e) {
throw new OAuthMessageSignerException(e);
}
}
示例10: buildReplaceResult
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
public static HttpPost buildReplaceResult(String url, String key, String secret, String sourcedid,
String score, String resultData, Boolean isUrl, String messageId) throws IOException, OAuthException, GeneralSecurityException
{
String dataXml = "";
if (resultData != null) {
String format = isUrl ? resultDataUrl : resultDataText;
dataXml = String.format(format, StringEscapeUtils.escapeXml(resultData));
}
String messageIdentifier = StringUtils.isBlank(messageId) ? String.valueOf(new Date().getTime()) : messageId;
String xml = String.format(ReplaceResultMessageTemplate,
StringEscapeUtils.escapeXml(messageIdentifier),
StringEscapeUtils.escapeXml(sourcedid),
StringEscapeUtils.escapeXml(score),
dataXml);
HttpParameters parameters = new HttpParameters();
String hash = getBodyHash(xml);
parameters.put("oauth_body_hash", URLEncoder.encode(hash, "UTF-8"));
CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret);
HttpPost request = new HttpPost(url);
request.setHeader("Content-Type", "application/xml");
request.setEntity(new StringEntity(xml, "UTF-8"));
signer.setAdditionalParameters(parameters);
signer.sign(request);
return request;
}
示例11: generateSig
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
private String generateSig(HttpRequest request, HttpParameters requestParameters) throws Exception {
String keyString = OAuth.percentEncode(getConsumerSecret()) + '&' + OAuth.percentEncode(getTokenSecret());
byte[] keyBytes = keyString.getBytes(OAuth.ENCODING);
SecretKey key = new SecretKeySpec(keyBytes, MAC_NAME);
Mac mac = Mac.getInstance(MAC_NAME);
mac.init(key);
String sbs = new SignatureBaseString(request, requestParameters).generate();
return base64(mac.doFinal(sbs.getBytes(OAuth.ENCODING)));
}
示例12: writeSignature
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
public String writeSignature(String signature, HttpRequest request, HttpParameters requestParameters) {
StringBuilder sb = new StringBuilder();
sb.append("OAuth ");
if (realm != null) {
sb.append("realm=\"" + realm + "\", ");
}
// add all (x_)oauth parameters
HttpParameters oauthParams = requestParameters.getOAuthParameters();
oauthParams.put(OAuth.OAUTH_SIGNATURE, signature, true);
Iterator<String> iter = oauthParams.keySet().iterator();
while (iter.hasNext()) {
String key = iter.next();
sb.append(oauthParams.getAsHeaderElement(key));
if (iter.hasNext()) {
sb.append(", ");
}
}
String header = sb.toString();
OAuth.debugOut("Auth Header", header);
request.setHeader(OAuth.HTTP_AUTHORIZATION_HEADER, header);
return header;
}
示例13: postToken
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
public TokenHolder postToken(String relativeUrl, TokenHolder tokenHolder, HttpParameters oauthParams,
List<? extends NameValuePair> parameters) {
byte[] response = post(relativeUrl, tokenHolder, oauthParams, parameters);
try {
HttpParameters responseParams = OAuth.decodeForm(new ByteArrayInputStream(response));
String token = responseParams.getFirst(OAuth.OAUTH_TOKEN);
String tokenSecret = responseParams.getFirst(OAuth.OAUTH_TOKEN_SECRET);
tokenHolder.setToken(token, tokenSecret);
return tokenHolder;
} catch (IOException e) {
throw new IllegalArgumentException("Failed to load OAuth token from response", e);
}
}
示例14: sign
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
private HttpURLConnection sign(String pattern, Method method, String json) throws OAuthNotAuthorizedException,
OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException {
if (mConsumer.getToken() == null || mConsumer.getTokenSecret() == null || !isAuthorized) {
throw new OAuthNotAuthorizedException();
}
// Connect and send request
HttpURLConnection connection = null;
try {
URL url = new URL(mServer.getApiUrl() + "/" + pattern);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method.toString());
// POST
if (method.equals(Method.POST)) {
logger.warn("Not tested yet!");
// Create an HttpURLConnection and add some headers
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json; charset=utf8");
connection.setDoOutput(true);
// Sign the request
HttpParameters doubleEncodedParams = new HttpParameters();
doubleEncodedParams.put("realm", url.toString());
mConsumer.setAdditionalParameters(doubleEncodedParams);
mConsumer.sign(connection);
// Send the payload to the connection
OutputStreamWriter outputStreamWriter = null;
try {
outputStreamWriter = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
outputStreamWriter.write(json);
} finally {
if (outputStreamWriter != null) {
outputStreamWriter.close();
}
}
// Send the request and read the output
// try {
// System.out.println(
// "Response: " + connection.getResponseCode() + " " +
// connection.getResponseMessage());
// InputStream in = new
// BufferedInputStream(connection.getInputStream());
// String inputStreamString = new Scanner(in,
// "UTF-8").useDelimiter("\\A").next();
// System.out.println(inputStreamString);
// } finally {
// connection.disconnect();
// }
} else {
mConsumer.sign(connection);
connection.connect();
}
} catch (IOException e) {
logger.debug(e);
}
return logger.exit(connection);
}
示例15: setOuathToken
import oauth.signpost.http.HttpParameters; //导入依赖的package包/类
public void setOuathToken(String token, String tokenSecret) {
this.token = token;
this.tokenSecret = tokenSecret;
consumer.setTokenWithSecret(token, tokenSecret);
consumer.setAdditionalParameters(new HttpParameters());
}