Repository: struts
Updated Branches:
  refs/heads/master 18be60fa1 -> 92c54de11


WW-4662 Partially reverts try-with-resources introduced with WW-4515


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/92c54de1
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/92c54de1
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/92c54de1

Branch: refs/heads/master
Commit: 92c54de11030d6f6325386dd24ba92efb9f34a90
Parents: 18be60f
Author: Lukasz Lenart <lukaszlen...@apache.org>
Authored: Tue Aug 30 08:51:32 2016 +0200
Committer: Lukasz Lenart <lukaszlen...@apache.org>
Committed: Tue Aug 30 08:51:32 2016 +0200

----------------------------------------------------------------------
 .../org/apache/struts2/result/StreamResult.java | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/92c54de1/core/src/main/java/org/apache/struts2/result/StreamResult.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/result/StreamResult.java 
b/core/src/main/java/org/apache/struts2/result/StreamResult.java
index fb9e4f5..b20ee5f 100644
--- a/core/src/main/java/org/apache/struts2/result/StreamResult.java
+++ b/core/src/main/java/org/apache/struts2/result/StreamResult.java
@@ -219,8 +219,9 @@ public class StreamResult extends StrutsResultSupport {
     protected void doExecute(String finalLocation, ActionInvocation 
invocation) throws Exception {
         LOG.debug("Find the Response in context");
 
-        HttpServletResponse oResponse = (HttpServletResponse) 
invocation.getInvocationContext().get(HTTP_RESPONSE);
-        try (OutputStream oOutput = oResponse.getOutputStream()) {
+        OutputStream oOutput = null;
+
+        try {
             if (inputStream == null) {
                 LOG.debug("Find the inputstream from the invocation variable 
stack");
                 inputStream = (InputStream) 
invocation.getStack().findValue(conditionalParse(inputName, invocation));
@@ -233,6 +234,9 @@ public class StreamResult extends StrutsResultSupport {
                 throw new IllegalArgumentException(msg);
             }
 
+
+            HttpServletResponse oResponse = (HttpServletResponse) 
invocation.getInvocationContext().get(HTTP_RESPONSE);
+
             LOG.debug("Set the content type: {};charset{}", contentType, 
contentCharSet);
             if (contentCharSet != null && ! contentCharSet.equals("")) {
                 oResponse.setContentType(conditionalParse(contentType, 
invocation)+";charset="+conditionalParse(contentCharSet, invocation));
@@ -249,8 +253,7 @@ public class StreamResult extends StrutsResultSupport {
                     if (_contentLengthAsInt >= 0) {
                         oResponse.setContentLength(_contentLengthAsInt);
                     }
-                }
-                catch(NumberFormatException e) {
+                } catch(NumberFormatException e) {
                     LOG.warn("failed to recognize {} as a number, 
contentLength header will not be set", _contentLength, e);
                 }
             }
@@ -266,6 +269,8 @@ public class StreamResult extends StrutsResultSupport {
                 oResponse.addHeader("Cache-Control", "no-cache");
             }
 
+            oOutput = oResponse.getOutputStream();
+
             LOG.debug("Streaming result [{}] type=[{}] length=[{}] 
content-disposition=[{}] charset=[{}]",
                     inputName, contentType, contentLength, contentDisposition, 
contentCharSet);
 
@@ -280,6 +285,13 @@ public class StreamResult extends StrutsResultSupport {
 
             // Flush
             oOutput.flush();
+        } finally {
+            if (inputStream != null) {
+                inputStream.close();
+            }
+            if (oOutput != null) {
+                oOutput.close();
+            }
         }
     }
 

Reply via email to