本文整理匯總了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);
}
示例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);
}
}
}
示例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());
}
}
示例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;
}
}
}
示例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();
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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));
}
}