Repository: struts Updated Branches: refs/heads/master d06689120 -> d75a89048
WW-4655 Cleans up code and uses more user friendly logic to process parameters Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/d75a8904 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/d75a8904 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/d75a8904 Branch: refs/heads/master Commit: d75a890482dee2c1770ef2568bdf213266355589 Parents: d066891 Author: Lukasz Lenart <lukaszlen...@apache.org> Authored: Sun Jul 3 10:55:14 2016 +0200 Committer: Lukasz Lenart <lukaszlen...@apache.org> Committed: Sun Jul 3 10:55:14 2016 +0200 ---------------------------------------------------------------------- .../org/apache/struts2/result/StreamResult.java | 64 +++----------------- .../apache/struts2/result/StreamResultTest.java | 10 +-- 2 files changed, 15 insertions(+), 59 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/d75a8904/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 0bc328d..fb9e4f5 100644 --- a/core/src/main/java/org/apache/struts2/result/StreamResult.java +++ b/core/src/main/java/org/apache/struts2/result/StreamResult.java @@ -22,7 +22,6 @@ package org.apache.struts2.result; import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.util.ValueStack; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -218,15 +217,12 @@ public class StreamResult extends StrutsResultSupport { * @see StrutsResultSupport#doExecute(java.lang.String, com.opensymphony.xwork2.ActionInvocation) */ protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { + LOG.debug("Find the Response in context"); - // Override any parameters using values on the stack - resolveParamsFromStack(invocation.getStack(), invocation); - - // Find the Response in context HttpServletResponse oResponse = (HttpServletResponse) invocation.getInvocationContext().get(HTTP_RESPONSE); try (OutputStream oOutput = oResponse.getOutputStream()) { if (inputStream == null) { - // Find the inputstream from the invocation variable stack + LOG.debug("Find the inputstream from the invocation variable stack"); inputStream = (InputStream) invocation.getStack().findValue(conditionalParse(inputName, invocation)); } @@ -237,18 +233,17 @@ public class StreamResult extends StrutsResultSupport { throw new IllegalArgumentException(msg); } - // Set the content type + LOG.debug("Set the content type: {};charset{}", contentType, contentCharSet); if (contentCharSet != null && ! contentCharSet.equals("")) { - oResponse.setContentType(conditionalParse(contentType, invocation)+";charset="+contentCharSet); - } - else { + oResponse.setContentType(conditionalParse(contentType, invocation)+";charset="+conditionalParse(contentCharSet, invocation)); + } else { oResponse.setContentType(conditionalParse(contentType, invocation)); } - // Set the content length + LOG.debug("Set the content length: {}", contentLength); if (contentLength != null) { String _contentLength = conditionalParse(contentLength, invocation); - int _contentLengthAsInt = -1; + int _contentLengthAsInt; try { _contentLengthAsInt = Integer.parseInt(_contentLength); if (_contentLengthAsInt >= 0) { @@ -260,12 +255,12 @@ public class StreamResult extends StrutsResultSupport { } } - // Set the content-disposition + LOG.debug("Set the content-disposition: {}", contentDisposition); if (contentDisposition != null) { oResponse.addHeader("Content-Disposition", conditionalParse(contentDisposition, invocation)); } - // Set the cache control headers if neccessary + LOG.debug("Set the cache control headers if necessary: {}", allowCaching); if (!allowCaching) { oResponse.addHeader("Pragma", "no-cache"); oResponse.addHeader("Cache-Control", "no-cache"); @@ -274,7 +269,6 @@ public class StreamResult extends StrutsResultSupport { LOG.debug("Streaming result [{}] type=[{}] length=[{}] content-disposition=[{}] charset=[{}]", inputName, contentType, contentLength, contentDisposition, contentCharSet); - // Copy input to output LOG.debug("Streaming to output buffer +++ START +++"); byte[] oBuff = new byte[bufferSize]; int iSize; @@ -289,44 +283,4 @@ public class StreamResult extends StrutsResultSupport { } } - /** - * Tries to lookup the parameters on the stack. Will override any existing parameters - * - * @param stack The current value stack - * @param invocation the action invocation - */ - protected void resolveParamsFromStack(ValueStack stack, ActionInvocation invocation) { - String disposition = stack.findString("contentDisposition"); - if (disposition != null) { - setContentDisposition(disposition); - } - - String contentType = stack.findString("contentType"); - if (contentType != null) { - setContentType(contentType); - } - - String inputName = stack.findString("inputName"); - if (inputName != null) { - setInputName(inputName); - } - - String contentLength = stack.findString("contentLength"); - if (contentLength != null) { - setContentLength(contentLength); - } - - Integer bufferSize = (Integer) stack.findValue("bufferSize", Integer.class); - if (bufferSize != null) { - setBufferSize(bufferSize); - } - - if (contentCharSet != null ) { - contentCharSet = conditionalParse(contentCharSet, invocation); - } - else { - contentCharSet = stack.findString("contentCharSet"); - } - } - } http://git-wip-us.apache.org/repos/asf/struts/blob/d75a8904/core/src/test/java/org/apache/struts2/result/StreamResultTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/struts2/result/StreamResultTest.java b/core/src/test/java/org/apache/struts2/result/StreamResultTest.java index fbb2525..3d58db5 100644 --- a/core/src/test/java/org/apache/struts2/result/StreamResultTest.java +++ b/core/src/test/java/org/apache/struts2/result/StreamResultTest.java @@ -78,8 +78,8 @@ public class StreamResultTest extends StrutsInternalTestCase { result.doExecute("helloworld", mai); - assertEquals(String.valueOf(contentLength), result.getContentLength()); - assertEquals("text/plain", result.getContentType()); + assertEquals(contentLength, response.getContentLength()); + assertEquals("text/plain", response.getContentType()); assertEquals("streamForImage", result.getInputName()); assertEquals(1024, result.getBufferSize()); // 1024 is default assertEquals("inline", result.getContentDisposition()); @@ -94,7 +94,7 @@ public class StreamResultTest extends StrutsInternalTestCase { result.setContentCharSet("ISO-8859-1"); result.doExecute("helloworld", mai); - assertEquals(String.valueOf(contentLength), result.getContentLength()); + assertEquals(contentLength, response.getContentLength()); assertEquals("text/plain", result.getContentType()); assertEquals("streamForImage", result.getInputName()); assertEquals(1024, result.getBufferSize()); // 1024 is default @@ -111,8 +111,9 @@ public class StreamResultTest extends StrutsInternalTestCase { result.doExecute("helloworld", mai); - assertEquals(String.valueOf(contentLength), result.getContentLength()); + assertEquals(contentLength, response.getContentLength()); assertEquals("text/plain", result.getContentType()); + assertEquals("text/plain;charset=UTF-8", response.getContentType()); assertEquals("streamForImage", result.getInputName()); assertEquals(1024, result.getBufferSize()); // 1024 is default assertEquals("inline", result.getContentDisposition()); @@ -220,6 +221,7 @@ public class StreamResultTest extends StrutsInternalTestCase { response = new MockHttpServletResponse(); result = new StreamResult(); + result.setContentLength("${contentLength}"); stack = ActionContext.getContext().getValueStack(); MyImageAction action = new MyImageAction();