javax.ws.rs.core.Response.hasEntity()方法的使用及代码示例

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

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

Response.hasEntity介绍

[英]Check if there is an entity available in the response. The method returns true if the entity is present, returns false otherwise.

Note that the method may return true also for response messages with a zero-length content, in case the javax.ws.rs.core.HttpHeaders#CONTENT_LENGTH and javax.ws.rs.core.HttpHeaders#CONTENT_TYPE headers are specified in the message. In such case, an attempt to read the entity using one of the readEntity(...)methods will return a corresponding instance representing a zero-length entity for a given Java type or produce a ProcessingException in case no such instance is available for the Java type.
[中]检查响应中是否有可用的实体。如果实体存在,则该方法返回true,否则返回false。
请注意,对于长度为零的内容的响应消息,该方法可能也会返回true,例如javax。ws。rs.core。HttpHeaders#内容#长度和javax。ws。rs.core。消息中指定了HttpHeaders#CONTENT_类型的头。在这种情况下,尝试使用readEntity(…)之一读取实体方法将返回一个对应的实例,该实例表示给定Java类型的零长度实体,或者在没有此类实例可用于该Java类型的情况下生成ProcessingException。

代码示例

代码示例来源:origin: jersey/jersey

/**
 * Format of response - status code, status family, reason phrase and info about entity.
 *
 * @param response response to be formatted
 * @param textSB   Formatted info will be appended to {@code StringBuilder}
 */
private static void formatResponse(final Response response, final StringBuilder textSB) {
  textSB.append(" <").append(formatStatusInfo(response.getStatusInfo())).append('|');
  if (response.hasEntity()) {
    formatInstance(response.getEntity(), textSB);
  } else {
    textSB.append("-no-entity-");
  }
  textSB.append('>');
}

代码示例来源:origin: jersey/jersey

/**
 * Format of response - status code, status family, reason phrase and info about entity.
 *
 * @param response response to be formatted
 * @param textSB   Formatted info will be appended to {@code StringBuilder}
 */
private static void formatResponse(final Response response, final StringBuilder textSB) {
  textSB.append(" <").append(formatStatusInfo(response.getStatusInfo())).append('|');
  if (response.hasEntity()) {
    formatInstance(response.getEntity(), textSB);
  } else {
    textSB.append("-no-entity-");
  }
  textSB.append('>');
}

代码示例来源:origin: Netflix/eureka

private EurekaHttpResponse<InstanceInfo> getInstanceInternal(String urlPath) {
  Response response = null;
  try {
    Builder requestBuilder = jerseyClient.target(serviceUrl).path(urlPath).request();
    addExtraProperties(requestBuilder);
    addExtraHeaders(requestBuilder);
    response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get();
    InstanceInfo infoFromPeer = null;
    if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
      infoFromPeer = response.readEntity(InstanceInfo.class);
    }
    return anEurekaHttpResponse(response.getStatus(), infoFromPeer).headers(headersOf(response)).build();
  } finally {
    if (logger.isDebugEnabled()) {
      logger.debug("Jersey2 HTTP GET {}/{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
    }
    if (response != null) {
      response.close();
    }
  }
}

代码示例来源:origin: Netflix/eureka

@Override
public EurekaHttpResponse<Application> getApplication(String appName) {
  String urlPath = "apps/" + appName;
  Response response = null;
  try {
    Builder requestBuilder = jerseyClient.target(serviceUrl).path(urlPath).request();
    addExtraProperties(requestBuilder);
    addExtraHeaders(requestBuilder);
    response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get();
    Application application = null;
    if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
      application = response.readEntity(Application.class);
    }
    return anEurekaHttpResponse(response.getStatus(), application).headers(headersOf(response)).build();
  } finally {
    if (logger.isDebugEnabled()) {
      logger.debug("Jersey2 HTTP GET {}/{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
    }
    if (response != null) {
      response.close();
    }
  }
}

代码示例来源:origin: Netflix/eureka

private EurekaHttpResponse<Applications> getApplicationsInternal(String urlPath, String[] regions) {
  Response response = null;
  try {
    WebTarget webTarget = jerseyClient.target(serviceUrl).path(urlPath);
    if (regions != null && regions.length > 0) {
      webTarget = webTarget.queryParam("regions", StringUtil.join(regions));
    }
    Builder requestBuilder = webTarget.request();
    addExtraProperties(requestBuilder);
    addExtraHeaders(requestBuilder);
    response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get();
    Applications applications = null;
    if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
      applications = response.readEntity(Applications.class);
    }
    return anEurekaHttpResponse(response.getStatus(), applications).headers(headersOf(response)).build();
  } finally {
    if (logger.isDebugEnabled()) {
      logger.debug("Jersey2 HTTP GET {}/{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
    }
    if (response != null) {
      response.close();
    }
  }
}

代码示例来源:origin: Netflix/eureka

response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).put(Entity.entity("{}", MediaType.APPLICATION_JSON_TYPE)); // Jersey2 refuses to handle PUT with no body
InstanceInfo infoFromPeer = null;
if (response.getStatus() == Status.CONFLICT.getStatusCode() && response.hasEntity()) {
  infoFromPeer = response.readEntity(InstanceInfo.class);

代码示例来源:origin: Netflix/eureka

response = requestBuilder.put(Entity.entity("{}", MediaType.APPLICATION_JSON_TYPE)); // Jersey2 refuses to handle PUT with no body
EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse(response.getStatus(), InstanceInfo.class).headers(headersOf(response));
if (response.hasEntity()) {
  eurekaResponseBuilder.entity(response.readEntity(InstanceInfo.class));

代码示例来源:origin: jersey/jersey

if (waeResponse.hasEntity()) {
  LOGGER.log(Level.FINE, LocalizationMessages
      .EXCEPTION_MAPPING_WAE_ENTITY(waeResponse.getStatus()), throwable);

代码示例来源:origin: jersey/jersey

if (waeResponse.hasEntity()) {
  LOGGER.log(Level.FINE, LocalizationMessages
      .EXCEPTION_MAPPING_WAE_ENTITY(waeResponse.getStatus()), throwable);

代码示例来源:origin: jersey/jersey

if (response.getStatus() != 200) {
  String errorEntity = null;
  if (response.hasEntity()) {
    errorEntity = response.readEntity(String.class);

代码示例来源:origin: jersey/jersey

if (nextResponse.hasEntity()) {
  response.setEntityStream(nextResponse.readEntity(InputStream.class));

代码示例来源:origin: jersey/jersey

if (nextResponse.hasEntity()) {
  response.setEntityStream(nextResponse.readEntity(InputStream.class));

代码示例来源:origin: org.glassfish.jersey.core/jersey-client

if (nextResponse.hasEntity()) {
  response.setEntityStream(nextResponse.readEntity(InputStream.class));

代码示例来源:origin: apache/nifi

getLogger().info("Successfully sent metrics to Ambari in {} ms", new Object[]{completedMillis});
} else {
  final String responseEntity = response.hasEntity() ? response.readEntity(String.class) : "unknown error";
  getLogger().error("Error sending metrics to Ambari due to {} - {}", new Object[]{response.getStatus(), responseEntity});

代码示例来源:origin: jamesagnew/hapi-fhir

@Override
public Reader createReader() {
  if (!myBufferedEntity && !myResponse.hasEntity()) {
    return new StringReader("");
  } else {
    return new StringReader(myResponse.readEntity(String.class));
  }
}

代码示例来源:origin: jamesagnew/hapi-fhir

@Override
public InputStream readEntity() {
  if (!myBufferedEntity && !myResponse.hasEntity()) {
    return new ByteArrayInputStream(new byte[0]);
  } else {
    return new ByteArrayInputStream(myResponse.readEntity(byte[].class));
  }
}

代码示例来源:origin: jersey/jersey

if (response.hasEntity()) {
  Object entityFuture = response.getEntity();
  if (entityFuture instanceof CompletionStage) {

代码示例来源:origin: jersey/jersey

if (response.hasEntity()) {
  Object entityFuture = response.getEntity();
  if (entityFuture instanceof CompletionStage) {

代码示例来源:origin: jamesagnew/hapi-fhir

@Override
public void bufferEntity() throws IOException {
  if(!myBufferedEntity && myResponse.hasEntity()) {
    myBufferedEntity = true;
    myResponse.bufferEntity();
  } else {
    myResponse.bufferEntity();
  }
}

代码示例来源:origin: hugegraph/hugegraph

@Override
public Response toResponse(WebApplicationException exception) {
  Response response = exception.getResponse();
  if (response.hasEntity()) {
    return response;
  }
  MultivaluedMap<String, Object> headers = response.getHeaders();
  boolean trace = this.trace(response.getStatus());
  response = Response.status(response.getStatus())
            .type(MediaType.APPLICATION_JSON)
            .entity(formatException(exception, trace))
            .build();
  response.getHeaders().putAll(headers);
  return response;
}

相关文章