下面列出了javax.ws.rs.client.ClientRequestContext#getEntityStream ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* {@inheritDoc}
*/
@Override
public void filter(final ClientRequestContext context) throws IOException {
final long id = _id.incrementAndGet();
context.setProperty(LOGGING_ID_PROPERTY, id);
final StringBuilder b = new StringBuilder();
printRequestLine(b, "Sending client request", id, context.getMethod(), context.getUri());
printPrefixedHeaders(b, id, REQUEST_PREFIX, context.getStringHeaders());
if (printEntity && context.hasEntity() && isSupportPrintType(context.getMediaType())) {
final OutputStream stream = new LoggingStream(b, context.getEntityStream());
context.setEntityStream(stream);
context.setProperty(ENTITY_LOGGER_PROPERTY, stream);
// not calling log(b) here - it will be called by the interceptor
} else {
log(b);
}
}
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
if (!logger.isLoggable(level)) {
return;
}
final long id = _id.incrementAndGet();
requestContext.setProperty(LOGGING_ID_PROPERTY, id);
final StringBuilder sb = new StringBuilder();
printRequestLine(sb, "Sending client request", id, requestContext.getMethod(), requestContext.getUri());
printHeaders(sb, id, REQUEST_PREFIX, requestContext.getStringHeaders());
if (requestContext.hasEntity() && maxEntitySize > 0) {
final OutputStream stream = new LoggingStream(sb, requestContext.getEntityStream());
requestContext.setEntityStream(stream);
requestContext.setProperty(ENTITY_STREAM_PROPERTY, stream);
} else {
log(sb);
}
}
@Override
public void filter(final ClientRequestContext context) throws IOException {
final long id = aid.incrementAndGet();
final StringBuilder b = new StringBuilder();
printRequestLine(b, "Sending client request", id, context.getMethod(), context.getUri());
printPrefixedHeaders(b, id, REQUEST_PREFIX, context.getStringHeaders());
if (printEntity && context.hasEntity()) {
final OutputStream stream = new LoggingStream(b, context.getEntityStream());
context.setEntityStream(stream);
context.setProperty(ENTITY_LOGGER_PROPERTY, stream);
// not calling log(b) here - it will be called by the interceptor
} else {
log(b);
}
}
@Override
public void filter(ClientRequestContext request) throws IOException {
if (request.hasEntity() && isPrintable(request.getMediaType())) {
LoggingFilterOutputStream out = new LoggingFilterOutputStream(request.getEntityStream());
request.setEntityStream(out);
request.setProperty(LoggingFilterOutputStream.KEY, out);
}
HttpRequest actual = new HttpRequest();
context.setPrevRequest(actual);
actual.startTimer();
}
@Override
public State buffer(final ClientRequestContext context) {
final TeeOutputStream stream = new TeeOutputStream(context.getEntityStream());
context.setEntityStream(stream);
return new Buffering(stream);
}