Suddenly stuck on generating a custom servlet response. I want to replace the servlet response with a predefined one:
public class MyCustomResponse extends HttpServletResponseWrapper {
private String customOutput;
public MyCustomResponse(String customOutput, HttpServletResponse response) {
super(response);
this.customOutput = customOutput;
}
}
and filter code are reset as follows:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
MyCustomResponse customResponse = new MyCustomResponse("Hello world!", (HttpServletResponse) response);
chain.doFilter(request, customResponse);
}
Shame on me, but I'm really fixated on this simple task :(
Any help would be appreciated.
UPDATE:
All I want to do is implement a custom response wrapper that, as soon as it fits into the filter chain, will always respond with some predefined text. I know how to write user data from the doFilter () method, but I want to be MyCustomResponseresponsible for this - just create an instance and add a chain. Any reasonable answers "You cannot do this because ..." are also welcome.