oauth.signpost.http.HttpRequest.getMethod()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中oauth.signpost.http.HttpRequest.getMethod()方法的一些代码示例,展示了HttpRequest.getMethod()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getMethod()方法的具体详情如下:
包路径:oauth.signpost.http.HttpRequest
类名称:HttpRequest
方法名:getMethod

HttpRequest.getMethod介绍

暂无

代码示例

代码示例来源:origin: mttkay/signpost

@Before
  public void initRequestMocks() {
    MockitoAnnotations.initMocks(this);

    when(httpGetMock.getMethod()).thenReturn("GET");
    when(httpGetMock.getRequestUrl()).thenReturn("http://www.example.com");

    when(httpGetMockWithQueryString.getMethod()).thenReturn("GET");
    when(httpGetMockWithQueryString.getRequestUrl()).thenReturn("http://www.example.com?foo=bar");

    when(httpPostMock.getMethod()).thenReturn("POST");
    when(httpPostMock.getRequestUrl()).thenReturn("http://www.example.com");
  }
}

代码示例来源:origin: mttkay/signpost

@Test
public void shouldReturnCorrectRequestMethod() {
  assertEquals(HTTP_POST_METHOD, request.getMethod());
}

代码示例来源:origin: mttkay/signpost

@Test
public void shouldWorkWithBracketsInParameterName() throws Exception {
  HttpRequest request = mock(HttpRequest.class);
  when(request.getMethod()).thenReturn("GET");
  when(request.getRequestUrl()).thenReturn("http://examplebrackets.com");
  HttpParameters params = new HttpParameters();
  params.put("a[]", "1", true);
  SignatureBaseString sbs = new SignatureBaseString(request, params);
  
  assertEquals("GET&http%3A%2F%2Fexamplebrackets.com%2F&a%255B%255D%3D1", sbs.generate());
}

代码示例来源:origin: mttkay/signpost

/**
 * Builds the signature base string from the data this instance was
 * configured with.
 * 
 * @return the signature base string
 * @throws OAuthMessageSignerException
 */
public String generate() throws OAuthMessageSignerException {
  try {
    String normalizedUrl = normalizeRequestUrl();
    String normalizedParams = normalizeRequestParameters();
    return request.getMethod() + '&' + OAuth.percentEncode(normalizedUrl) + '&'
        + OAuth.percentEncode(normalizedParams);
  } catch (Exception e) {
    throw new OAuthMessageSignerException(e);
  }
}

代码示例来源:origin: mttkay/signpost

@Test
public void shouldEncodeAndConcatenateAllSignatureParts() throws Exception {
  HttpRequest request = mock(HttpRequest.class);
  when(request.getMethod()).thenReturn("GET");
  when(request.getRequestUrl()).thenReturn("http://example.com");
  HttpParameters params = new HttpParameters();
  params.put("a", "1");
  SignatureBaseString sbs = new SignatureBaseString(request, params);
  //TODO: Is it correct that a trailing slash is always added to the
  //request URL authority if the path is empty? 
  assertEquals("GET&http%3A%2F%2Fexample.com%2F&a%3D1", sbs.generate());
}

代码示例来源:origin: mttkay/signpost

@Test
  public void shouldWorkWithMultipleParametersWithBracketsOfSameName() throws Exception {
    HttpRequest request = mock(HttpRequest.class);
    when(request.getMethod()).thenReturn("GET");
    when(request.getRequestUrl()).thenReturn("http://examplemultiple.com");

    HttpParameters params = new HttpParameters();
    params.put("a[]", "1", true);
    params.put("a[]", "2", true);

    SignatureBaseString sbs = new SignatureBaseString(request, params);
    
    assertEquals("GET&http%3A%2F%2Fexamplemultiple.com%2F&a%255B%255D%3D1%26a%255B%255D%3D2", sbs.generate());
  }
}

代码示例来源:origin: mttkay/signpost

@Test
public void shouldComputeCorrectHmacSha1Signature() throws Exception {
  // based on the reference test case from
  // http://oauth.pbwiki.com/TestCases
  OAuthMessageSigner signer = new HmacSha1MessageSigner();
  signer.setConsumerSecret(CONSUMER_SECRET);
  signer.setTokenSecret(TOKEN_SECRET);
  HttpRequest request = mock(HttpRequest.class);
  when(request.getRequestUrl()).thenReturn("http://photos.example.net/photos");
  when(request.getMethod()).thenReturn("GET");
  HttpParameters params = new HttpParameters();
  params.putAll(OAUTH_PARAMS);
  params.put("file", "vacation.jpg");
  params.put("size", "original");
  assertEquals("tR3+Ty81lMeYAr/Fid0kMTYa/WM=", signer.sign(request, params));
}

代码示例来源:origin: mttkay/signpost

@Test
  public void shouldComputeCorrectHmacSha256Signature() throws Exception {
    // based on the reference test case from
    // http://oauth.pbwiki.com/TestCases
    OAuthMessageSigner signer = new HmacSha256MessageSigner();
    signer.setConsumerSecret(CONSUMER_SECRET);
    signer.setTokenSecret(TOKEN_SECRET);

    HttpRequest request = mock(HttpRequest.class);
    when(request.getRequestUrl()).thenReturn("http://photos.example.net/photos");
    when(request.getMethod()).thenReturn("GET");

    HttpParameters params = new HttpParameters();
    params.putAll(OAUTH_PARAMS);
    params.put("file", "vacation.jpg");
    params.put("size", "original");

    assertEquals("0gCtTYQAxqCKhIE0sltgx7UgHkAs10vrpuYE7xpRBnE=", signer.sign(request, params));
  }
}

代码示例来源:origin: oauth.signpost/signpost-core

/**
 * Builds the signature base string from the data this instance was
 * configured with.
 * 
 * @return the signature base string
 * @throws OAuthMessageSignerException
 */
public String generate() throws OAuthMessageSignerException {
  try {
    String normalizedUrl = normalizeRequestUrl();
    String normalizedParams = normalizeRequestParameters();
    return request.getMethod() + '&' + OAuth.percentEncode(normalizedUrl) + '&'
        + OAuth.percentEncode(normalizedParams);
  } catch (Exception e) {
    throw new OAuthMessageSignerException(e);
  }
}

相关文章