Java Code Examples for javax.ws.rs.client.ClientRequestContext#hasEntity()
The following examples show how to use
javax.ws.rs.client.ClientRequestContext#hasEntity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoggingFilter.java From ameba with MIT License | 6 votes |
/** * {@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); } }
Example 2
Source File: MaskingLoggingFilter.java From gitlab4j-api with MIT License | 6 votes |
@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); } }
Example 3
Source File: LoggingFilter.java From docker-java with Apache License 2.0 | 6 votes |
@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); } }
Example 4
Source File: RestClient.java From ats-framework with Apache License 2.0 | 5 votes |
@Override public void filter( ClientRequestContext context ) throws IOException { if (debugLevel == RESTDebugLevel.NONE || debugLevel == RESTDebugLevel.TARGET_URI || isApacheConnectorProviderInUse()) { return; } MultivaluedMap<String, Object> reqHeaders = context.getHeaders(); StringBuilder requestMessage = new StringBuilder(); requestMessage.append("Sending the following request: \n"); if ( (debugLevel & RESTDebugLevel.HEADERS) == RESTDebugLevel.HEADERS) { requestMessage.append(context.getMethod() + " " + context.getUri() + " \n"); for (Entry<String, List<Object>> reqHeaderEntry : reqHeaders.entrySet()) { requestMessage.append(reqHeaderEntry.getKey() + ": " + Arrays.toString(reqHeaderEntry.getValue().toArray()) + " \n"); } } if ( (debugLevel & RESTDebugLevel.BODY) == RESTDebugLevel.BODY && context.hasEntity()) { // log request body Object entity = context.getEntity(); if (entity instanceof Form) { requestMessage.append("Body: " + ((Form) entity).asMap()); } else { requestMessage.append("Body: " + entity.toString()); } } log.info(requestMessage); }
Example 5
Source File: LoggingInterceptor.java From karate with MIT License | 5 votes |
@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(); }
Example 6
Source File: LogbookClientFilter.java From logbook with MIT License | 5 votes |
@Override public void filter(final ClientRequestContext context) throws IOException { final LocalRequest request = new LocalRequest(context); final RequestWritingStage stage = logbook.process(request); if (context.hasEntity()) { context.setProperty("request", request); context.setProperty("write-request", stage); } else { context.setProperty("process-response", stage.write()); } request.expose(); }
Example 7
Source File: JAXRS20ClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Override public void filter(ClientRequestContext context) throws IOException { String opName = (String)JAXRSUtils.getCurrentMessage().getExchange().get("org.apache.cxf.resource.operation.name"); assertFalse(opName.endsWith("?a=b")); context.getHeaders().putSingle("Simple", "simple"); if (context.hasEntity()) { context.getHeaders().putSingle("Content-Type", MediaType.APPLICATION_XML_TYPE); } }