當前位置: 首頁>>代碼示例>>Java>>正文


Java Response.bufferEntity方法代碼示例

本文整理匯總了Java中javax.ws.rs.core.Response.bufferEntity方法的典型用法代碼示例。如果您正苦於以下問題:Java Response.bufferEntity方法的具體用法?Java Response.bufferEntity怎麽用?Java Response.bufferEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.core.Response的用法示例。


在下文中一共展示了Response.bufferEntity方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: expect

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
protected Response expect(ResponseExpectation expectation, Invocation i) {
  try (Timer.TimedBlock b = Timer.time("request")) {
    Response response = i.invoke();
    response.bufferEntity();
    try {
      expectation.validate(response);
    } catch (AssertionError e) {
      // this will show the body of the response in the error message
      // if an error occurred it will show the server side error.
      // response.toString() does not show the content
      String body = response.readEntity(String.class);
      throw new AssertionError(String.format("%s\n%s\n%s", e.getMessage(), response.toString(), body), e);
    }
    return response;
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:17,代碼來源:BaseClientUtils.java

示例2: validate

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
public static void validate(Response response, int status, String msg) {
    assertNotNull("No response was produced", response);

    response.bufferEntity(); //this is needed in case validate is called more than once
    JSONObject jsonObject = new JSONObject(response.readEntity(String.class));

    assertEquals(status, response.getStatus());
    assertFalse("Response does not have the code property", jsonObject.isNull("code"));
    assertFalse("Response does not have the message property", jsonObject.isNull("message"));
    assertEquals("Response code is not equal", status, jsonObject.getInt("code"));
    assertEquals("Response message is not equal",msg, jsonObject.getString("message"));
}
 
開發者ID:tosinoni,項目名稱:SECP,代碼行數:13,代碼來源:ResponseValidator.java

示例3: readEntity

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
private static <T> T readEntity(Class<T> entityClazz, Invocation invocation) throws IOException {
  Response response = invocation.invoke();
  try {
    response.bufferEntity();
    if (response.getStatus() != Response.Status.OK.getStatusCode()) {
      if (response.hasEntity()) {
        // Try to parse error message as generic error message JSON type
        try {
          GenericErrorMessage message = response.readEntity(GenericErrorMessage.class);
          throw new IOException(format("Status %d (%s): %s (more info: %s)",
              response.getStatus(),
              response.getStatusInfo().getReasonPhrase(),
              message.getErrorMessage(),
              message.getMoreInfo()));
        } catch (ProcessingException e) {
          // Fallback to String if unparsing is unsuccessful
          throw new IOException(format("Status %d (%s)",
              response.getStatus(),
              response.getStatusInfo().getReasonPhrase(),
              response.readEntity(String.class)));
        }
      }
      throw new IOException(format("Status %d (%s)",
          response.getStatus(),
          response.getStatusInfo().getReasonPhrase()));
    }
    return response.readEntity(entityClazz);
  } finally {
    response.close();
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:32,代碼來源:Backup.java

示例4: readEntity

import javax.ws.rs.core.Response; //導入方法依賴的package包/類
private <T> T readEntity(Response response, GenericType<T> c) {
  response.bufferEntity();
  try {
    return response.readEntity(c);
  } catch (ProcessingException e) {
    String body = response.readEntity(String.class);
    throw new RuntimeException("Error deserializing entity with " + c + " : " + body, e);
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:10,代碼來源:BaseClientUtils.java


注:本文中的javax.ws.rs.core.Response.bufferEntity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。