Anonymous avatar Anonymous committed 4e84f21

WW-1456 (IE not friendly to SSL headers in JasperReportsResult)

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2977 573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (5)

src/java/com/opensymphony/webwork/dispatcher/HttpHeaderResult.java

 package com.opensymphony.webwork.dispatcher;
 
 import com.opensymphony.webwork.ServletActionContext;
+import com.opensymphony.webwork.views.AbstractHttpHeaderPopulatingResult;
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.Result;
  * <!-- END SNIPPET: example --></pre>
  *
  * @author Jason Carreira
+ * @author tmjee
+ * @version $Date$ $Id$
  */
-public class HttpHeaderResult implements Result {
+public class HttpHeaderResult extends AbstractHttpHeaderPopulatingResult {
 
     public static final String DEFAULT_PARAM = "status";
 
 
-    protected boolean parse = true;
-    private Map headers;
     private int status = -1;
 
 
     /**
-     * Returns a Map of all HTTP headers.
-     *
-     * @return a Map of all HTTP headers.
-     */
-    public Map getHeaders() {
-        if (headers == null) {
-            headers = new HashMap();
-        }
-
-        return headers;
-    }
-
-    /**
      * Sets whether or not the HTTP header values should be evaluated against the ValueStack (by default they are).
      *
      * @param parse <tt>true</tt> if HTTP header values should be evaluated agains the ValueStack, <tt>false</tt>
      * Sets the optional HTTP response status code and also re-sets HTTP headers after they've
      * been optionally evaluated against the ValueStack.
      *
+     * @param finalLocation
      * @param invocation an encapsulation of the action execution state.
      * @throws Exception if an error occurs when re-setting the headers.
      */
-    public void execute(ActionInvocation invocation) throws Exception {
+    protected void afterHttpHeadersPopulatedExecute(String finalLocation, ActionInvocation invocation) throws Exception {
         HttpServletResponse response = ServletActionContext.getResponse();
 
         if (status != -1) {
             response.setStatus(status);
         }
 
-        if (headers != null) {
-            OgnlValueStack stack = ActionContext.getContext().getValueStack();
-
-            for (Iterator iterator = headers.entrySet().iterator();
-                 iterator.hasNext();) {
-                Map.Entry entry = (Map.Entry) iterator.next();
-                String value = (String) entry.getValue();
-                String finalValue = parse ? TextParseUtil.translateVariables(value, stack) : value;
-                response.addHeader((String) entry.getKey(), finalValue);
-            }
-        }
+        
     }
 }

src/java/com/opensymphony/webwork/util/ClassLoaderUtils.java

 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.Collections;
 
 
 /**
  * It has come out of many months of frustrating use of multiple application servers at Atlassian,
  * please don't change things unless you're sure they're not going to break in one server or another!
  *
- * @author $Author$
- * @version $Revision$
+ * @author plightbo
+ * @author tmjee
+ * @version $Date$ $Id$
  */
 public class ClassLoaderUtils {
 

src/java/com/opensymphony/webwork/views/AbstractHttpHeaderPopulatingResult.java

+/*
+ * Copyright (c) 2002-2007 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.webwork.views;
+
+import com.opensymphony.webwork.ServletActionContext;
+import com.opensymphony.webwork.dispatcher.WebWorkResultSupport;
+import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.ActionInvocation;
+import com.opensymphony.xwork.util.OgnlValueStack;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * An abstract class that will auto populate the http response header of the current http request.
+ *
+ * @see HttpHeaderResult
+ * @see JasperReportsResult
+ *
+ * @author tmjee
+ * @version $Date$ $Id$
+ */
+public abstract class AbstractHttpHeaderPopulatingResult extends WebWorkResultSupport {
+
+    private Map headers;
+    
+    /**
+     * Returns a Map of all HTTP headers.
+     *
+     * @return a Map of all HTTP headers.
+     */
+    public Map getHeaders() {
+        if (headers == null) {
+            headers = new HashMap();
+        }
+
+        return headers;
+    }
+
+    /**
+     * Sets the optional HTTP response status code and also re-sets HTTP headers after they've
+     * been optionally evaluated against the ValueStack.
+     *
+     * @param finalLocation 
+     * @param invocation an encapsulation of the action execution state.
+     * @throws Exception if an error occurs when re-setting the headers.
+     */
+    public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
+        HttpServletResponse response = ServletActionContext.getResponse();
+
+        if (headers != null) {
+            OgnlValueStack stack = ActionContext.getContext().getValueStack();
+
+            for (Iterator iterator = headers.entrySet().iterator();
+                 iterator.hasNext();) {
+                Map.Entry entry = (Map.Entry) iterator.next();
+                String value = (String) entry.getValue();
+                String finalValue = conditionalParse(value, invocation);
+                response.addHeader((String) entry.getKey(), finalValue);
+            }
+        }
+
+        afterHttpHeadersPopulatedExecute(finalLocation, invocation);
+    }
+
+    /**
+     * This method is meant for subclass to override, it is called after the http headers
+     * have been set into the current http response.
+     *
+     * @param finalLocation
+     * @param invocation
+     * @throws Exception
+     */
+   protected abstract void afterHttpHeadersPopulatedExecute(String finalLocation, ActionInvocation invocation) throws Exception;
+}

src/java/com/opensymphony/webwork/views/jasperreports/JasperReportsResult.java

 /*
- * Copyright (c) 2002-2005 by OpenSymphony
+ * Copyright (c) 2002-2007 by OpenSymphony
  * All rights reserved.
  */
 package com.opensymphony.webwork.views.jasperreports;
 import com.opensymphony.util.TextUtils;
 import com.opensymphony.webwork.ServletActionContext;
 import com.opensymphony.webwork.WebWorkException;
+import com.opensymphony.webwork.views.AbstractHttpHeaderPopulatingResult;
 import com.opensymphony.webwork.dispatcher.WebWorkResultSupport;
 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.util.OgnlValueStack;
  *
  * @author Patrick Lightbody
  * @author Rainer Hermanns
+ * @author tmjee
+ * @version $Date$ $Id$
  */
-public class JasperReportsResult extends WebWorkResultSupport implements JasperReportConstants {
+public class JasperReportsResult extends AbstractHttpHeaderPopulatingResult implements JasperReportConstants {
     private final static Log LOG = LogFactory.getLog(JasperReportsResult.class);
 
 
         this.delimiter = delimiter;
     }
 
-    protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
+    protected void afterHttpHeadersPopulatedExecute(String finalLocation, ActionInvocation invocation) throws Exception {
+        
         if (this.format == null) {
             this.format = FORMAT_PDF;
         }
         }
     }
 
+
+
     /**
      * Run a Jasper report to CSV format and put the results in a byte array
      *

src/test/com/opensymphony/webwork/dispatcher/HttpHeaderResultTest.java

 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.XWorkTestCase;
 import com.opensymphony.xwork.util.OgnlUtil;
+import com.opensymphony.xwork.util.OgnlValueStack;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.HashMap;
     HttpHeaderResult result;
     HttpServletResponse response;
     Mock responseMock;
+    Mock invocationMock;
 
 
     public void testHeaderValuesAreNotParsedWhenParseIsFalse() throws Exception {
 
         Map values = new HashMap();
         values.put("bar", "abc");
-        ActionContext.getContext().getValueStack().push(values);
+        OgnlValueStack valueStack = ActionContext.getContext().getValueStack();
+        valueStack.push(values);
 
         OgnlUtil.setProperties(params, result);
 
         responseMock.expect("addHeader", C.args(C.eq("foo"), C.eq("abc")));
         responseMock.expect("addHeader", C.args(C.eq("baz"), C.eq("baz")));
+
+        // We need to do this twice in MockObject, maybe we should switch to easymock.
+        invocationMock.expectAndReturn("getStack", valueStack);
+        invocationMock.expectAndReturn("getStack", valueStack);
+
         result.execute(invocation);
+        invocationMock.verify();
         responseMock.verify();
     }
 
         result = new HttpHeaderResult();
         responseMock = new Mock(HttpServletResponse.class);
         response = (HttpServletResponse) responseMock.proxy();
-        invocation = (ActionInvocation) new Mock(ActionInvocation.class).proxy();
+        invocationMock = new Mock(ActionInvocation.class);
+        invocation = (ActionInvocation) invocationMock.proxy();
         ServletActionContext.setResponse(response);
     }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.