当前位置: 首页>>代码示例>>Java>>正文


Java HttpParameters.put方法代码示例

本文整理汇总了Java中oauth.signpost.http.HttpParameters.put方法的典型用法代码示例。如果您正苦于以下问题:Java HttpParameters.put方法的具体用法?Java HttpParameters.put怎么用?Java HttpParameters.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth.signpost.http.HttpParameters的用法示例。


在下文中一共展示了HttpParameters.put方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:LtiOauthSigner.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:IMSPOXRequest.java

示例3: 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";
        }
    }
}
 
开发者ID:toopher,项目名称:toopher-pingfederate,代码行数:17,代码来源:ToopherIframe.java

示例4: 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);
}
 
开发者ID:BellaDati,项目名称:belladati-sdk-java,代码行数:19,代码来源:BellaDatiConnectionImpl.java

示例5: 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;
}
 
开发者ID:IMSGlobal,项目名称:basiclti-util-java,代码行数:29,代码来源:IMSPOXRequest.java

示例6: 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;
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:30,代码来源:AuthorizationHeaderSigningStrategy.java

示例7: 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);
}
 
开发者ID:CollapsedDom,项目名称:Stud.IP-Client,代码行数:68,代码来源:OAuthConnector.java


注:本文中的oauth.signpost.http.HttpParameters.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。