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

x33g5p2x  于2022-01-17 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(273)

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

CloseableHttpResponse.setEntity介绍

暂无

代码示例

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.clients

@Override
public void setEntity(HttpEntity entity) {
  httpResponse.setEntity(entity);
}

代码示例来源:origin: org.esigate/esigate-core

/**
 * Create an HTTP error page exception from an Http response.
 * 
 * @param httpResponse
 *            backend response.
 */
public HttpErrorPage(CloseableHttpResponse httpResponse) {
  super(httpResponse.getStatusLine().getStatusCode() + " " + httpResponse.getStatusLine().getReasonPhrase());
  this.httpResponse = httpResponse;
  // Consume the entity and replace it with an in memory Entity
  httpResponse.setEntity(toMemoryEntity(httpResponse.getEntity()));
}

代码示例来源:origin: org.esigate/esigate-core

/**
 * Create an HTTP response from a String content wich will be used as the response entity.
 * 
 * @param statusCode
 * @param statusMessage
 * @param content
 */
public HttpErrorPage(int statusCode, String statusMessage, String content) {
  super(statusCode + " " + statusMessage);
  this.httpResponse = HttpErrorPage.generateHttpResponse(statusCode, statusMessage);
  this.httpResponse.setEntity(toMemoryEntity(content));
}

代码示例来源:origin: org.esigate/esigate-core

/**
 * Create an HTTP response from an exception. This exception stack trace will be showed to the end user.
 * 
 * @param statusCode
 * @param statusMessage
 * @param exception
 */
public HttpErrorPage(int statusCode, String statusMessage, Exception exception) {
  super(statusCode + " " + statusMessage, exception);
  this.httpResponse = HttpErrorPage.generateHttpResponse(statusCode, statusMessage);
  this.httpResponse.setEntity(toMemoryEntity(exception));
}

代码示例来源:origin: org.esigate/esigate-core

BasicCloseableHttpResponse.adapt(new BasicHttpResponse(response.getStatusLine()));
transformedResponse.setHeaders(response.getAllHeaders());
transformedResponse.setEntity(transformedHttpEntity);
return transformedResponse;

代码示例来源:origin: org.esigate/esigate-core

public static CloseableHttpResponse generateHttpResponse(int statusCode, String statusText) {
  CloseableHttpResponse result =
      BasicCloseableHttpResponse.adapt(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1,
          statusCode, statusText)));
  result.setEntity(toMemoryEntity(statusText));
  return result;
}

代码示例来源:origin: me.geso/mech

response.setEntity(new BufferedHttpEntity(entity));

代码示例来源:origin: FINRAOS/herd

@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse200BadContentReturnsNull() throws Exception
{
  CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "testReasonPhrase"), false);
  httpResponse.setEntity(new StringEntity("invalid xml"));
  executeWithoutLogging(DataBridgeWebClient.class, () -> {
    BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse =
      dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse);
    assertNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse);
  });
}

代码示例来源:origin: org.esigate/esigate-core

response.setEntity(new StringEntity(currentValue, HttpResponseUtils.getContentType(response)));

代码示例来源:origin: FINRAOS/herd

@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse200ValidResponse() throws Exception
{
  CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "testReasonPhrase"), false);
  httpResponse.setEntity(new StringEntity(xmlHelper.objectToXml(new BusinessObjectDataStorageFilesCreateResponse())));
  BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse =
    dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse);
  assertNotNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse);
}

代码示例来源:origin: FINRAOS/herd

@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse200ValidResponseHttpResponseThrowsExceptionOnClose() throws Exception
{
  CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "testReasonPhrase"), true);
  httpResponse.setEntity(new StringEntity(xmlHelper.objectToXml(new BusinessObjectDataStorageFilesCreateResponse())));
  executeWithoutLogging(DataBridgeWebClient.class, () -> {
    BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse =
      dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse);
    assertNotNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse);
  });
}

代码示例来源:origin: FINRAOS/herd

@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse400BadContentThrows() throws Exception
{
  int expectedStatusCode = 400;
  String expectedReasonPhrase = "testReasonPhrase";
  String expectedErrorMessage = "invalid xml";
  CloseableHttpResponse httpResponse =
    new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, expectedStatusCode, expectedReasonPhrase), false);
  httpResponse.setEntity(new StringEntity(expectedErrorMessage));
  try
  {
    executeWithoutLogging(DataBridgeWebClient.class, () -> {
      dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse);
    });
    Assert.fail("expected HttpErrorResponseException, but no exception was thrown");
  }
  catch (Exception e)
  {
    assertEquals("thrown exception type", HttpErrorResponseException.class, e.getClass());
    HttpErrorResponseException httpErrorResponseException = (HttpErrorResponseException) e;
    assertEquals("httpErrorResponseException responseMessage", expectedErrorMessage, httpErrorResponseException.getResponseMessage());
    assertEquals("httpErrorResponseException statusCode", expectedStatusCode, httpErrorResponseException.getStatusCode());
    assertEquals("httpErrorResponseException statusDescription", expectedReasonPhrase, httpErrorResponseException.getStatusDescription());
    assertEquals("httpErrorResponseException message", "Failed to add storage files", httpErrorResponseException.getMessage());
  }
}

代码示例来源:origin: FINRAOS/herd

@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse400Throws() throws Exception
{
  int expectedStatusCode = 400;
  String expectedReasonPhrase = "testReasonPhrase";
  String expectedErrorMessage = "testErrorMessage";
  ErrorInformation errorInformation = new ErrorInformation();
  errorInformation.setStatusCode(expectedStatusCode);
  errorInformation.setMessage(expectedErrorMessage);
  errorInformation.setStatusDescription(expectedReasonPhrase);
  String requestContent = xmlHelper.objectToXml(errorInformation);
  CloseableHttpResponse httpResponse =
    new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, expectedStatusCode, expectedReasonPhrase), false);
  httpResponse.setEntity(new StringEntity(requestContent));
  try
  {
    dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse);
    Assert.fail("expected HttpErrorResponseException, but no exception was thrown");
  }
  catch (Exception e)
  {
    assertEquals("thrown exception type", HttpErrorResponseException.class, e.getClass());
    HttpErrorResponseException httpErrorResponseException = (HttpErrorResponseException) e;
    assertEquals("httpErrorResponseException responseMessage", expectedErrorMessage, httpErrorResponseException.getResponseMessage());
    assertEquals("httpErrorResponseException statusCode", expectedStatusCode, httpErrorResponseException.getStatusCode());
    assertEquals("httpErrorResponseException statusDescription", expectedReasonPhrase, httpErrorResponseException.getStatusDescription());
    assertEquals("httpErrorResponseException message", "Failed to add storage files", httpErrorResponseException.getMessage());
  }
}

相关文章