@Override public boolean shouldProcessParam(String paramName, Channel channel) { final String messageTypePropertyValue = getProfiledOrDefaultProperty(channel.name()); final List<Pattern> patterns = retrievePatternsForPropertyValue(messageTypePropertyValue); return anyPatternMatchesParamName(patterns, paramName); }
private boolean anyPatternMatchesParamName(Iterable<Pattern> patterns, String paramName) { for (Pattern pattern : patterns) { if (patternMatchesParamName(pattern, paramName)) return true; } return false; }
private PropertyChain getPropertyChain() { if (_lazyPropertyChain == null) { _lazyPropertyChain = PropertiesBasedTraceeFilterConfiguration.loadPropertyChain(); } return _lazyPropertyChain; }
public void injectContext(JobDataMap jobDataMap) { final TraceeFilterConfiguration configuration = backend.getConfiguration(profile); if (!backend.isEmpty() && configuration.shouldProcessContext(AsyncDispatch)) { jobDataMap.put(TraceeConstants.TPIC_HEADER, backend.getConfiguration(profile).filterDeniedParams(backend.copyToMap(), AsyncDispatch)); } } }
void cleanUp() { if (backend.getConfiguration().shouldProcessContext(AsyncProcess)) { backend.clear(); } }
/** * Loads a layered property chain based on: * <ol> * <li>System properties</li> * <li>merged entries from all {@code /META-INF/tracee.properties} files on the classpath (loaded in undefined order)</li> * <li>merged entries from all {@code /META-INF/tracee.default.properties} files on the classpath (loaded in undefined order)</li> * </ol> */ public static PropertyChain loadPropertyChain() { try { final Properties traceeDefaultFileProperties = new TraceePropertiesFileLoader().loadTraceeProperties(TraceePropertiesFileLoader.TRACEE_DEFAULT_PROPERTIES_FILE); final Properties traceeFileProperties = new TraceePropertiesFileLoader().loadTraceeProperties(TraceePropertiesFileLoader.TRACEE_PROPERTIES_FILE); return PropertyChain.build(System.getProperties(), traceeFileProperties, traceeDefaultFileProperties); } catch (IOException ioe) { throw new IllegalStateException("Could not load TraceeProperties: " + ioe.getMessage(), ioe); } }
@Override public int generatedInvocationIdLength() { return parseIntOrZero(getProfiledOrDefaultProperty(GENERATE_INVOCATION_ID)); }
@Override public boolean shouldProcessContext(final Channel channel) { final String messageTypePropertyValue = getProfiledOrDefaultProperty(channel.name()); return !Utilities.isNullOrEmptyString(messageTypePropertyValue); }
/** * 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())); } } }
@Override public boolean shouldGenerateSessionId() { return generatedSessionIdLength() > 0; }
@Override public boolean shouldGenerateInvocationId() { return generatedInvocationIdLength() > 0; }
private String getProfiledOrDefaultProperty(final String propertyName) { if (profileName != null && !Profile.DEFAULT.equals(profileName)) { final String profiledProperty = propertyChain.getProperty(PROFILED_PREFIX + profileName + '.' + propertyName); if (profiledProperty != null) return profiledProperty; } return propertyChain.getProperty(TRACEE_DEFAULT_PROFILE_PREFIX + propertyName); }
public static PropertyChain build(Properties... properties) { return new PropertyChain(Arrays.asList(properties)); }
private List<Pattern> retrievePatternsForPropertyValue(final String propertyValue) { if (propertyValue == null) { return Collections.emptyList(); } final List<Pattern> patterns = patternCache.get(propertyValue); if (patterns != null) { return patterns; } final List<Pattern> unmodPatterns = Collections.unmodifiableList(extractPatterns(propertyValue)); patternCache.put(propertyValue, unmodPatterns); return unmodPatterns; }
@Override public final TraceeFilterConfiguration getConfiguration(String profileName) { final String lookupProfile = profileName == null ? Profile.DEFAULT : profileName; TraceeFilterConfiguration filterConfiguration = configurationCache.get(lookupProfile); if (filterConfiguration == null) { filterConfiguration = new PropertiesBasedTraceeFilterConfiguration(getPropertyChain(), lookupProfile); configurationCache.put(lookupProfile, filterConfiguration); } return filterConfiguration; }
@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(); } }
@Override public int generatedSessionIdLength() { return parseIntOrZero(getProfiledOrDefaultProperty(GENERATE_SESSION_ID)); }
/** * 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); } }