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


Java OAuth.FORM_ENCODED属性代码示例

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


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

示例1: sendPostData

private String sendPostData(HttpMethod method) throws IOException {

	String form;
       
	if (useAuthHeader) {    
	    form = OAuth.formEncode(nonOAuthParams);
       } else {
       	form = OAuth.formEncode(message.getParameters());
       }

       method.addRequestHeader(HEADER_CONTENT_TYPE, OAuth.FORM_ENCODED);
       method.addRequestHeader(HEADER_CONTENT_LENGTH, form.length() + ""); //$NON-NLS-1$
      
       if (method instanceof PostMethod || method instanceof PutMethod) {

       	StringRequestEntity requestEntity = new StringRequestEntity(
           		form, OAuth.FORM_ENCODED, OAuth.ENCODING);
           
           ((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
       } else {
       	log.error("Logic error, method must be POST or PUT to send body"); //$NON-NLS-1$
       }
       
       return form;     
}
 
开发者ID:aoprisan,项目名称:net.oauth,代码行数:25,代码来源:OAuthSampler.java

示例2: testConsumerFailBodyHashSigningWithFormEncoding

@Test
public void testConsumerFailBodyHashSigningWithFormEncoding() throws Exception {
  replay();
  FakeOAuthRequest bodyHashPost =
      new FakeOAuthRequest("POST", TEST_URL, "a=b&c=d&oauth_body_hash=hash",
      OAuth.FORM_ENCODED);
  FakeHttpServletRequest request = bodyHashPost
      .sign(null, FakeOAuthRequest.OAuthParamLocation.URI_QUERY,
          FakeOAuthRequest.BodySigning.NONE);
  try {
    reqHandler.getSecurityTokenFromRequest(request);
    fail("Cant have body signing with form-encoded post bodies");
  } catch (AuthenticationHandler.InvalidAuthenticationException iae) {
    // Pass
  }
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:16,代码来源:OAuthAuthenticationHanderTest.java

示例3: setUp

@Override
protected void setUp() throws Exception {
  reqHandler = new OAuthAuthenticationHandler(mockStore, true);
  formEncodedPost = new FakeOAuthRequest("POST", TEST_URL, "a=b&c=d",
      OAuth.FORM_ENCODED);
  nonFormEncodedPost = new FakeOAuthRequest("POST", TEST_URL, "BODY",
      "text/plain");
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:8,代码来源:OAuthAuthenticationHanderTest.java

示例4: testInvokeMessage

public void testInvokeMessage() throws Exception {
    final String echo = "http://localhost:" + port + "/Echo";
    final String data = new String(new char[] { 0, 1, ' ', 'a', 127, 128,
            0xFF, 0x3000, 0x4E00 });
    final byte[] utf8 = data.getBytes("UTF-8");
    List<OAuth.Parameter> parameters = OAuth.newList("x", "y",
            "oauth_token", "t");
    String parametersForm = "oauth_token=t&x=y";
    final Object[][] messages = new Object[][] {
            { new OAuthMessage("GET", echo, parameters),
                    "GET\n" + parametersForm + "\n" + "null\n", null },
            {
                    new OAuthMessage("POST", echo, parameters),
                    "POST\n" + parametersForm + "\n"
                            + parametersForm.length() + "\n",
                    OAuth.FORM_ENCODED },
            {
                    new MessageWithBody("PUT", echo, parameters,
                            "text/OAuthClientTest; charset=\"UTF-8\"", utf8),
                    "PUT\n" + parametersForm + "\n"
                            + utf8.length + "\n" + data,
                    "text/OAuthClientTest; charset=UTF-8" },
            {
                    new MessageWithBody("PUT", echo, parameters,
                            "application/octet-stream", utf8),
                    "PUT\n" + parametersForm + "\n"
                            + utf8.length + "\n"
                            + new String(utf8, "ISO-8859-1"),
                    "application/octet-stream" },
            { new OAuthMessage("DELETE", echo, parameters),
                    "DELETE\n" + parametersForm + "\n" + "null\n", null } };
    final ParameterStyle[] styles = new ParameterStyle[] {
            ParameterStyle.BODY, ParameterStyle.AUTHORIZATION_HEADER };
    final long startTime = System.nanoTime();
    for (OAuthClient client : clients) {
        for (Object[] testCase : messages) {
            for (ParameterStyle style : styles) {
                OAuthMessage request = (OAuthMessage) testCase[0];
                final String id = client + " " + request.method + " " + style;
                OAuthMessage response = null;
                // System.out.println(id + " ...");
                try {
                    response = client.invoke(request, style);
                } catch (Exception e) {
                    AssertionError failure = new AssertionError(id);
                    failure.initCause(e);
                    throw failure;
                }
                // System.out.println(response.getDump()
                // .get(OAuthMessage.HTTP_REQUEST));
                String expectedBody = (String) testCase[1];
                if ("POST".equalsIgnoreCase(request.method)
                        && style == ParameterStyle.AUTHORIZATION_HEADER) {
                    // Only the non-oauth parameters went in the body.
                    expectedBody = expectedBody.replace("\n" + parametersForm.length()
                            + "\n", "\n3\n");
                }
                String body = response.readBodyAsString();
                assertEquals(id, expectedBody, body);
                assertEquals(id, testCase[2], response.getHeader(HttpMessage.CONTENT_TYPE));
            }
        }
    }
    final long endTime = System.nanoTime();
    final float elapsedSec = ((float) (endTime - startTime)) / 1000000000L;
    if (elapsedSec > 10) {
        fail("elapsed time = " + elapsedSec + " sec");
        // This often means the client isn't re-using TCP connections,
        // and consequently all the Jetty server threads are occupied
        // waiting for data on the wasted connections.
    }
}
 
开发者ID:groovenauts,项目名称:jmeter_oauth_plugin,代码行数:72,代码来源:OAuthClientTest.java


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