final void doFilterHttp(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { final TraceeFilterConfiguration configuration = backend.getConfiguration(profile); try { // we need to eagerly write ResponseHeaders since the inner servlets may flush the output stream // and writing of response headers become impossible afterwards. This is a best effort trade-off. writeContextToResponse(response, configuration); filterChain.doFilter(request, response); } finally { if (!response.isCommitted()) { writeContextToResponse(response, configuration); } } }
@SuppressWarnings("unchecked") public void beforeProcessing(Message message) throws JMSException { if (backend.getConfiguration().shouldProcessContext(AsyncProcess)) { final Object encodedTraceeContext = message.getObjectProperty(TraceeConstants.JMS_HEADER_NAME); if (encodedTraceeContext != null) { final Map<String, String> contextFromMessage = (Map<String, String>) encodedTraceeContext; final Map<String, String> filteredContext = backend.getConfiguration().filterDeniedParams(contextFromMessage, AsyncProcess); backend.putAll(filteredContext); } } }
void cleanUp() { if (backend.getConfiguration().shouldProcessContext(AsyncProcess)) { backend.clear(); } }
void cleanUp() { if (backend.getConfiguration().shouldProcessContext(AsyncProcess)) { backend.clear(); } }
/** * Writes the current TraceeContext to the given javaee message. * This method is idempotent. */ protected void writeTraceeContextToMessage(Message message) throws JMSException { if (!backend.isEmpty() && backend.getConfiguration().shouldProcessContext(AsyncDispatch)) { final Map<String, String> filteredContext = backend.getConfiguration().filterDeniedParams(backend, AsyncDispatch); message.setObjectProperty(TraceeConstants.JMS_HEADER_NAME, filteredContext); } }
/** * This method handles the incoming response */ @Override public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) { final List<String> serializedHeaders = responseContext.getHeaders().get(TraceeConstants.TPIC_HEADER); if (serializedHeaders != null && backend.getConfiguration().shouldProcessContext(IncomingResponse)) { final Map<String, String> parsed = transportSerialization.parse(serializedHeaders); backend.putAll(backend.getConfiguration().filterDeniedParams(parsed, IncomingResponse)); } } }
private void httpRequestInitialized(HttpServletRequest request) { final TraceeFilterConfiguration configuration = backend.getConfiguration(); if (configuration.shouldProcessContext(IncomingRequest)) { mergeIncomingContextToBackend(request); } Utilities.generateRequestIdIfNecessary(backend); final HttpSession session = request.getSession(false); if (session != null) { Utilities.generateSessionIdIfNecessary(backend, session.getId()); } }
/** * Generate invocation id if it doesn't exist in TraceeBackend and configuration asks for one * * @param backend Currently used TraceeBackend */ public static void generateInvocationIdIfNecessary(final TraceeBackend backend) { if (backend != null && !backend.containsKey(TraceeConstants.INVOCATION_ID_KEY) && backend.getConfiguration().shouldGenerateInvocationId()) { backend.put(TraceeConstants.INVOCATION_ID_KEY, Utilities.createRandomAlphanumeric(backend.getConfiguration().generatedInvocationIdLength())); } }
/** * Generate session id hash if it doesn't exist in TraceeBackend and configuration asks for one * * @param backend Currently used TraceeBackend * @param sessionId Current http sessionId */ public static void generateSessionIdIfNecessary(final TraceeBackend backend, final String sessionId) { if (backend != null && !backend.containsKey(TraceeConstants.SESSION_ID_KEY) && backend.getConfiguration().shouldGenerateSessionId()) { backend.put(TraceeConstants.SESSION_ID_KEY, Utilities.createAlphanumericHash(sessionId, backend.getConfiguration().generatedSessionIdLength())); } } }
/** * This method handles the outgoing response */ @Override public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) { if (backend.getConfiguration().shouldProcessContext(OutgoingResponse)) { final Map<String, String> filtered = backend.getConfiguration().filterDeniedParams(backend.copyToMap(), OutgoingResponse); responseContext.getHeaders().putSingle(TraceeConstants.TPIC_HEADER, transportSerialization.render(filtered)); } backend.clear(); } }
@SuppressWarnings("unchecked") public void beforeProcessing(final Message message) throws JMSException { if (backend.getConfiguration().shouldProcessContext(AsyncProcess)) { final String encodedTraceeContext = message.getStringProperty(TraceeConstants.TPIC_HEADER); if (encodedTraceeContext != null) { final Map<String, String> contextFromMessage = httpHeaderSerialization.parse(singletonList(encodedTraceeContext)); backend.putAll(backend.getConfiguration().filterDeniedParams(contextFromMessage, AsyncProcess)); } } Utilities.generateInvocationIdIfNecessary(backend); }
/** * This method handles the outgoing request */ @Override public void filter(final ClientRequestContext requestContext) { if (!backend.isEmpty() && backend.getConfiguration().shouldProcessContext(OutgoingRequest)) { final Map<String, String> filtered = backend.getConfiguration().filterDeniedParams(backend.copyToMap(), OutgoingRequest); requestContext.getHeaders().putSingle(TraceeConstants.TPIC_HEADER, transportSerialization.render(filtered)); } }
private void writeContextToResponse(HttpServletResponse response, TraceeFilterConfiguration configuration) { if (configuration.shouldProcessContext(OutgoingResponse) && !backend.isEmpty()) { final Map<String, String> filteredContext = backend.getConfiguration(profile).filterDeniedParams(backend, OutgoingResponse); response.setHeader(HTTP_HEADER_NAME, transportSerialization.render(filteredContext)); } }
private void postResponse(HttpMethod httpMethod) { if (!httpMethod.isRequestSent()) return; final Header[] responseHeaders = httpMethod.getResponseHeaders(TraceeConstants.TPIC_HEADER); final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile); if (responseHeaders != null && responseHeaders.length > 0 && filterConfiguration.shouldProcessContext(IncomingResponse)) { final List<String> stringTraceeHeaders = new ArrayList<>(); for (Header header : responseHeaders) { stringTraceeHeaders.add(header.getValue()); } backend.putAll(filterConfiguration.filterDeniedParams(transportSerialization.parse(stringTraceeHeaders), IncomingResponse)); } }
/** * Writes the current TraceeContext to the given javaee message. * This method is idempotent. */ protected void writeTraceeContextToMessage(Message message) throws JMSException { if (!backend.isEmpty() && backend.getConfiguration().shouldProcessContext(AsyncDispatch)) { final Map<String, String> filteredContext = backend.getConfiguration().filterDeniedParams(backend.copyToMap(), AsyncDispatch); final String contextAsString = httpHeaderSerialization.render(filteredContext); message.setStringProperty(TraceeConstants.TPIC_HEADER, contextAsString); } }
private void preRequest(final HttpRequest request) { final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile); if (!backend.isEmpty() && filterConfiguration.shouldProcessContext(OutgoingRequest)) { final Map<String, String> filteredParams = filterConfiguration.filterDeniedParams(backend.copyToMap(), OutgoingRequest); request.getHeaders().add(TraceeConstants.TPIC_HEADER, transportSerialization.render(filteredParams)); } }
@Override public final void process(final HttpRequest httpRequest, final HttpContext httpContext) { final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile); if (!backend.isEmpty() && filterConfiguration.shouldProcessContext(OutgoingRequest)) { final Map<String, String> filteredParams = filterConfiguration.filterDeniedParams(backend.copyToMap(), OutgoingRequest); httpRequest.setHeader(TraceeConstants.TPIC_HEADER, transportSerialization.render(filteredParams)); } } }
@Override public final void process(final HttpRequest httpRequest, final HttpContext httpContext) { final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile); if (!backend.isEmpty() && filterConfiguration.shouldProcessContext(OutgoingRequest)) { final Map<String, String> filteredParams = filterConfiguration.filterDeniedParams(backend.copyToMap(), OutgoingRequest); httpRequest.setHeader(TraceeConstants.TPIC_HEADER, transportSerialization.render(filteredParams)); } } }
private void postResponse(ClientHttpResponse response) { final List<String> headers = response.getHeaders().get(TraceeConstants.TPIC_HEADER); if (headers != null) { final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile); if (filterConfiguration.shouldProcessContext(IncomingResponse)) { backend.putAll(filterConfiguration.filterDeniedParams(transportSerialization.parse(headers), IncomingResponse)); } } } }
private void preRequest(HttpMethod httpMethod) { final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile); if (!backend.isEmpty() && filterConfiguration.shouldProcessContext(OutgoingRequest)) { final Map<String, String> filteredParams = filterConfiguration.filterDeniedParams(backend.copyToMap(), OutgoingRequest); httpMethod.setRequestHeader(TraceeConstants.TPIC_HEADER, transportSerialization.render(filteredParams)); } }