org.glassfish.jersey.message.MessageUtils Java Examples
The following examples show how to use
org.glassfish.jersey.message.MessageUtils.
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 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); }
Example #2
Source File: LoggingFilter.java From ameba with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public void filter(final ContainerRequestContext context) throws IOException { final long id = _id.incrementAndGet(); context.setProperty(LOGGING_ID_PROPERTY, id); final StringBuilder b = new StringBuilder(); printRequestLine(b, "Server has received a request", id, context.getMethod(), context.getUriInfo().getRequestUri()); printPrefixedHeaders(b, id, REQUEST_PREFIX, context.getHeaders()); if (printEntity && context.hasEntity() && isSupportPrintType(context.getMediaType())) { context.setEntityStream( logInboundEntity(b, context.getEntityStream(), MessageUtils.getCharset(context.getMediaType()))); } log(b); }
Example #3
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 #4
Source File: MaskingLoggingFilter.java From gitlab4j-api with MIT License | 6 votes |
@Override public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { if (!logger.isLoggable(level)) { return; } final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder sb = new StringBuilder(); printResponseLine(sb, "Received server response", id, responseContext.getStatus()); printHeaders(sb, id, RESPONSE_PREFIX, responseContext.getHeaders()); if (responseContext.hasEntity() && maxEntitySize > 0) { responseContext.setEntityStream(logResponseEntity(sb, responseContext.getEntityStream(), MessageUtils.getCharset(responseContext.getMediaType()))); } log(sb); }
Example #5
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 #6
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 #7
Source File: LoggingFilter.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Override public void filter(final ContainerRequestContext context) throws IOException { final Stopwatch stopwatch = Stopwatch.createStarted(); final UUID id = UUID.randomUUID(); MDC.put(MDC_ID, id.toString()); MDC.put(MDC_RELEASE_HASH, releaseHash); MDC.put(MDC_PRE_LOG, "true"); //Log a very minimal message. Mostly to make sure that we notice requests that never log in the response filter LOG.info("> " + context.getMethod() + " " + context.getUriInfo().getRequestUri().toASCIIString()); MDC.remove(MDC_PRE_LOG); context.setProperty(STOPWATCH_PROPERTY, stopwatch); if (context.hasEntity()) { context.setEntityStream( addInboundEntityToMdc(context.getEntityStream(), MessageUtils.getCharset(context.getMediaType())) ); } }
Example #8
Source File: StructuredEventFilter.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public void filter(ContainerRequestContext requestContext) throws IOException { boolean loggingEnabled = isLoggingEnabled(requestContext); requestContext.setProperty(LOGGING_ENABLED_PROPERTY, loggingEnabled); if (loggingEnabled) { requestContext.setProperty(REQUEST_TIME, System.currentTimeMillis()); StringBuilder body = new StringBuilder(); requestContext.setEntityStream(logInboundEntity(body, requestContext.getEntityStream(), MessageUtils.getCharset(requestContext.getMediaType()))); requestContext.setProperty(REST_PARAMS, getRequestUrlParameters(requestContext)); requestContext.setProperty(REQUEST_DETAILS, createRequestDetails(requestContext, body.toString())); } }