当前位置: 首页>>代码示例>>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;未经允许,请勿转载。