-1

Is there a wrapper that provides access to the components of HttpServletResponse in Java?

Thanks, Xybrek

quarks
  • 33,478
  • 73
  • 290
  • 513

1 Answers1

0

class HttpServletResponseWrapper

Jasonw
  • 5,054
  • 7
  • 43
  • 48
  • The OP wants to access the components of the HttpServletResponse. The HttpServletResponseWrapper would not allow for it. – Vineet Reynolds Jun 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? – quarks Jun 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. – quarks Jun 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. – Jasonw Jun 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? – quarks Jun 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. – Jasonw Jun 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. – quarks Jun 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. – quarks Jun 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? – quarks Jun 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 Reynolds Jun 08 '11 at 11:01