org.apache.http.client.methods.RequestBuilder.getEntity()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(99)

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

RequestBuilder.getEntity介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-gobblin

public static void assertEqual(RequestBuilder actual, RequestBuilder expect)
  throws IOException {
 // Check entity
 HttpEntity actualEntity = actual.getEntity();
 HttpEntity expectedEntity = expect.getEntity();
 if (actualEntity == null) {
  Assert.assertTrue(expectedEntity == null);
 } else {
  Assert.assertEquals(actualEntity.getContentLength(), expectedEntity.getContentLength());
  String actualContent = IOUtils.toString(actualEntity.getContent(), StandardCharsets.UTF_8);
  String expectedContent = IOUtils.toString(expectedEntity.getContent(), StandardCharsets.UTF_8);
  Assert.assertEquals(actualContent, expectedContent);
 }
 // Check request
 HttpUriRequest actualRequest = actual.build();
 HttpUriRequest expectedRequest = expect.build();
 Assert.assertEquals(actualRequest.getMethod(), expectedRequest.getMethod());
 Assert.assertEquals(actualRequest.getURI().toString(), expectedRequest.getURI().toString());
 Header[] actualHeaders = actualRequest.getAllHeaders();
 Header[] expectedHeaders = expectedRequest.getAllHeaders();
 Assert.assertEquals(actualHeaders.length, expectedHeaders.length);
 for (int i = 0; i < actualHeaders.length; i++) {
  Assert.assertEquals(actualHeaders[i].toString(), expectedHeaders[i].toString());
 }
}

代码示例来源:origin: Nexmo/nexmo-java

@Test
public void testMakeRequest() throws Exception {
  RequestBuilder request = method.makeRequest(new Call("447700900903",
      "447700900904",
      "https://example.com/answer"
  ));
  assertEquals("POST", request.getMethod());
  assertEquals("application/json", request.getFirstHeader("Content-Type").getValue());
  ObjectMapper objectMapper = new ObjectMapper();
  JsonNode node = objectMapper.readValue(request.getEntity().getContent(), JsonNode.class);
  LOG.info(request.getEntity().getContent());
  assertEquals("447700900903", node.get("to").get(0).get("number").asText());
  assertEquals("447700900904", node.get("from").get("number").asText());
  assertEquals("https://example.com/answer", node.get("answer_url").get(0).asText());
}

代码示例来源:origin: Nexmo/nexmo-java

@Test
public void makeRequest() throws Exception {
  HttpWrapper httpWrapper = new HttpWrapper();
  SendDtmfMethod methodUnderTest = new SendDtmfMethod(httpWrapper);
  RequestBuilder request = methodUnderTest.makeRequest(new DtmfRequest("abc-123", "867"));
  assertEquals("PUT", request.getMethod());
  assertEquals("application/json", request.getFirstHeader("Content-Type").getValue());
  ObjectMapper objectMapper = new ObjectMapper();
  JsonNode node = objectMapper.readValue(request.getEntity().getContent(), JsonNode.class);
  LOG.info(request.getEntity().getContent());
  assertEquals("867", node.get("digits").asText());
}

代码示例来源:origin: Nexmo/nexmo-java

@Test
public void testConstructParamsWithoutType() throws Exception {
  RedactRequest request = new RedactRequest("test-id", RedactRequest.Product.VOICE);
  RequestBuilder builder = method.makeRequest(request);
  HttpEntity entity = builder.getEntity();
  assertEquals(entity.getContentType().getValue(), ContentType.APPLICATION_JSON.toString());
  assertNotNull(entity.getContent());
}

代码示例来源:origin: Nexmo/nexmo-java

@Test
public void testConstructParams() throws Exception {
  CreateSecretRequest request = new CreateSecretRequest("account-id", "secret");
  RequestBuilder builder = method.makeRequest(request);
  HttpEntity entity = builder.getEntity();
  assertEquals(entity.getContentType().getValue(), ContentType.APPLICATION_JSON.toString());
  assertNotNull(entity.getContent());
}

代码示例来源:origin: com.netflix.ribbon/ribbon-httpasyncclient

if (builder.getEntity() == null) {
  throw new ClientException("No suitable serializer for " + key);

代码示例来源:origin: Nexmo/nexmo-java

@Test
public void testConstructParamsWithType() throws Exception {
  RedactRequest request = new RedactRequest("test-id", RedactRequest.Product.SMS);
  request.setType(RedactRequest.Type.INBOUND);
  RequestBuilder builder = method.makeRequest(request);
  HttpEntity entity = builder.getEntity();
  assertEquals(entity.getContentType().getValue(), ContentType.APPLICATION_JSON.toString());
  assertNotNull(entity.getContent());
}

代码示例来源:origin: Nexmo/nexmo-java

@Test
public void makeRequest() throws Exception {
  HttpWrapper httpWrapper = new HttpWrapper();
  ModifyCallMethod methodUnderTest = new ModifyCallMethod(httpWrapper);
  RequestBuilder request = methodUnderTest.makeRequest(
      new CallModifier("abc-123", ModifyCallAction.HANGUP)
  );
  assertEquals("PUT", request.getMethod());
  assertEquals("application/json", request.getFirstHeader("Content-Type").getValue());
  ObjectMapper objectMapper = new ObjectMapper();
  JsonNode node = objectMapper.readValue(request.getEntity().getContent(), JsonNode.class);
  assertEquals("hangup", node.get("action").asText());
}

代码示例来源:origin: Nexmo/nexmo-java

@Test
public void earmuffRequest() throws Exception {
  HttpWrapper httpWrapper = new HttpWrapper();
  ModifyCallMethod methodUnderTest = new ModifyCallMethod(httpWrapper);
  RequestBuilder request = methodUnderTest.makeRequest(
      new CallModifier("abc-123", ModifyCallAction.EARMUFF)
  );
  assertEquals("PUT", request.getMethod());
  assertEquals("application/json", request.getFirstHeader("Content-Type").getValue());
  ObjectMapper objectMapper = new ObjectMapper();
  JsonNode node = objectMapper.readValue(request.getEntity().getContent(), JsonNode.class);
  assertEquals("earmuff", node.get("action").asText());
}

代码示例来源:origin: Nexmo/nexmo-java

@Test
public void unearmuffRequest() throws Exception {
  HttpWrapper httpWrapper = new HttpWrapper();
  ModifyCallMethod methodUnderTest = new ModifyCallMethod(httpWrapper);
  RequestBuilder request = methodUnderTest.makeRequest(
      new CallModifier("abc-123", ModifyCallAction.UNEARMUFF)
  );
  assertEquals("PUT", request.getMethod());
  assertEquals("application/json", request.getFirstHeader("Content-Type").getValue());
  ObjectMapper objectMapper = new ObjectMapper();
  JsonNode node = objectMapper.readValue(request.getEntity().getContent(), JsonNode.class);
  assertEquals("unearmuff", node.get("action").asText());
}

代码示例来源:origin: Nexmo/nexmo-java

@Test
public void muteRequest() throws Exception {
  HttpWrapper httpWrapper = new HttpWrapper();
  ModifyCallMethod methodUnderTest = new ModifyCallMethod(httpWrapper);
  RequestBuilder request = methodUnderTest.makeRequest(
      new CallModifier("abc-123", ModifyCallAction.MUTE)
  );
  assertEquals("PUT", request.getMethod());
  assertEquals("application/json", request.getFirstHeader("Content-Type").getValue());
  ObjectMapper objectMapper = new ObjectMapper();
  JsonNode node = objectMapper.readValue(request.getEntity().getContent(), JsonNode.class);
  assertEquals("mute", node.get("action").asText());
}

代码示例来源:origin: Nexmo/nexmo-java

@Test
public void unmuteRequest() throws Exception {
  HttpWrapper httpWrapper = new HttpWrapper();
  ModifyCallMethod methodUnderTest = new ModifyCallMethod(httpWrapper);
  RequestBuilder request = methodUnderTest.makeRequest(
      new CallModifier("abc-123", ModifyCallAction.UNMUTE)
  );
  assertEquals("PUT", request.getMethod());
  assertEquals("application/json", request.getFirstHeader("Content-Type").getValue());
  ObjectMapper objectMapper = new ObjectMapper();
  JsonNode node = objectMapper.readValue(request.getEntity().getContent(), JsonNode.class);
  assertEquals("unmute", node.get("action").asText());
}

相关文章