private void mergeIncomingContextToBackend(HttpServletRequest request) { final Enumeration headers = request.getHeaders(HTTP_HEADER_NAME); if (headers == null) { throw new IllegalStateException("Could not read headers with name '" + HTTP_HEADER_NAME + "'. The access seem to be forbidden by the container."); } final Map<String, String> parsed = new HashMap<String, String>(); while (headers.hasMoreElements()) { parsed.putAll(transportSerialization.parse((String) headers.nextElement())); } final Map<String, String> filtered = backend.getConfiguration().filterDeniedParams(parsed, IncomingRequest); backend.putAll(filtered); } }
private void handleHttpMessage(final Message message, final TraceeFilterConfiguration filterConfiguration) { final Map<String, List<String>> requestHeaders = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS)); if (requestHeaders != null && !requestHeaders.isEmpty()) { final List<String> traceeHeader = requestHeaders.get(TraceeConstants.TPIC_HEADER); if (traceeHeader != null && !traceeHeader.isEmpty()) { final Map<String, String> parsedContext = httpJsonSerializer.parse(traceeHeader); backend.putAll(filterConfiguration.filterDeniedParams(parsedContext, channel)); } } }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { if (invocation instanceof ReflectiveMethodInvocation) { final ReflectiveMethodInvocation methodInvocation = (ReflectiveMethodInvocation) invocation; final Object tpicObj = methodInvocation.getUserAttribute(TraceeConstants.TPIC_HEADER); if (tpicObj instanceof Map) { @SuppressWarnings("unchecked") final Map<? extends String, ? extends String> tpic = (Map<? extends String, ? extends String>) tpicObj; backend.putAll(tpic); } } try { return invocation.proceed(); } finally { backend.clear(); } } }
@Override public final void process(HttpResponse response, HttpContext context) { final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile); final Iterator<Header> headerIterator = response.headerIterator(TraceeConstants.TPIC_HEADER); if (headerIterator != null && headerIterator.hasNext() && filterConfiguration.shouldProcessContext(IncomingResponse)) { final List<String> stringTraceeHeaders = new ArrayList<>(); while (headerIterator.hasNext()) { stringTraceeHeaders.add(headerIterator.next().getValue()); } backend.putAll(filterConfiguration.filterDeniedParams(transportSerialization.parse(stringTraceeHeaders), IncomingResponse)); } } }
@Override public final void process(HttpResponse response, HttpContext context) { final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile); final Header[] responseHeaders = response.getHeaders(TraceeConstants.TPIC_HEADER); 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)); } } }
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)); } }
@Override public void jobToBeExecuted(JobExecutionContext context) { final TraceeFilterConfiguration configuration = backend.getConfiguration(profile); if (configuration.shouldProcessContext(AsyncProcess)) { @SuppressWarnings("unchecked") final Map<String, String> traceeContext = (Map<String, String>) context.getMergedJobDataMap().get(TraceeConstants.TPIC_HEADER); if (traceeContext != null && !traceeContext.isEmpty()) { final Map<String, String> filteredContext = configuration.filterDeniedParams(traceeContext, AsyncProcess); backend.putAll(filteredContext); } } Utilities.generateInvocationIdIfNecessary(backend); }
private void httpRequestInitialized(final HttpServletRequest request) { final TraceeFilterConfiguration configuration = backend.getConfiguration(); if (configuration.shouldProcessContext(IncomingRequest)) { final Enumeration<String> headers = request.getHeaders(HTTP_HEADER_NAME); if (headers != null && headers.hasMoreElements()) { final Map<String, String> contextMap = transportSerialization.parse(Collections.list(headers)); backend.putAll(backend.getConfiguration().filterDeniedParams(contextMap, IncomingRequest)); } } Utilities.generateInvocationIdIfNecessary(backend); final HttpSession session = request.getSession(false); if (session != null) { Utilities.generateSessionIdIfNecessary(backend, session.getId()); } } }
@Override public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object o) { final TraceeFilterConfiguration configuration = backend.getConfiguration(profileName); if (configuration.shouldProcessContext(IncomingRequest)) { @SuppressWarnings("unchecked") final Enumeration<String> headers = request.getHeaders(incomingHeaderName); if (headers != null && headers.hasMoreElements()) { final Map<String, String> parsedContext = httpHeaderSerialization.parse(Collections.list(headers)); backend.putAll(configuration.filterDeniedParams(parsedContext, IncomingResponse)); } } Utilities.generateInvocationIdIfNecessary(backend); final HttpSession session = request.getSession(false); if (session != null) { Utilities.generateSessionIdIfNecessary(backend, session.getId()); } // We add the current TPIC to the response. If the response is commited before we can replace the values with the current state // the current state is on the wire. -- better than nothing :-) (See #96) writeHeaderIfUncommitted(response); return true; }
private void handleSoapMessage(final SoapMessage message, final TraceeFilterConfiguration filterConfiguration) { final Header soapHeader = message.getHeader(TraceeConstants.SOAP_HEADER_QNAME); if (soapHeader != null) { final Map<String, String> parsedContext = httpSoapSerializer.parseTpicHeader((Element) soapHeader.getObject()); backend.putAll(filterConfiguration.filterDeniedParams(parsedContext, channel)); } } }
/** * 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)); } } }
/** * This method handles the incoming request */ @Override public void filter(final ContainerRequestContext containerRequestContext) { if (backend.getConfiguration().shouldProcessContext(IncomingRequest)) { final List<String> serializedTraceeHeaders = containerRequestContext.getHeaders().get(TraceeConstants.TPIC_HEADER); if (serializedTraceeHeaders != null && !serializedTraceeHeaders.isEmpty()) { final Map<String, String> parsed = transportSerialization.parse(serializedTraceeHeaders); backend.putAll(backend.getConfiguration().filterDeniedParams(parsed, IncomingRequest)); } } Utilities.generateInvocationIdIfNecessary(backend); }
@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); } } }
/** * Incoming messages */ @Override public MessageProperties toMessageProperties(AMQP.BasicProperties source, Envelope envelope, String charset) { final MessageProperties messageProperties = super.toMessageProperties(source, envelope, charset); final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile); if (filterConfiguration.shouldProcessContext(AsyncProcess)) { // Values are stored as type of LongStringHelper.ByteArrayLongString - but it's private final Map<String, String> traceeContextMap = transformToTraceeContextMap( (Map<String, ?>) messageProperties.getHeaders().get(TPIC_HEADER)); if (traceeContextMap != null && !traceeContextMap.isEmpty()) { backend.putAll(filterConfiguration.filterDeniedParams(traceeContextMap, AsyncProcess)); } } Utilities.generateInvocationIdIfNecessary(backend); return messageProperties; }
@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); }
protected final void handleIncoming(final SOAPMessageContext context) { final SOAPMessage msg = context.getMessage(); if (msg != null && traceeBackend.getConfiguration().shouldProcessContext(OutgoingRequest)) { try { final SOAPHeader header = msg.getSOAPHeader(); if (header != null) { final Map<String, String> parsedContext = transportSerialization.parseSoapHeader(header); traceeBackend.putAll(traceeBackend.getConfiguration().filterDeniedParams(parsedContext, OutgoingRequest)); } } catch (final SOAPException e) { logger.warn("Error during precessing of inbound soap header: " + e.getMessage()); logger.debug("Detailed: Error during precessing of inbound soap header: {}", e.getMessage(), e); } } }
protected final void handleIncoming(final SOAPMessageContext context) { final SOAPMessage msg = context.getMessage(); if (msg != null && traceeBackend.getConfiguration().shouldProcessContext(OutgoingRequest)) { try { final SOAPHeader header = msg.getSOAPHeader(); if (header != null) { final Map<String, String> parsedContext = transportSerialization.parseSoapHeader(header); traceeBackend.putAll(traceeBackend.getConfiguration().filterDeniedParams(parsedContext, OutgoingRequest)); } } catch (final SOAPException e) { logger.warn("Error during precessing of inbound soap header: " + e.getMessage()); logger.debug("Detailed: Error during precessing of inbound soap header: {}", e.getMessage(), e); } } }
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)); } } } }
protected final void handleIncoming(SOAPMessageContext context) { final SOAPMessage soapMessage = context.getMessage(); try { final SOAPHeader header = soapMessage.getSOAPHeader(); if (header != null && traceeBackend.getConfiguration().shouldProcessContext(IncomingRequest)) { final Map<String, String> parsedContext = transportSerialization.parseSoapHeader(header); final Map<String, String> filteredContext = traceeBackend.getConfiguration().filterDeniedParams(parsedContext, IncomingRequest); traceeBackend.putAll(filteredContext); } } catch (final SOAPException e) { logger.warn("Error during precessing of inbound soap header: {}", e.getMessage()); logger.debug("Detailed: Error during precessing of inbound soap header: {}", e.getMessage(), e); } Utilities.generateInvocationIdIfNecessary(traceeBackend); }
protected final void handleIncoming(SOAPMessageContext context) { final SOAPMessage soapMessage = context.getMessage(); try { final SOAPHeader header = soapMessage.getSOAPHeader(); if (header != null && traceeBackend.getConfiguration().shouldProcessContext(IncomingRequest)) { final Map<String, String> parsedContext = transportSerialization.parseSoapHeader(header); final Map<String, String> filteredContext = traceeBackend.getConfiguration().filterDeniedParams(parsedContext, IncomingRequest); traceeBackend.putAll(filteredContext); } } catch (final SOAPException e) { logger.warn("Error during precessing of inbound soap header: {}", e.getMessage()); logger.debug("Detailed: Error during precessing of inbound soap header: {}", e.getMessage(), e); } Utilities.generateInvocationIdIfNecessary(traceeBackend); }