GenericMonitoringFilter.java (moskito-moskito-2.9.3) | : | GenericMonitoringFilter.java (moskito-moskito-2.10.0) | ||
---|---|---|---|---|
package net.anotheria.moskito.web.filters; | package net.anotheria.moskito.web.filters; | |||
import net.anotheria.moskito.core.config.MoskitoConfiguration; | import net.anotheria.moskito.core.config.MoskitoConfiguration; | |||
import net.anotheria.moskito.core.config.MoskitoConfigurationHolder; | import net.anotheria.moskito.core.config.MoskitoConfigurationHolder; | |||
import net.anotheria.moskito.core.context.CurrentMeasurement; | ||||
import net.anotheria.moskito.core.context.MoSKitoContext; | import net.anotheria.moskito.core.context.MoSKitoContext; | |||
import net.anotheria.moskito.core.dynamic.EntryCountLimitedOnDemandStatsProducer ; | import net.anotheria.moskito.core.dynamic.EntryCountLimitedOnDemandStatsProducer ; | |||
import net.anotheria.moskito.core.dynamic.OnDemandStatsProducer; | import net.anotheria.moskito.core.dynamic.OnDemandStatsProducer; | |||
import net.anotheria.moskito.core.dynamic.OnDemandStatsProducerException; | import net.anotheria.moskito.core.dynamic.OnDemandStatsProducerException; | |||
import net.anotheria.moskito.core.predefined.Constants; | import net.anotheria.moskito.core.predefined.Constants; | |||
import net.anotheria.moskito.core.predefined.FilterStats; | import net.anotheria.moskito.core.predefined.FilterStats; | |||
import net.anotheria.moskito.core.predefined.FilterStatsFactory; | import net.anotheria.moskito.core.predefined.FilterStatsFactory; | |||
import net.anotheria.moskito.core.producers.IStatsProducer; | import net.anotheria.moskito.core.producers.IStatsProducer; | |||
import net.anotheria.moskito.core.registry.ProducerRegistryFactory; | import net.anotheria.moskito.core.registry.ProducerRegistryFactory; | |||
import net.anotheria.moskito.core.stats.Interval; | import net.anotheria.moskito.core.stats.Interval; | |||
skipping to change at line 142 | skipping to change at line 143 | |||
} | } | |||
@Override public void doFilter(ServletRequest req, ServletResponse res, F ilterChain chain) throws IOException, ServletException { | @Override public void doFilter(ServletRequest req, ServletResponse res, F ilterChain chain) throws IOException, ServletException { | |||
if (! (req instanceof HttpServletRequest)){ | if (! (req instanceof HttpServletRequest)){ | |||
chain.doFilter(req, res); | chain.doFilter(req, res); | |||
return; | return; | |||
} | } | |||
beforeExecution((HttpServletRequest)req, (HttpServletResponse)res ); | beforeExecution((HttpServletRequest)req, (HttpServletResponse)res ); | |||
MoSKitoContext.get().setLastProducer(this); | CurrentMeasurement measurement = MoSKitoContext.get().notifyProdu | |||
cerEntry(this); | ||||
if (measurement.isFirst()){ | ||||
//build request description. | ||||
HttpServletRequest httpServletRequest = (HttpServletReque | ||||
st) req; | ||||
StringBuilder callDescription = new StringBuilder(); | ||||
callDescription.append(httpServletRequest.getRequestURI() | ||||
); | ||||
if (httpServletRequest.getQueryString()!=null && httpServ | ||||
letRequest.getQueryString().length()>0){ | ||||
callDescription.append('?').append(httpServletReq | ||||
uest.getQueryString()); | ||||
} | ||||
measurement.setCallDescription(callDescription.toString() | ||||
); | ||||
} | ||||
long startTime = System.nanoTime(); | long startTime = System.nanoTime(); | |||
Throwable t = null; | Throwable t = null; | |||
try{ | try{ | |||
chain.doFilter(req, res); | chain.doFilter(req, res); | |||
}catch(ServletException e){ | }catch(ServletException e){ | |||
t = e; | t = e; | |||
}catch(IOException e){ | }catch(IOException e){ | |||
t = e; | t = e; | |||
}catch(RuntimeException e){ | }catch(RuntimeException e){ | |||
t = e; | t = e; | |||
}catch(Error e){ | }catch(Error e){ | |||
t = e; | t = e; | |||
}finally{ | }finally{ | |||
long exTime = System.nanoTime() - startTime; | long exTime = System.nanoTime() - startTime; | |||
afterExecution( (HttpServletRequest)req, (HttpServletResp onse) res, exTime, t); | afterExecution( (HttpServletRequest)req, (HttpServletResp onse) res, exTime, t); | |||
if (measurement.isFirst()){ | ||||
measurement.notifyProducerFinished(); | ||||
} | ||||
} | } | |||
} | } | |||
@Override public void init(FilterConfig config) throws ServletException { | @Override public void init(FilterConfig config) throws ServletException { | |||
int limit = -1; | int limit = -1; | |||
String pLimit = config.getInitParameter(INIT_PARAM_LIMIT); | String pLimit = config.getInitParameter(INIT_PARAM_LIMIT); | |||
if (pLimit!=null) { | if (pLimit!=null) { | |||
try { | try { | |||
limit = Integer.parseInt(pLimit); | limit = Integer.parseInt(pLimit); | |||
} catch (NumberFormatException ignored) { | } catch (NumberFormatException ignored) { | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 22 lines changed or added |