Issue Details (XML | Word | Printable)

Key: WW-602
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Patrick Lightbody
Reporter: Martin Crawford
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
WebWork

Stream Result Type

Created: 27/Jul/04 01:54 PM   Updated: 16/Aug/05 05:54 PM
Component/s: Views
Affects Version/s: 2.1
Fix Version/s: 2.1.2

File Attachments: 1. Java Source File StreamResult.java (3 kB)



 Description  « Hide
I wrote this Stream Result handler to take an an InputStream from the invocation value stack and redirect it to the browser. It takes a configurable content-type. Should perhaps include some handling for cache control headers. Thought I should give you guys a copy to do what you please.

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Martin Crawford added a comment - 27/Jul/04 01:54 PM
Here is the file.

Patrick Lightbody added a comment - 09/Sep/04 07:00 PM
thanks

Martin Crawford added a comment - 16/Sep/04 11:26 AM
Realized that probably the input stream should be closed after the data is transfered to the output stream. Not sure what memory leak issues might occur otherwise. So far I haven't encountered any in my application using this but it would seem to be good practice.

David Bernard added a comment - 29/Oct/04 10:39 AM
with webwork 2.1.5, I need to add the parameter "parse" to avoid NPE in xwork TextParseUtil.

      <result name="success" type="stream">
        <param name="parse">false</param>
        <param name="contentType">image/png</param>
        <param name="inputName">imageStream</param>
        <param name="bufferSize">1024</param>
      </result>

Paul Zepernick added a comment - 16/Aug/05 05:54 PM
On 2.1.7 I had a problem with the stream not being closed. I need to delete files that had been read by the stream later on, and had issues because they were in use. I implemented the following fix in the class:

    protected void doExecute(String finalLocation, ActionInvocation invocation)
            throws Exception {
        
        InputStream oInput = null;
        OutputStream oOutput = null;
        
        try{
// Find the inputstream from the invocation variable stack
oInput = (InputStream) invocation.getStack().findValue(conditionalParse(inputName, invocation));

// Find the Response in context
HttpServletResponse oResponse = (HttpServletResponse) invocation.getInvocationContext().get(HTTP_RESPONSE);

// Set the content type
oResponse.setContentType(conditionalParse(contentType, invocation));

// Set the content-disposition
if (contentDisposition != null) {
oResponse.addHeader("Content-disposition", conditionalParse(contentDisposition, invocation));
}

// Get the outputstream
oOutput = oResponse.getOutputStream();

// Copy input to output
byte[] oBuff = new byte[bufferSize];
int iSize = 0;
while (-1 != (iSize = oInput.read(oBuff))) {
oOutput.write(oBuff, 0, iSize);
}

// Flush
oOutput.flush();
        }finally{
            if (oInput != null)oInput.close();
            if (oOutput != null)oOutput.close();
        }
        
            
    }