I'm looking for a good, clean, hopefully relatively easy way to capture the html output of an executed JSP page outside of a web context, i.e. from within a service method. One way I got to work was to use HttpUnit and just open a connection and hit the Action (it's Struts-based) that executes the JSP in question, then dump the HTML. The problem is that there may be security issues that may preclude me from doing this in production, so I'm looking for a method that doesn't involve opening sockets.

Another approach I tried which I've not gotten to work so far, was to get a handle on the ServletContext magically from within my service method, then create a ServletResponseWrapper and call a requestDispatcher to forward (or include) the jsp in question, let the JSP write its content to my wrapper response object and capture everything, but it's just not working. Not getting any exceptions, and I've tested/traced everything right up to the JSP and right after the JSP but my ResponseWrapper's internal String that should be holding the JSP's output doesn't contain anything.

Does that approach sound remotely like the right way to go about this? Is there an even easier way perhaps?

Thanks for any help.