image - How to output a binary document based on a HTML document using filters in Java -


It may be a little confusing but I'm having some difficulty, my goal is to take an input HTML document and then to that document To use HTML data to process and output an image document. For example, the user requests the URL, some actions in QuickString = PNG, and then get filters for the URL and the output image document.

I am able to produce only one type of my environment (websphere). If input type is text / html, then I can only output to a text document, I can not output to a binary document. Why? Because I get an unlawful state exception every time.

[1/2 9/09 17: 59: 57: 576 EST] 00000020 system IRR R Java. Link. IlllegalState Expression: SRVE0209E: Author has already received [1/2 9/9 17: 59: 57: 576 EST] com.ibm.ws.webcontainer.srt.SRTServletResponse.getOutputStream (SRTServletResponse.java:505) On 00000020SystemRRR

I'm using the proxy code to reveal all my code:

   

The rapper class code is essentially:

  public class ContentCaptureServletResponse HttpServletResponseWrapper Extended {Private ByteArray Output Content BUFFER; Private PrintWriter Writer; Public PrintWriter getWriter () throws IOException {if (author == blank) {contentsBuffer = new ByteArrayOutputStream (); Author = new print-writer (content buffer); } Return Author; } Public string getContent () {try = writer = getWriter (); } Hold (IOException e) {e.printStackTrace (); } Author. Full (); String xhtmlContent = new string (contentBuffer.toByteArray ()); Println (xhtmlContent); Return xhtmlContent; }}  

and filter code is:

  Public Zero doFilter (ServletRequest request, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {HttpServletRequest request = (HTTPSvRTuAst) Rake; HttpServletResponse response = (HttpServletResponse) resp; Last string render type = request.getParameter ("R"); Last string renderClassName = request.getParameter ("C"); If ((type render = zero) & amp; amp; (renderClassName! = Null)) {{this.setFilterChain (filterChain); Response.setContentType ("image / png"); PrintWriter out = response.getWriter (); // I call getWriter but not both! //response.getOutputStream (); Response.getWriter (); // Create HTML document in a string. CaptureSpons cap content = new capture response (feedback); this. Minfilter chain.dofilter (rake,); String Maestring = Cap HTML Content Mate content (); // What I really want to do here is output an output stream / / so I can write a binary image processor (myString); Response.getOutputStream (); reaction. Write (BinRemage)} Catch (Exception E) {e.printStackTrace (); } // No data will be output to user} Other {filterChain.doFilter (request, response); } // if-else} end of // method closing  

If I want to take some input html text documents, the code works. I'm assuming the cause of the Open PrintRighter stream but I have trouble getting into a different format. Actually, because I can not react. GetOutputStream ()

This problem looks like you are opening author authors before wrapping the feedback.

It seems that you should be able to:

  this.setFilterChain (filterChain); CaptureContent capContent = new capturer (feedback); DoFilter () Process (); Response.setContentType ("image / png"); . Write Response.getOutputStream () (imagedata);  

You can not safely open both author and output stream


Comments