Java Code Examples for javax.ws.rs.ext.WriterInterceptorContext#getProperty()
The following examples show how to use
javax.ws.rs.ext.WriterInterceptorContext#getProperty() .
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 aroundWriteTo(final WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException { final LoggingStream stream = (LoggingStream) writerInterceptorContext.getProperty(ENTITY_LOGGER_PROPERTY); writerInterceptorContext.proceed(); final Object requestId = Requests.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); StringBuilder b = (StringBuilder) writerInterceptorContext.getProperty(LOGGER_BUFFER_PROPERTY); if (b == null) { b = new StringBuilder(); writerInterceptorContext.setProperty(LOGGER_BUFFER_PROPERTY, b); } printPrefixedHeaders(b, id, RESPONSE_PREFIX, HeaderUtils.asStringHeaders(writerInterceptorContext.getHeaders())); if (stream != null) { log(stream.getStringBuilder(MessageUtils.getCharset(writerInterceptorContext.getMediaType()))); } else { log(b); } }
Example 2
Source File: MaskingLoggingFilter.java From gitlab4j-api with MIT License | 6 votes |
@Override public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { final LoggingStream stream = (LoggingStream) context.getProperty(ENTITY_STREAM_PROPERTY); context.proceed(); if (stream == null) { return; } MediaType mediaType = context.getMediaType(); if (mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE) || mediaType.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE)) { log(stream.getStringBuilder(MessageUtils.getCharset(mediaType))); } }
Example 3
Source File: StructuredEventFilter.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { context.proceed(); if (BooleanUtils.isTrue((Boolean) context.getProperty(LOGGING_ENABLED_PROPERTY))) { Long requestTime = (Long) context.getProperty(REQUEST_TIME); RestRequestDetails restRequest = (RestRequestDetails) context.getProperty(REQUEST_DETAILS); RestResponseDetails restResponse = (RestResponseDetails) context.getProperty(RESPONSE_DETAILS); String responseBody = ((LoggingStream) context.getProperty(LOGGINGSTREAM_PROPERTY)).getStringBuilder( MessageUtils.getCharset(context.getMediaType())).toString(); Map<String, String> restParams = (Map<String, String>) context.getProperty(REST_PARAMS); if (restParams == null) { restParams = new HashMap<>(); } extendRestParamsFromResponse(restParams, responseBody); sendStructuredEvent(restRequest, restResponse, restParams, requestTime, responseBody); } }
Example 4
Source File: BaseMethodStatsInterceptor.java From datawave with Apache License 2.0 | 5 votes |
protected ResponseMethodStats doWrite(WriterInterceptorContext context) throws IOException, WebApplicationException { ResponseMethodStats stats; long start = System.nanoTime(); OutputStream originalOutputStream = context.getOutputStream(); CountingOutputStream countingStream = new CountingOutputStream(originalOutputStream); context.setOutputStream(countingStream); try { context.proceed(); } finally { long stop = System.nanoTime(); long time = TimeUnit.NANOSECONDS.toMillis(stop - start); context.setOutputStream(originalOutputStream); stats = (ResponseMethodStats) context.getProperty(RESPONSE_STATS_NAME); if (stats == null) { log.warn("No response stats found for " + getClass() + ". Using default."); stats = new ResponseMethodStats(); } RequestMethodStats requestStats = (RequestMethodStats) context.getProperty(REQUEST_STATS_NAME); if (requestStats == null) { log.warn("No request method stats found for " + getClass() + ". Using default."); requestStats = new RequestMethodStats(); requestStats.callStartTime = stop + TimeUnit.MILLISECONDS.toNanos(1); } stats.serializationTime = time; stats.loginTime = requestStats.getLoginTime(); stats.callTime = TimeUnit.NANOSECONDS.toMillis(stop - requestStats.getCallStartTime()); stats.bytesWritten = countingStream.getCount(); // Merge in the headers we saved in the postProcess call, if any. putNew(stats.responseHeaders, context.getHeaders()); } return stats; }
Example 5
Source File: LoggingFilter.java From docker-java with Apache License 2.0 | 5 votes |
@Override public void aroundWriteTo(final WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException { final LoggingStream stream = (LoggingStream) writerInterceptorContext.getProperty(ENTITY_LOGGER_PROPERTY); writerInterceptorContext.proceed(); if (stream != null) { log(stream.getStringBuilder()); } }