aspose file tools*
The moose likes Servlets and the fly likes Response Filtering Suggestions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Response Filtering Suggestions" Watch "Response Filtering Suggestions" New topic
Author

Response Filtering Suggestions

siva kumar
Ranch Hand

Joined: May 02, 2004
Posts: 120
Hi Friends,

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 ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by siva kumar:
response and if I get a undesired response then ...


How are you defining an 'undesirable response'?
What are you checking for?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
siva kumar
Ranch Hand

Joined: May 02, 2004
Posts: 120
Hi...,

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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.
siva kumar
Ranch Hand

Joined: May 02, 2004
Posts: 120
Hi Ben,

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.
siva kumar
Ranch Hand

Joined: May 02, 2004
Posts: 120
Hi Ben,

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

www.xxxx.com/RequestProcessor?render=home.jsp

where requestprocessor is the servlet given by CMS vendor and render is a parameter passed to resquestprocessor

thats the reason in home.jsp we cannot access any JSP/Servlet Implict Objects

If in need to add a filter I can add it only for Filter mapping ie /RequestProcessor/
siva kumar
Ranch Hand

Joined: May 02, 2004
Posts: 120
Hi Friends,

Any solutions/Suggestion on the above problem, I agree that this a peculiar problem, but surely some one might have seen simillar issues in their projects.

As I am struck any help would be really great, I hope I have explained the problem clearly if not kindly send me a message.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Response Filtering Suggestions