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


Java OAuthMessage.POST属性代码示例

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


在下文中一共展示了OAuthMessage.POST属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLaunchParameters

private OAuthMessage createLaunchParameters(String consumerKey, String secret, String url, String bodyHash)
{
	final String nonce = UUID.randomUUID().toString();
	final String timestamp = Long.toString(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));

	final OAuthMessage message = new OAuthMessage(OAuthMessage.POST, url, null);
	message.addParameter(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
	message.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
	message.addParameter(OAuth.OAUTH_NONCE, nonce);
	message.addParameter(OAuth.OAUTH_TIMESTAMP, timestamp);
	message.addParameter("oauth_body_hash", bodyHash);

	final OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, secret, null);
	final OAuthAccessor accessor = new OAuthAccessor(consumer);
	try
	{
		message.sign(accessor);
		return message;
	}
	catch( Exception e )
	{
		throw new RuntimeException(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:24,代码来源:LtiServiceImpl.java

示例2: testAccess

public void testAccess() throws Exception {
    final String echo = "http://localhost:" + port + "/Echo";
    final List<OAuth.Parameter> parameters = OAuth.newList("n", "v");
    final String contentType = "text/fred; charset=" + OAuth.ENCODING;
    final byte[] content = "1234".getBytes(OAuth.ENCODING);
    for (OAuthClient client : clients) {
        String id = client.getHttpClient().toString();
        OAuthMessage request = new OAuthMessage(OAuthMessage.POST, echo, parameters, new ByteArrayInputStream(content));
        request.getHeaders().add(new OAuth.Parameter("Content-Type", contentType));
        OAuthMessage response = client.access(request, ParameterStyle.QUERY_STRING);
        String expectedBody = (client.getHttpClient() instanceof HttpClient4) //
                ? "POST\nn=v\nnull\n1234" // no Content-Length
                : "POST\nn=v\n4\n1234";
        String body = response.readBodyAsString();
        assertEquals(id, contentType, response.getHeader(HttpMessage.CONTENT_TYPE));
        assertEquals(id, expectedBody, body);
    }
}
 
开发者ID:groovenauts,项目名称:jmeter_oauth_plugin,代码行数:18,代码来源:OAuthClientTest.java

示例3: getOauthSignatureParams

@Override
public List<Entry<String, String>> getOauthSignatureParams(String consumerKey, String secret, String urlStr,
	Map<String, String[]> formParams)
{
	String nonce = UUID.randomUUID().toString();
	String timestamp = Long.toString(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
	// OAuth likes the Map.Entry interface, so copy into a Collection of a
	// local implementation thereof. Note that this is a flat list.
	List<Parameter> postParams = null;

	if( !Check.isEmpty(formParams) )
	{
		postParams = new ArrayList<Parameter>(formParams.size());
		for( Entry<String, String[]> entry : formParams.entrySet() )
		{
			String key = entry.getKey();
			String[] formParamEntry = entry.getValue();
			// cater for multiple values for the same key
			if( formParamEntry.length > 0 )
			{
				for( int i = 0; i < formParamEntry.length; ++i )
				{
					Parameter erp = new Parameter(entry.getKey(), formParamEntry[i]);
					postParams.add(erp);
				}
			}
			else
			{
				// key with no value
				postParams.add(new Parameter(key, null));
			}
		}
	}

	OAuthMessage message = new OAuthMessage(OAuthMessage.POST, urlStr, postParams);
	// Parameters needed for a signature
	message.addParameter(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
	message.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
	message.addParameter(OAuth.OAUTH_NONCE, nonce);
	message.addParameter(OAuth.OAUTH_TIMESTAMP, timestamp);
	message.addParameter(OAuth.OAUTH_VERSION, OAuth.VERSION_1_0);
	message.addParameter(OAuth.OAUTH_CALLBACK, "about:blank");

	// Sign the request
	OAuthConsumer consumer = new OAuthConsumer("about:blank", consumerKey, secret, null);
	OAuthAccessor accessor = new OAuthAccessor(consumer);
	try
	{
		message.sign(accessor);
		// send oauth parameters back including signature
		return message.getParameters();
	}
	catch( Exception e )
	{
		throw new RuntimeException(e);
	}

}
 
开发者ID:equella,项目名称:Equella,代码行数:58,代码来源:ExternalToolsServiceImpl.java


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