Ummm ... the general idea of a wrapper is that it **hides** things. Can you be more explicit about what you need access to?
– Stephen CJun 07 '11 at 04:14
@Ramesh PVK, I need to access the whole "text/html" contained in the response.
@Ravi Parekh, I just need to filter the "text/html" content then modify it, but not just appending to it. Basically, I need to: Read-Modify then Write it back.
– quarksJun 08 '11 at 09:20
The OP wants to access the components of the HttpServletResponse. The HttpServletResponseWrapper would not allow for it.
– Vineet ReynoldsJun 07 '11 at 05:04
I need to get the content response then modify it. There is no facility to do it using HttpServletResponseWrapper. Any ideas?
– quarksJun 07 '11 at 11:27
Basically I followed the code provided here:
http://stackoverflow.com/questions/701681/how-can-i-read-an-httpservletreponses-output-stream
However I get an empty string.
– quarksJun 07 '11 at 14:06
@xybrek this link (http://www.oracle.com/technetwork/java/filters-137243.html#72674) has what you want. To override response
methods, you wrap the response in an object that extends
ServletResponseWrapper or HttpServletResponseWrapper. Other than the what you specified in that stackoverflow 701681, you need to set in your deployment descriptor.
– JasonwJun 08 '11 at 02:56
@Jasonw, the link really is quite the same thing that I need to do, however when in put this code:
CharResponseWrapper wrapper = new CharResponseWrapper( (HttpServletResponse)servletresponse); chain.doFilter(servletrequest, wrapper);
The client gets HTTP error 503, however when I do just "pass-through" like:
chain.doFilter(servletrequest, servletresponse); The client gets the html properly. Any ideas?
– quarksJun 08 '11 at 03:57
@xybreak I think your response drifting a bit far from the original question. Have the initial suggested answer , answer your initial question?
also, try catch IOException, ServletException and then Exception and print the stackstrace to understand where is the source of problem.
– JasonwJun 08 '11 at 04:52
@Jasonw, well HttpServletResponse wrapper technically may be the solution, however I still am not able to get the "components" of HttpServelet response (to manipulate it), the link you provide is very informative almost the one I need to do; however I need to get and manipulate the components of HttpServletResponse not really just to append to it. So, I am still looking for some answer.
– quarksJun 08 '11 at 09:10
@Jasonw, the servlet does not throw exception when I tried wrapping the code with try-catch block. What really happens from the code in the link you provided is that the if-else statement fails in this portion of the code: if(wrapper.getContentType().equals("text/html")). So I still really can't access the components of HttpServletRespose with using the wrapper.
– quarksJun 08 '11 at 09:13
@Vineet Reynolds what do you mean when you said "The HttpServletResponseWrapper would not allow for it"?, do you mean that its not totally possible to get access with the response content?
– quarksJun 08 '11 at 09:18
@xybrek, I read you question as the need to access the members of HttpResponse. If so, then a HttpResponseWrapper will not help. A response wrapper is used, typically by a filter, to provide a wrapper object to a downstream servlet. The servlet writes its response to the wrapper instead of the actual response object (which only the filter has access to). If you want to access the inner members of the HttpsReponse object that are not accessible via the servlet API, you need to use reflection or other mechanisms.
– Vineet ReynoldsJun 08 '11 at 11:01