You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sirona.apache.org by "E. Vernat (JIRA)" <ji...@apache.org> on 2014/02/07 22:47:20 UTC

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

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

E. Vernat updated SIRONA-28:
----------------------------

    Description: 
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);
	}
}

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;
	}
}

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.)

  was:
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:

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);
	}
}

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;
	}
}

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);
	}
}


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.)


> JSP statistics
> --------------
>
>                 Key: SIRONA-28
>                 URL: https://issues.apache.org/jira/browse/SIRONA-28
>             Project: Sirona
>          Issue Type: New Feature
>            Reporter: E. Vernat
>
> 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);
> 	}
> }
> 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;
> 	}
> }
> 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)