org.javasimon.javaee
Class SimonServletFilterUtils

java.lang.Object
  extended by org.javasimon.javaee.SimonServletFilterUtils

public class SimonServletFilterUtils
extends Object

Various supporting utility methods for SimonServletFilter.

Author:
virgo47@gmail.com

Field Summary
private static Replacer TO_DOT_PATTERN
          Regex replacer for any number of slashes or dots for a single dot.
 
Constructor Summary
SimonServletFilterUtils()
           
 
Method Summary
private static StopwatchSource<javax.servlet.http.HttpServletRequest> createMonitorForSourceSpecifiedClass(String stopwatchSourceClass, Manager manager)
           
private static StopwatchSource<javax.servlet.http.HttpServletRequest> createMonitorSource(String stopwatchSourceClass, Manager manager)
           
(package private) static Replacer createUnallowedCharsReplacer(String replacement)
          Creates new replacer for unallowed characters in the URL.
static String getSimonName(String uri, Replacer unallowedCharacterReplacer)
          Returns Simon name for the specified request (local name without any configured prefix).
static RequestReporter initRequestReporter(javax.servlet.FilterConfig filterConfig)
          Returns RequestReporter for the class specified for context parameter SimonServletFilter.INIT_PARAM_REQUEST_REPORTER_CLASS.
protected static StopwatchSource<javax.servlet.http.HttpServletRequest> initStopwatchSource(javax.servlet.FilterConfig filterConfig, Manager manager)
          Create and initialize the stopwatch source depending on the filter init parameters.
private static void injectSimonPrefixIntoMonitorSource(javax.servlet.FilterConfig filterConfig, MonitorSource<javax.servlet.http.HttpServletRequest,Stopwatch> stopwatchSource)
           
private static StopwatchSource<javax.servlet.http.HttpServletRequest> monitorSourceNewInstance(Manager manager, Class<?> monitorClass)
           
private static StopwatchSource<javax.servlet.http.HttpServletRequest> wrapMonitorSourceWithCacheIfNeeded(StopwatchSource<javax.servlet.http.HttpServletRequest> stopwatchSource, String cache)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TO_DOT_PATTERN

private static final Replacer TO_DOT_PATTERN
Regex replacer for any number of slashes or dots for a single dot.

Constructor Detail

SimonServletFilterUtils

public SimonServletFilterUtils()
Method Detail

createUnallowedCharsReplacer

static Replacer createUnallowedCharsReplacer(String replacement)
Creates new replacer for unallowed characters in the URL. This inverts character group for name pattern (SimonUtils.NAME_PATTERN_CHAR_CLASS_CONTENT) and replaces its dot with slash too (dots are to be replaced, slashs preserved in this step of URL processing).

Parameters:
replacement - replacement string (for every unallowed character)
Returns:
compiled pattern matching characters to remove from the URL

getSimonName

public static String getSimonName(String uri,
                                  Replacer unallowedCharacterReplacer)
Returns Simon name for the specified request (local name without any configured prefix). By default dots and all non-simon-name compliant characters are removed first, then all slashes are switched to dots (repeating slashes make one dot).

Parameters:
uri - request URI
unallowedCharacterReplacer - replacer for characters that are not allowed in Simon name
Returns:
local part of the Simon name for the request URI (without prefix)

initStopwatchSource

protected static StopwatchSource<javax.servlet.http.HttpServletRequest> initStopwatchSource(javax.servlet.FilterConfig filterConfig,
                                                                                            Manager manager)
Create and initialize the stopwatch source depending on the filter init parameters. Both monitor source class (SimonServletFilter.INIT_PARAM_STOPWATCH_SOURCE_CLASS and whether to cache results (SimonServletFilter.INIT_PARAM_STOPWATCH_SOURCE_CACHE) can be adjusted.

Parameters:
filterConfig - Filter configuration
Returns:
Stopwatch source

createMonitorSource

private static StopwatchSource<javax.servlet.http.HttpServletRequest> createMonitorSource(String stopwatchSourceClass,
                                                                                          Manager manager)

injectSimonPrefixIntoMonitorSource

private static void injectSimonPrefixIntoMonitorSource(javax.servlet.FilterConfig filterConfig,
                                                       MonitorSource<javax.servlet.http.HttpServletRequest,Stopwatch> stopwatchSource)

wrapMonitorSourceWithCacheIfNeeded

private static StopwatchSource<javax.servlet.http.HttpServletRequest> wrapMonitorSourceWithCacheIfNeeded(StopwatchSource<javax.servlet.http.HttpServletRequest> stopwatchSource,
                                                                                                         String cache)

createMonitorForSourceSpecifiedClass

private static StopwatchSource<javax.servlet.http.HttpServletRequest> createMonitorForSourceSpecifiedClass(String stopwatchSourceClass,
                                                                                                           Manager manager)

monitorSourceNewInstance

private static StopwatchSource<javax.servlet.http.HttpServletRequest> monitorSourceNewInstance(Manager manager,
                                                                                               Class<?> monitorClass)
                                                                                        throws InstantiationException,
                                                                                               IllegalAccessException
Throws:
InstantiationException
IllegalAccessException

initRequestReporter

public static RequestReporter initRequestReporter(javax.servlet.FilterConfig filterConfig)
Returns RequestReporter for the class specified for context parameter SimonServletFilter.INIT_PARAM_REQUEST_REPORTER_CLASS.



Copyright © 2013. All Rights Reserved.