struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Hum (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (WW-4662) StreamResult closes outputstream early
Date Tue, 19 Jul 2016 12:19:21 GMT

     [ https://issues.apache.org/jira/browse/WW-4662?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Michael Hum updated WW-4662:
----------------------------
    Description: 
We recently upgraded from struts 2.3.x to 2.5.2 at our workplace. One of the changes we noticed
was with stream result - if an error occurs, the output stream is automatically closed and
no response is sent to the user (ignoring our custom error-500 page). The content-length of
the response is thus 0 - a blank page.

This is occuring due to the addition of try-with-resources. In 2.3.x, the output stream wasn't
set until after we find the input stream, like so:

{code}
try {
   get inputStream
   if (inputStream == null)
        throw Exception
   get outputStream
} finally {
   if inputStream != null inputStream.close()
   if outputStream != null outputStream.close()
}
{code}

However, in 2.5, this was changed to use a try-with-resources on the output stream by ticket
WW-4515 (https://git-wip-us.apache.org/repos/asf?p=struts.git;a=commit;h=3fab155b4cc530ca3ca0b69299ddcb348eb5f26d):

{code:java}
try (OutputStream oOutput = oResponse.getOutputStream()) {
// ...
}
{code}

So, when we throw an error, the stream is closed and nothing further is written. 

Is this intended behaviour? Is there an alternate solution to show our own error pages now
(with stack trace?)? 



  was:
We recently upgraded from struts 2.3.x to 2.5.2 at our workplace. One of the changes we noticed
was with stream result - if an error occurs, the output stream is automatically closed and
no response is sent to the user (ignoring our custom error-500 page). The content-length of
the response is thus 0 - a blank page.

This is occuring due to the addition of try-with-resources. In 2.3.x, the output stream wasn't
set until after we find the input stream, like so:

{code}
try {
   get inputStream
   if (inputStream == null)
        throw Exception
   get outputStream
} finally {
   if inputStream != null inputStream.close()
   if outputStream != null outputStream.close()
}
{code}

However, in 2.5, this was changed to use a try-with-resources on the output stream (https://git-wip-us.apache.org/repos/asf?p=struts.git;a=commit;h=3fab155b4cc530ca3ca0b69299ddcb348eb5f26d):

{code:java}
try (OutputStream oOutput = oResponse.getOutputStream()) {
// ...
}
{code}

So, when we throw an error, the stream is closed and nothing further is written. 

Is this intended behaviour? Is there an alternate solution to show our own error pages now
(with stack trace?)? 




> StreamResult closes outputstream early
> --------------------------------------
>
>                 Key: WW-4662
>                 URL: https://issues.apache.org/jira/browse/WW-4662
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.5
>            Reporter: Michael Hum
>
> We recently upgraded from struts 2.3.x to 2.5.2 at our workplace. One of the changes
we noticed was with stream result - if an error occurs, the output stream is automatically
closed and no response is sent to the user (ignoring our custom error-500 page). The content-length
of the response is thus 0 - a blank page.
> This is occuring due to the addition of try-with-resources. In 2.3.x, the output stream
wasn't set until after we find the input stream, like so:
> {code}
> try {
>    get inputStream
>    if (inputStream == null)
>         throw Exception
>    get outputStream
> } finally {
>    if inputStream != null inputStream.close()
>    if outputStream != null outputStream.close()
> }
> {code}
> However, in 2.5, this was changed to use a try-with-resources on the output stream by
ticket WW-4515 (https://git-wip-us.apache.org/repos/asf?p=struts.git;a=commit;h=3fab155b4cc530ca3ca0b69299ddcb348eb5f26d):
> {code:java}
> try (OutputStream oOutput = oResponse.getOutputStream()) {
> // ...
> }
> {code}
> So, when we throw an error, the stream is closed and nothing further is written. 
> Is this intended behaviour? Is there an alternate solution to show our own error pages
now (with stack trace?)? 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message