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

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

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

HttpRequest.getContentType介绍

暂无

代码示例

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

/**
 * Collects x-www-form-urlencoded body parameters as per OAuth Core 1.0 spec
 * section 9.1.1
 */
protected void collectBodyParameters(HttpRequest request, HttpParameters out)
    throws IOException {
  // collect x-www-form-urlencoded body params
  String contentType = request.getContentType();
  if (contentType != null && contentType.startsWith(OAuth.FORM_ENCODED)) {
    InputStream payload = request.getMessagePayload();
    out.putAll(OAuth.decodeForm(payload), true);
  }
}

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

@Test
public void shouldReturnCorrectContentType() {
  assertEquals(CONTENT_TYPE, request.getContentType());
}

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

@Test
public void shouldIncludeOAuthAndQueryAndBodyParams() throws Exception {
  // mock a request that has custom query, body, and header params set
  HttpRequest request = mock(HttpRequest.class);
  when(request.getRequestUrl()).thenReturn("http://example.com?a=1+1");
  ByteArrayInputStream body = new ByteArrayInputStream("b=2+2".getBytes());
  when(request.getMessagePayload()).thenReturn(body);
  when(request.getContentType()).thenReturn(
      "application/x-www-form-urlencoded; charset=ISO-8859-1");
  when(request.getHeader("Authorization")).thenReturn(
      "OAuth realm=\"http%3A%2F%2Fexample.com\", oauth_token=\"12%25345\", oauth_signature=\"1234\"");
  OAuthMessageSigner signer = mock(HmacSha1MessageSigner.class);
  consumer.setMessageSigner(signer);
  consumer.sign(request);
  // verify that all custom params are properly read and passed to the
  // message signer
  ArgumentMatcher<HttpParameters> hasAllParameters = new ArgumentMatcher<HttpParameters>() {
    public boolean matches(Object argument) {
      HttpParameters params = (HttpParameters) argument;
      assertEquals("1 1", params.getFirst("a", true));
      assertEquals("2 2", params.getFirst("b", true));
      assertEquals("http://example.com", params.getFirst("realm", true));
      assertEquals("12%345", params.getFirst("oauth_token", true));
      // signature should be dropped, not valid to pre-set
      assertNull(params.getFirst("oauth_signature"));
      return true;
    }
  };
  verify(signer).sign(same(request), argThat(hasAllParameters));
}

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

/**
 * Collects x-www-form-urlencoded body parameters as per OAuth Core 1.0 spec
 * section 9.1.1
 */
protected void collectBodyParameters(HttpRequest request, HttpParameters out)
    throws IOException {
  // collect x-www-form-urlencoded body params
  String contentType = request.getContentType();
  if (contentType != null && contentType.startsWith(OAuth.FORM_ENCODED)) {
    InputStream payload = request.getMessagePayload();
    out.putAll(OAuth.decodeForm(payload), true);
  }
}

相关文章