Filter tricks in tomcat
Hi, Im working with Tomcat 5 from 3 months ago. I understand the filter architecture, but I cannot capture the response filter for my JSP and servelt. Tomcat 5 is Servlet 2.4, so I thing it can filter either request or response. What I can do, is capture the entire request and its response, to have a good mechanism of statistics in my web application. So, can you help in order to know how can I catch the response in a filter?? Thanks in advanced, And best regards. .pcs __ Pablo Carretero Sánchez Cygnux Arquitecto de Software Pintor Velázquez nº 3 Esc Izq 7º B 28932 Móstoles (Madrid) Movil: +34 699929150 [EMAIL PROTECTED] http://www.cygnux.com/egroupware/email/compose.php?folder=INBOXsessionid=1 2a0f5acc6fd5805a190a5b55a147155kp3=7c4ad1ea016bfe58bf86addf2e6064d3domain= cygnux.com[EMAIL PROTECTED]
RE: Filter tricks in tomcat
Hi, I assume that when you say capture you mean handle ? Or maybe wrap? To only handle outgoing (response) data in a filter, do something like this: public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws Blah { chain.doFilter(request, response); // Now do whatever you want with the response // Remember though that the response is likely committed by now } To only wrap a response is even simpler: public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws Blah { // Do whatever chain.doFilter(request, new MyResponseWrapper(response)); // Do whatever } Yoav Shapira http://www.yoavshapira.com -Original Message- From: Pablo Carretero [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 09, 2004 3:06 AM To: [EMAIL PROTECTED] Subject: Filter tricks in tomcat Hi, I'm working with Tomcat 5 from 3 months ago. I understand the filter architecture, but I cannot capture the response filter for my JSP and servelt. Tomcat 5 is Servlet 2.4, so I thing it can filter either request or response. What I can do, is capture the entire request and its response, to have a good mechanism of statistics in my web application. So, can you help in order to know how can I catch the response in a filter?? Thanks in advanced, And best regards. .pcs __ Pablo Carretero Sánchez Cygnux Arquitecto de Software Pintor Velázquez nº 3 Esc Izq 7º B 28932 - Móstoles (Madrid) Movil: +34 699929150 [EMAIL PROTECTED] http://www.cygnux.com/egroupware/email/compose.php?folder=INBOXsessionid= 1 2a0f5acc6fd5805a190a5b55a147155kp3=7c4ad1ea016bfe58bf86addf2e6064d3domain = cygnux.com[EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Filter tricks in tomcat
actually, you can use filters to capture the response and then use a filter to dump the whole thing to the outputstream. What you'll have to do is create your own buffer to hold the content and not write to either the jspwriter or the printwriter in the servlet. the tricky part is this. if you have custom error pages, you'll have to be careful because there may already be stuff in the buffer. one of these days I'll have to write an example and post a patch for the tomcat jsp examples. peter On Tue, 9 Nov 2004 09:03:10 -0500, Shapira, Yoav [EMAIL PROTECTED] wrote: Hi, I assume that when you say capture you mean handle ? Or maybe wrap? To only handle outgoing (response) data in a filter, do something like this: public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws Blah { chain.doFilter(request, response); // Now do whatever you want with the response // Remember though that the response is likely committed by now } To only wrap a response is even simpler: public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws Blah { // Do whatever chain.doFilter(request, new MyResponseWrapper(response)); // Do whatever } Yoav Shapira http://www.yoavshapira.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]