This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am trying developa response filter, the requirement is as follows.
1.) The Filter should get the request and response object and should send a wrapped Response object to the filter.
2.) The wrapped response object should not write any thing to the browser, all the response. write, println should be captured in a stringbuffer
3.) Once the servlet returns, I should be able to check the StringBuffer response and if I get a undesired response then I will set the status as 500 and return to browser else I would send a content of string Buffer and send the same back to browser.
Please note: - As my application is running on another application ( Something like CMS) I wouldn't be able to access any of the J2EE implicit objects in any of the servlets, The only solution is to design the above response filter.
I have designed the response filter, can any one guide on how to design the Response wrapper [ December 11, 2007: Message edited by: Bear Bibeault ]
Here un-desirable response is some information that comes from the CMS tool
Such as "an error occured please try again"
Basically the CMS server if any error occurs automatically re-directs to its custom error page. ( With a response status as 200 OK)
Now whenever I get the response from the custom error page I should interrupt the response and set the status as 500 ----
why I would do that, is because we are feeding our html into some third party tool. which is configured in such a manner that it will reject and will not process if the status is 500.
Please note : the CMS vendor is no longer supporting the product (Infact he has closed down) and we dont have CMS source code. I couldnt decompile CMS code as the vendor has encrypted the code using a scrambler.
If you're using a Servlet Spec 2.4 compliant container, you should be able to filter requests (either forwarded or redirected to) for the custom error page itself and return you're own message, plus whatever response code you like.
That seems like it would be easier than parsing the entire response.
Joined: May 02, 2004
Thanks for your reply.
But I dont understand the solution, can you please provide some sample code.
Is there a any specific way we can do this without using response wapper.
Any guidance on this would be really great.
Joined: May 02, 2004
Sorry I forgot to update
1.) The custom error page is not being called directly from the client browser,The error.jsp is called by home.jsp only when an error occured the calling is done via request dispatcher.
2.) The worst thing with this tool is that you cannot have any servlets and JSP's called explictly there is a special RequestProcessor servlet and all calls will go via request processor servlet the URL for my home page will be some thing like