• Post Reply Bookmark Topic Watch Topic
  • New Topic

Html content from the response object

 
Mckenzie John
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i extract the HTML content from a HttpResponse Object.?

I have a response object which i need to intercept and modify the appearance before it gets rendered in the browser. I have a separate API which does the modification but how do i pass the response object to the API which accepts only HTM as string to get this done.

Is there a way to get the entire html content of the end page from the response object using a custom filter. We have this application with a spring filter chain to intercept URLs.

Helpful ideas are useful.
 
Stefan Evans
Bartender
Posts: 1822
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you would have to read the OutputStream of the response object.
The trick here is to intercept the call BEFORE the response gets generated. You create your own HTTPResponse object wrapping the original one, and pass that down to the next item in the chain.
That will then mean that anything that gets written to that HTTPResponse object comes to you instead. You can then capture it in a String, pass it to your modification library, and then write the result through to the original HttpResponse Object.

make sense?




 
Mckenzie John
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A code snippet would help me better. Can you please share one?
 
Mckenzie John
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jerry,

Can you please Provide a working snippet
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An example of performing this exact operation with a filter can be found in Java Filter Documentation
Check out the section "Programming Customized Requests and Responses"

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!