Commits

Anonymous committed 6a1bfca

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

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

Comments (0)

Files changed (2)

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

 
 /**
  * An abstract class that will auto populate the http response header of the current http request.
+ * Subclass would want to override {@link #afterHttpHeadersPopulatedExecute(String, com.opensymphony.xwork.ActionInvocation)}
+ * which would be called, after the http headers are being populated into {@link javax.servlet.http.HttpServletResponse}.
+ * Normally, we'd do
+ * <pre>
+ *    ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
+ * </pre>
+ * or
+ * <pre>
+ *    ServetActionContext.getResponse();
+ * </pre>
+ * to get hold of {@link javax.servlet.http.HttpServletResponse}.
+ *
  *
  * @see HttpHeaderResult
  * @see JasperReportsResult

src/test/com/opensymphony/webwork/views/HttpHeaderPopulatingResultTest.java

+/*
+ * Copyright (c) 2002-2007 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.webwork.views;
+
+import com.opensymphony.webwork.ServletActionContext;
+import com.opensymphony.webwork.WebWorkTestCase;
+import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.ActionInvocation;
+import com.opensymphony.xwork.mock.MockActionInvocation;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+import java.util.HashMap;
+
+/**
+ * A test case for {@link com.opensymphony.webwork.views.AbstractHttpHeaderPopulatingResult}.
+ *
+ * @author tmjee
+ * @version $Date$ $Id$
+ */
+public class HttpHeaderPopulatingResultTest extends WebWorkTestCase {
+
+    
+    public void test() throws Exception {
+        AbstractHttpHeaderPopulatingResult result = new AbstractHttpHeaderPopulatingResult() {
+            protected void afterHttpHeadersPopulatedExecute(String finalLocation, ActionInvocation invocation) throws Exception {
+                // do nothing
+            }
+        };
+
+
+        MockHttpServletResponse response = new MockHttpServletResponse();
+        MockActionInvocation actionInvocation = new MockActionInvocation();
+        actionInvocation.setInvocationContext(ActionContext.getContext());
+        actionInvocation.setStack(ActionContext.getContext().getValueStack());
+        actionInvocation.getInvocationContext().put(ServletActionContext.HTTP_RESPONSE, response);
+
+
+        result.getHeaders().put("header1", "header_value_1");
+        result.getHeaders().put("Content-Type", "text/html");
+        result.getHeaders().put("Cache-Control", "cache, must-revalidate");
+        result.getHeaders().put("Pragma", "public");
+        result.execute(actionInvocation);
+
+        assertEquals(response.getHeader("header1"), "header_value_1");
+        assertEquals(response.getHeader("Content-Type"), "text/html");
+        assertEquals(response.getHeader("Cache-Control"), "cache, must-revalidate");
+        assertEquals(response.getHeader("Pragma"), "public");
+        assertEquals(response.getHeader("no-such-header"), null);
+    }
+
+
+}