You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sirona.apache.org by "Romain Manni-Bucau (JIRA)" <ji...@apache.org> on 2014/02/09 18:51:21 UTC

[jira] [Resolved] (SIRONA-28) JSP statistics

     [ https://issues.apache.org/jira/browse/SIRONA-28?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Romain Manni-Bucau resolved SIRONA-28.
--------------------------------------

       Resolution: Fixed
    Fix Version/s: 0.2-incubating
         Assignee: Romain Manni-Bucau

Done wrapping JspFactory, doc should be up to date soon


> JSP statistics
> --------------
>
>                 Key: SIRONA-28
>                 URL: https://issues.apache.org/jira/browse/SIRONA-28
>             Project: Sirona
>          Issue Type: New Feature
>            Reporter: E. Vernat
>            Assignee: Romain Manni-Bucau
>             Fix For: 0.2-incubating
>
>
> JSP are in general rendered by using "request.getRequestDispatcher(path).include(request, response)" or "request.getRequestDispatcher(path).forward(request, response)" in the monitored webapp.
> It may be useful to know in Sirona the number of executions and times of JSP rendering.
> And this can be coded using javax.servlet.Filter and javax.servlet.http.HttpServletRequestWrapper to monitor all includes and forwards.
> Here is some code to demonstrate that, inspired by JavaMelody code:
> {code:java}
> public class MyFilter implements Filter {
> 	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
> 			throws IOException, ServletException {
> 		HttpServletRequest httpRequest = (HttpServletRequest) request;
> 		HttpServletRequest wrappedRequest = new JspRequestWrapper(httpRequest);
> 		chain.doFilter(wrappedRequest, response);
> 	}
> }
> {code}
> {code:java}
> class JspRequestWrapper extends HttpServletRequestWrapper {
> 	JspRequestWrapper(HttpServletRequest request) {
> 		super(request);
> 	}
> 	@Override
> 	public RequestDispatcher getRequestDispatcher(String path) {
> 		final RequestDispatcher requestDispatcher = super.getRequestDispatcher(path);
> 		if (requestDispatcher == null) {
> 			return null;
> 		}
> 		final InvocationHandler invocationHandler = new JspHandler(String.valueOf(path),
> 				requestDispatcher);
> 		// TODO create Sirona proxy for requestDispatcher using invocationHandler
> 		return proxy;
> 	}
> }
> {code}
> {code:java}
> class JspHandler implements InvocationHandler {
> 	private final String path;
> 	private final RequestDispatcher requestDispatcher;
> 	JspHandler(String path, RequestDispatcher requestDispatcher) {
> 		this.path = path;
> 		this.requestDispatcher = requestDispatcher;
> 	}
> 	@Override
> 	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
> 		final String methodName = method.getName();
> 		if ("include" != methodName && "forward" != methodName) { // better for perf in this case
> 			return method.invoke(requestDispatcher, args);
> 		}
> 		// NOTE parameters after '?' could be stripped from path to have only the real path
> 		// TODO monitor invoke into JSP statistics for that path
> 		return method.invoke(requestDispatcher, args);
> 	}
> }
> {code}
> Adding a new servlet filter each time for JSP, and then for GWT / SOAP / XML-RPC scanning, would make much longer all the stack-traces of the webapp.
> This is bad. So it is certainly better to plug that into the existing Sirona filter and not to create a new filter each time.
> In fact, the servlet RequestDispatcher can be used to render just any web resources such as servlets and files, but JSP is the most common case.
> (Off-topic: I have seen the undocumented JSP tags in Sirona for some JSP statistics, but it does not seem great to add the Sirona tags in the JSP files of the monitored webapp.)



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)