org.javasimon.javaee
Class HttpStopwatchSource

java.lang.Object
  extended by org.javasimon.source.AbstractStopwatchSource<javax.servlet.http.HttpServletRequest>
      extended by org.javasimon.javaee.HttpStopwatchSource
All Implemented Interfaces:
MonitorSource<javax.servlet.http.HttpServletRequest,Stopwatch>, StopwatchSource<javax.servlet.http.HttpServletRequest>

public class HttpStopwatchSource
extends AbstractStopwatchSource<javax.servlet.http.HttpServletRequest>

Provide stopwatch source for HTTP Servlet request. Used by SimonServletFilter as default stopwatch source. Can be overridden to customize monitored HTTP Requests and their related Simon name.

To select which HTTP Request should be monitored method isMonitored(javax.servlet.http.HttpServletRequest) can be overridden. Default implementation monitors everything except for typical resource-like requests (images, JS/CSS, ...).

Author:
gquintana, Richard "Virgo" Richter

Field Summary
static String DEFAULT_SIMON_PREFIX
          Default prefix for web filter Simons if no "prefix" init parameter is used.
private  Replacer jsessionParameterReplacer
           
private  String prefix
          Simon prefix, can be set to null.
private  Replacer trailingStuffReplacer
           
private  Replacer unallowedCharacterReplacer
           
 
Constructor Summary
HttpStopwatchSource(Manager manager)
           
 
Method Summary
 Stopwatch getMonitor(javax.servlet.http.HttpServletRequest request)
          Get a stopwatch for given HTTP request.
protected  String getMonitorName(javax.servlet.http.HttpServletRequest request)
          Returns Simon name for the specified HTTP request with the specified prefix.
 String getPrefix()
           
 String getReplaceUnallowed()
           
 boolean isMonitored(javax.servlet.http.HttpServletRequest httpServletRequest)
          Indicates whether the HTTP Request should be monitored - method is intended for override.
static StopwatchSource<javax.servlet.http.HttpServletRequest> newCacheStopwatchSource(StopwatchSource<javax.servlet.http.HttpServletRequest> stopwatchSource)
          Wraps given stop watch source in a cache.
protected  String removeJSessionIdFromUri(String uri)
          Removes JSESSIONID parameter from URI.
protected  String removeTrailingStuff(String uri)
          Removes any trailing slashes followed by other characters if none of them is alphabetic.
protected  String requestToStringForMonitorName(javax.servlet.http.HttpServletRequest request)
          Performs the first step in getting the monitor name from the specified HTTP request - here any custom ignore logic should happen.
 void setPrefix(String prefix)
           
 void setReplaceUnallowed(String replaceUnallowed)
           
 
Methods inherited from class org.javasimon.source.AbstractStopwatchSource
getManager, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SIMON_PREFIX

public static final String DEFAULT_SIMON_PREFIX
Default prefix for web filter Simons if no "prefix" init parameter is used.

See Also:
Constant Field Values

prefix

private String prefix
Simon prefix, can be set to null.


unallowedCharacterReplacer

private Replacer unallowedCharacterReplacer

jsessionParameterReplacer

private Replacer jsessionParameterReplacer

trailingStuffReplacer

private Replacer trailingStuffReplacer
Constructor Detail

HttpStopwatchSource

public HttpStopwatchSource(Manager manager)
Method Detail

getPrefix

public String getPrefix()

setPrefix

public void setPrefix(String prefix)

getReplaceUnallowed

public String getReplaceUnallowed()

setReplaceUnallowed

public void setReplaceUnallowed(String replaceUnallowed)

getMonitorName

protected final String getMonitorName(javax.servlet.http.HttpServletRequest request)
Returns Simon name for the specified HTTP request with the specified prefix. By default it contains URI without parameters with all slashes replaced for dots (slashes then determines position in Simon hierarchy). Method can NOT be overridden, but some of the following steps can:
  1. the request is transformed to the string (requestToStringForMonitorName(javax.servlet.http.HttpServletRequest), can be overridden),
  2. the characters that are not allowed as part of the Simon name are replaced with underscore (_) - replacement regex can be changed with setReplaceUnallowed(String),
  3. any subsequent slashes and dots are replaced with a single dot (Manager.HIERARCHY_DELIMITER)

Specified by:
getMonitorName in class AbstractStopwatchSource<javax.servlet.http.HttpServletRequest>
Parameters:
request - HTTP request
Returns:
fully qualified name of the Simon
See Also:
requestToStringForMonitorName(javax.servlet.http.HttpServletRequest)

requestToStringForMonitorName

protected String requestToStringForMonitorName(javax.servlet.http.HttpServletRequest request)
Performs the first step in getting the monitor name from the specified HTTP request - here any custom ignore logic should happen. By default the name is URI (without parameters - see HttpServletRequest.getRequestURI()) with JSessionID removed (see removeJSessionIdFromUri(String)) and any trailing stuff removed (see removeTrailingStuff(String)). This method can be overridden for two typical reasons:

Parameters:
request - HTTP request
Returns:
preprocessed URI that will be converted to the Simon name
See Also:
getMonitorName(javax.servlet.http.HttpServletRequest), removeJSessionIdFromUri(String)

removeJSessionIdFromUri

protected String removeJSessionIdFromUri(String uri)
Removes JSESSIONID parameter from URI. By default it is not necessary to handle parameters, as incoming URI already is without parameters, but JSESSIONID sometimes come before parameters in other forms and this method tries to remove such forms.

Called by default implementation of requestToStringForMonitorName(javax.servlet.http.HttpServletRequest) and extracted so it can be used by any overriding implementation of the same method. Method can be overridden if the default behavior is not sufficient.

Parameters:
uri - preprocessed URI that may contain JSessionID
Returns:
preprocessed URI without JSessionID
See Also:
requestToStringForMonitorName(javax.servlet.http.HttpServletRequest)

removeTrailingStuff

protected String removeTrailingStuff(String uri)
Removes any trailing slashes followed by other characters if none of them is alphabetic. This should take care of some REST parameters (numeric id-s) and it also removes trailing slashes to avoid empty local Simon names which is forbidden.

Called by default implementation of requestToStringForMonitorName(javax.servlet.http.HttpServletRequest) and extracted so it can be used by any overriding implementation of the same method. Method can be overridden if the default behavior is not sufficient.

Parameters:
uri - preprocessed URI that may contain JSessionID
Returns:
preprocessed URI without JSessionID
See Also:
requestToStringForMonitorName(javax.servlet.http.HttpServletRequest)

isMonitored

public boolean isMonitored(javax.servlet.http.HttpServletRequest httpServletRequest)
Indicates whether the HTTP Request should be monitored - method is intended for override. Default behavior ignores URIs ending with .css, .png, .gif, .jpg and .js (ignores casing).

Specified by:
isMonitored in interface MonitorSource<javax.servlet.http.HttpServletRequest,Stopwatch>
Overrides:
isMonitored in class AbstractStopwatchSource<javax.servlet.http.HttpServletRequest>
Parameters:
httpServletRequest - HTTP Request
Returns:
true to enable request monitoring, false either

getMonitor

public Stopwatch getMonitor(javax.servlet.http.HttpServletRequest request)
Get a stopwatch for given HTTP request.

Specified by:
getMonitor in interface MonitorSource<javax.servlet.http.HttpServletRequest,Stopwatch>
Overrides:
getMonitor in class AbstractStopwatchSource<javax.servlet.http.HttpServletRequest>
Parameters:
request - Method HTTP request
Returns:
Stopwatch for the HTTP request

newCacheStopwatchSource

public static StopwatchSource<javax.servlet.http.HttpServletRequest> newCacheStopwatchSource(StopwatchSource<javax.servlet.http.HttpServletRequest> stopwatchSource)
Wraps given stop watch source in a cache.

Parameters:
stopwatchSource - Stopwatch source
Returns:
Cached stopwatch source


Copyright © 2013. All Rights Reserved.