@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { System.out.println("WebApplicationExceptionFilter.postFilter() enter"); if (responseContext.hasEntity() && responseContext.getEntity().equals("Response Exception")) { throw new WebApplicationException(Response.Status.OK); } System.out.println("WebApplicationExceptionFilter.postFilter() exit"); } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { if (responseContext.hasEntity()) { Exception e = (Exception) responseContext.getEntity(); if (exceptionClass.isAssignableFrom(e.getClass()) || (e.getCause() != null && exceptionClass.isAssignableFrom(e.getCause().getClass()))) { meter.mark(); } responseContext.setEntity(null); responseContext.getHeaders().add("X-Exceptions-Thrown", e.toString() + " : " + meter.getCount()); } } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { if (responseContext.hasEntity()) { responseContext.setEntity("" + responseContext.getEntity() + "NAM_MATCH_OUT", null, MediaType.TEXT_PLAIN_TYPE); } } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { if (responseContext.hasEntity()) { responseContext.setEntity("" + responseContext.getEntity() + "PRE_MATCH_OUT", null, MediaType.TEXT_PLAIN_TYPE); } } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { if (responseContext.hasEntity()) { responseContext.setEntity("" + responseContext.getEntity() + "DYN_MATCH_OUT", null, MediaType.TEXT_PLAIN_TYPE); } } }
@Override public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { if (!response.hasEntity()) { return;
@Override public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { if (!response.hasEntity()) { return;
@Override public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) throws IOException { final long id = aid.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Server responded with a response", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getStringHeaders()); if (printEntity && responseContext.hasEntity()) { final OutputStream stream = new LoggingStream(b, responseContext.getEntityStream()); responseContext.setEntityStream(stream); requestContext.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 ContainerRequestContext requestContext, final ContainerResponseContext 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 b = new StringBuilder(); printResponseLine(b, "Server responded with a response", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getStringHeaders()); if (responseContext.hasEntity() && printEntity(verbosity, responseContext.getMediaType())) { final OutputStream stream = new LoggingStream(b, responseContext.getEntityStream()); responseContext.setEntityStream(stream); requestContext.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 ContainerRequestContext requestContext, final ContainerResponseContext 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 b = new StringBuilder(); printResponseLine(b, "Server responded with a response", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getStringHeaders()); if (responseContext.hasEntity() && printEntity(verbosity, responseContext.getMediaType())) { final OutputStream stream = new LoggingStream(b, responseContext.getEntityStream()); responseContext.setEntityStream(stream); requestContext.setProperty(ENTITY_LOGGER_PROPERTY, stream); // not calling log(b) here - it will be called by the interceptor } else { log(b); } } }
@Override public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { if (!response.hasEntity()) { return;
@Override public long getLength() { int res = ctx.getLength(); if (res < 0) { if (ctx.hasEntity()) { res = ctx.getEntity().toString().length(); } } return res; }
@Override public long getLength() { int res = ctx.getLength(); if (res < 0) { if (ctx.hasEntity()) { res = ctx.getEntity().toString().length(); } } return res; }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { if (responseContext.hasEntity()) { Exception e = (Exception) responseContext.getEntity(); if (exceptionClass.isAssignableFrom(e.getClass()) || (e.getCause() != null && exceptionClass.isAssignableFrom(e.getCause().getClass()))) { meter.mark(); } responseContext.setEntity(null); responseContext.getHeaders().add("X-Exceptions-Thrown", e.toString() + " : " + meter.getCount()); } } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { if (responseContext.hasEntity()) { Exception e = (Exception) responseContext.getEntity(); if (exceptionClass.isAssignableFrom(e.getClass()) || (e.getCause() != null && exceptionClass.isAssignableFrom(e.getCause().getClass()))) { meter.mark(); } responseContext.setEntity(null); responseContext.getHeaders().add("X-Exceptions-Thrown", e.toString() + " : " + meter.getCount()); } } }
@Override public void filter(final ContainerRequestContext request, final ContainerResponseContext response) { final RawHttpResponse rawHttpResponse = new LocalResponse(response); if (response.hasEntity()) { request.setProperty(RESPONSE, rawHttpResponse); } else { read(request::getProperty, CORRELATOR, Correlator.class) .ifPresent(throwingConsumer(correlator -> correlator.write(rawHttpResponse))); } }
private ContainerResponseContext createResponseMock(Object entity, MultivaluedMap<String, Object> headers) { ContainerResponseContext response = mock(ContainerResponseContext.class); when(response.hasEntity()).thenReturn(entity != null); when(response.getEntity()).thenReturn(entity); when(response.getHeaders()).thenReturn(headers); return response; }
@Override public void filter(ContainerRequestContext req, ContainerResponseContext resp) throws IOException { if (resp.hasEntity() && (resp.getEntity() instanceof Status)) { Status status = (Status) resp.getEntity(); int code = (Status.State.UP == status.getState()) ? 200 : 503; resp.setStatus(code); resp.setEntity(status.toJson()); resp.getHeaders().putSingle("Content-Type", MediaType.APPLICATION_JSON); } }
@Override public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) throws IOException { final long id = aid.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Server responded with a response", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getStringHeaders()); if (printEntity && responseContext.hasEntity()) { final OutputStream stream = new LoggingStream(b, responseContext.getEntityStream()); responseContext.setEntityStream(stream); requestContext.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 ContainerRequestContext requestContext, final ContainerResponseContext responseContext) throws IOException { final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY); final long id = requestId != null ? (Long) requestId : _id.incrementAndGet(); final StringBuilder b = new StringBuilder(); printResponseLine(b, "Server responded with a response", id, responseContext.getStatus()); printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getStringHeaders()); if (printEntity && responseContext.hasEntity()) { final OutputStream stream = new LoggingStream(b, responseContext.getEntityStream()); responseContext.setEntityStream(stream); requestContext.setProperty(ENTITY_LOGGER_PROPERTY, stream); // not calling log(b) here - it will be called by the interceptor } else { log(b); } }