@Override public void filter(final ClientRequestContext context) throws IOException { if (!logger.isLoggable(level)) { return; } 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 (context.hasEntity() && printEntity(verbosity, 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(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(final ClientRequestContext context) throws IOException { if (!logger.isLoggable(level)) { return; } 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 (context.hasEntity() && printEntity(verbosity, 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); } }
public LocalRequest(final ClientRequestContext context) { // TODO now we need to buffer needlessly if we never actually need the body this.stream = new TeeOutputStream(context.getEntityStream()); context.setEntityStream(stream); this.context = context; }
@Override public void filter(ClientRequestContext requestContext) throws IOException { if (!(requestContext.getEntityStream() instanceof SavingOutputStream)) { requestContext.setEntityStream(new SavingOutputStream(requestContext.getEntityStream())); } }
@Override public void filter(ClientRequestContext requestContext) throws IOException { if (!(requestContext.getEntityStream() instanceof SavingOutputStream)) { requestContext.setEntityStream(new SavingOutputStream(requestContext.getEntityStream())); } }
@Override public void filter(ClientRequestContext context) throws IOException { StringBuilder request = new StringBuilder(); request.append("HTTP Request\n"); request.append(context.getMethod() + " " + context.getUri() + "\n"); appendHeaders(request, context.getStringHeaders()); if (context.hasEntity()) { OutputStream stream = new RequestLoggingStream(request, context.getEntityStream()); context.setEntityStream(stream); context.setProperty(REQUEST_LOGGING_STREAM, stream); } else { log.debug(request.toString()); } }
@Override public void filter(ClientRequestContext context) throws IOException { context.setEntityStream(new ReplacingOutputStream( context.getEntityStream(), 'X', 'O')); } });
@Test public void testGetSetEntityStreamLambda() { String address = "http://localhost:" + PORT + "/bookstore/entityecho"; String entity = "BOOKSTORE"; Client client = ClientBuilder.newClient(); client.register((ClientRequestFilter) context -> { context.setEntityStream(new ReplacingOutputStream(context.getEntityStream(), 'X', 'O')); }); WebTarget target = client.target(address); Response response = target.request().post( Entity.entity(entity.replace('O', 'X'), "text/plain")); assertEquals(entity, response.readEntity(String.class)); }
@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(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()) { 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(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()) { 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(final ClientRequestContext context) throws IOException { if (!logger.isLoggable(level)) { return; } 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 (context.hasEntity() && printEntity(verbosity, 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(final ClientRequestContext context) throws IOException { if (!logger.isLoggable(level)) { return; } 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 (context.hasEntity() && printEntity(verbosity, 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(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()) { 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(final ClientRequestContext context) throws IOException { String uriPath = context.getUri().getPath(); if (!logger.isTraceEnabled() || jerseyFiltering.excludeForUri(uriPath)) { return; } long id = _id.incrementAndGet(); context.setProperty(LOGGING_ID_PROPERTY, id); context.setProperty(Constants.REST_TIMING, System.currentTimeMillis()); StringBuilder b = new StringBuilder(); URI uri = context.getUri(); recordOutgoing(context, "sending"); printRequestLine(b, "Sending client request", id, context.getMethod(), uri); printPrefixedHeaders(b, id, REQUEST_PREFIX, context.getStringHeaders()); if (context.hasEntity() && printEntity(verbosity, context.getMediaType()) && !jerseyFiltering.excludePayloadForUri(uriPath)) { 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); } }
/** * {@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 context) throws IOException { Collector.getCurrent().ifPresent((exchangeInfo -> { JaxRsExchangeMessage msg = new JaxRsExchangeMessage(ExchangeMessage.Type.REQUEST); msg.setMethod(context.getMethod()); msg.setAddress(context.getUri().toString()); msg.setHeaders(context.getStringHeaders()); if (context.hasEntity()) { final OutputStream stream = new LoggingStream(msg, context.getEntityStream()) { @Override public void collect() { exchangeInfo.addBackendMessage(msg); } }; context.setEntityStream(stream); context.setProperty(ENTITY_LOGGER_PROPERTY, stream); // not calling log(b) here - it will be called by the interceptor } else { exchangeInfo.addBackendMessage(msg); } })); }