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


Java ClientResponseContext.hasEntity方法代碼示例

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


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

示例1: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext)
        throws IOException {
    final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY);
    final long id = requestId != null ? (Long) requestId : _id.incrementAndGet();

    StringBuilder b = (StringBuilder) requestContext.getProperty(LOGGER_BUFFER_PROPERTY);
    if (b == null) {
        b = new StringBuilder();
        requestContext.setProperty(LOGGER_BUFFER_PROPERTY, b);
    }

    printResponseLine(b, "Client response received", id, responseContext.getStatus());
    printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders());

    if (printEntity && responseContext.hasEntity() && isSupportPrintType(responseContext.getMediaType())) {
        responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(),
                MessageUtils.getCharset(responseContext.getMediaType())));
    }

    log(b);
}
 
開發者ID:icode,項目名稱:ameba,代碼行數:26,代碼來源:LoggingFilter.java

示例2: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
    if (responseContext.getStatus() != Response.Status.OK.getStatusCode() && responseContext.hasEntity()) {
        try {
            final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            final Error error = (Error) unmarshaller.unmarshal(responseContext.getEntityStream());

            final Response.ResponseBuilder builder = Response.status(responseContext.getStatusInfo());
            builder.entity(error);
            // copy response headers
            for (Map.Entry<String, List<String>> header : responseContext.getHeaders().entrySet()) {
                builder.header(header.getKey(), header.getValue());
            }

            throw new LinkedInException(error, builder.build());
        } catch (JAXBException e) {
            // log and ignore
            LOG.warn("Unable to parse LinkedIn error: " + e.getMessage(), e);
        }
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:LinkedInExceptionResponseFilter.java

示例3: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(final ClientRequestContext requestContext,
                   final ClientResponseContext responseContext) {
    try {
        // For non-200 response, log the custom error message.
        if (responseContext.getStatus() != Response.Status.OK.getStatusCode()) {
            if (responseContext.hasEntity()) {
                String error = CharStreams.toString(
                    new InputStreamReader(responseContext.getEntityStream(), Charsets.UTF_8));
                LOG.severe(error);
                System.err.println(error);
            }
        }
    } catch (Exception e) {
        // Silently pass. We don't want anything to fail because of this filter.
        LOG.warning("Error while checking response code: " + e.getMessage());
    }
}
 
開發者ID:qubole,項目名稱:qds-sdk-java,代碼行數:19,代碼來源:ErrorResponseFilter.java

示例4: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
  public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
      
// TODO - add other non-error responses here
      if (responseContext.getStatus() != Response.Status.OK.getStatusCode() &&
      		responseContext.getStatus() != Response.Status.CREATED.getStatusCode()) {
          if (responseContext.hasEntity()) {
              // get the "real" error message
              Error error = _MAPPER.readValue(responseContext.getEntityStream(), Error.class);

              Response.Status status = Response.Status.fromStatusCode(responseContext.getStatus());
              MaxinetWebException maxinetException;
              switch (status) {
                  case INTERNAL_SERVER_ERROR:
                  	maxinetException = new MaxinetInternalException(error.getMessage(), responseContext.getStatus());
                      break;
                  case BAD_REQUEST:
                  	maxinetException = new MaxinetClientException(error.getMessage(), responseContext.getStatus());
                      break;
                  default:
                  	maxinetException = new MaxinetWebException(error.getMessage(), responseContext.getStatus());
              }

              throw maxinetException;
          }
      }
  }
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:28,代碼來源:ErrorResponseFilter.java

示例5: getResponseMetaData

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private HttpResponseMetaData getResponseMetaData(ClientResponseContext responseContext) throws IOException {
    Map<String, String> headers = FormatUtil.MultiMapAsStringMap(responseContext.getHeaders());
    HttpResponseMetaData.HttpResponseMetaDataBuilder builder = HttpResponseMetaData.builder()
            .status(responseContext.getStatus())
            .headers(headers);

    if (responseContext.hasEntity()) {
        String body;
        // setUp the "real" error message
        try (BufferedReader buffer = new BufferedReader(new InputStreamReader(responseContext.getEntityStream(), "UTF-8"))) {
            body = buffer.lines().collect(Collectors.joining("\n"));
        }
        try {
            ProblemResponse problem = mapper.readValue(body, ProblemResponse.class);
            if (problemWasParsed(problem)) {
                builder.problemResponse(problem)
                        .incidentReferenceId(problem.incidentReferenceId);
            }
        } catch (JsonParseException | JsonMappingException e) {
            //ignore
        }

        if (builder.build().problemResponse == null) {
            builder.response(body);
        }
    }

    return builder.build();
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:30,代碼來源:ClientErrorResponseFilter.java

示例6: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
  if (logger.isDebugEnabled()) {
    logger.debug("Response status: " + responseContext.getStatus() + " - " + responseContext.getStatusInfo());
  }
  if (logger.isTraceEnabled() && responseContext.hasEntity()) {
    logResponseBody(responseContext);
  }
}
 
開發者ID:SK-EID,項目名稱:smart-id-java-client,代碼行數:10,代碼來源:LoggingFilter.java

示例7: shouldLogEntity

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private static boolean shouldLogEntity(final ClientResponseContext responseCtx) {
    if (!responseCtx.hasEntity()) {
        return false;
    } else if (responseCtx.getStatus() < 400) {
        return Settings.INSTANCE.isDebugHttpResponseLoggingEnabled();
    } else {
        return true;
    }
}
 
開發者ID:RoboZonky,項目名稱:robozonky,代碼行數:10,代碼來源:RoboZonkyFilter.java

示例8: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext)
        throws IOException {
    final long id = aid.incrementAndGet();
    final StringBuilder b = new StringBuilder();

    printResponseLine(b, "Client response received", id, responseContext.getStatus());
    printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders());

    if (printEntity && responseContext.hasEntity()) {
        responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream()));
    }

    log(b);
}
 
開發者ID:docker-java,項目名稱:docker-java,代碼行數:16,代碼來源:LoggingFilter.java

示例9: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
    if (responseContext.hasEntity()) {
        assertEquals(HttpHeaders.ACCEPT_ENCODING, responseContext.getHeaderString(HttpHeaders.VARY));
        assertEquals(ConverterNetworkProtocol.COMPRESSION_TYPE_GZIP, responseContext.getHeaderString(HttpHeaders.CONTENT_ENCODING));
    }
}
 
開發者ID:documents4j,項目名稱:documents4j,代碼行數:8,代碼來源:AbstractEncodingJerseyTest.java


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