You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ni...@apache.org on 2007/08/10 16:16:26 UTC
svn commit: r564602 - in /struts/struts2/trunk/plugins/portlet/src:
main/java/org/apache/struts2/portlet/context/
main/java/org/apache/struts2/portlet/dispatcher/
main/java/org/apache/struts2/portlet/interceptor/ main/resources/
test/java/org/apache/st...
Author: nilsga
Date: Fri Aug 10 07:16:24 2007
New Revision: 564602
URL: http://svn.apache.org/viewvc?view=rev&rev=564602
Log:
WW-2053,WW-2101 Removed ServletContextHolder - Using mock servlet object instead. New interceptor for state handling.
Added:
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java
Removed:
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/ServletContextHolderListener.java
struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/context/ServletContextHolderListenerTest.java
Modified:
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
struts/struts2/trunk/plugins/portlet/src/main/resources/struts-plugin.xml
struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java
Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java?view=diff&rev=564602&r1=564601&r2=564602
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java Fri Aug 10 07:16:24 2007
@@ -21,7 +21,6 @@
package org.apache.struts2.portlet.dispatcher;
import java.io.IOException;
-import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
@@ -58,7 +57,6 @@
import org.apache.struts2.portlet.PortletRequestMap;
import org.apache.struts2.portlet.PortletSessionMap;
import org.apache.struts2.portlet.context.PortletActionContext;
-import org.apache.struts2.portlet.context.ServletContextHolderListener;
import org.apache.struts2.portlet.servlet.PortletServletContext;
import org.apache.struts2.portlet.servlet.PortletServletRequest;
import org.apache.struts2.portlet.servlet.PortletServletResponse;
@@ -67,13 +65,11 @@
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionProxyFactory;
-import com.opensymphony.xwork2.ValidationAware;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.util.FileManager;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import com.opensymphony.xwork2.util.TextUtils;
-import com.opensymphony.xwork2.util.ValueStack;
/**
* <!-- START SNIPPET: javadoc -->
@@ -84,7 +80,7 @@
* </p>
* <!-- END SNIPPET: javadoc -->
*
- * @author <a href="nils-helge.garli@bekk.no">Nils-Helge Garli </a>
+ * @author Nils-Helge Garli
* @author Rainer Hermanns
*
* <p><b>Init parameters</b></p>
@@ -196,8 +192,7 @@
params.put(name, value);
}
- Dispatcher.setPortletSupportActive(true);
- dispatcherUtils = new Dispatcher(ServletContextHolderListener.getServletContext(), params);
+ dispatcherUtils = new Dispatcher(new PortletServletContext(cfg.getPortletContext()), params);
dispatcherUtils.init();
// For testability
@@ -432,26 +427,7 @@
proxy.setMethod(mapping.getMethod());
request.setAttribute("struts.valueStack", proxy.getInvocation()
.getStack());
- if (PortletActionConstants.RENDER_PHASE.equals(phase)
- && TextUtils.stringSet(request
- .getParameter(EVENT_ACTION))) {
- Object action = request.getPortletSession()
- .getAttribute(EVENT_ACTION);
- if (action != null) {
- ValueStack stack = proxy.getInvocation().getStack();
- Object top = stack.pop();
- stack.push(action);
- stack.push(top);
- }
- }
proxy.execute();
- if (PortletActionConstants.EVENT_PHASE.equals(phase)) {
- // Store the executed action in the session for retrieval in the
- // render phase.
- ActionResponse actionResp = (ActionResponse) response;
- request.getPortletSession().setAttribute(EVENT_ACTION, proxy.getAction());
- actionResp.setRenderParameter(EVENT_ACTION, "true");
- }
} catch (ConfigurationException e) {
LOG.error("Could not find action", e);
throw new PortletException("Could not find action " + actionName, e);
Added: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java?view=auto&rev=564602
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java (added)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java Fri Aug 10 07:16:24 2007
@@ -0,0 +1,64 @@
+package org.apache.struts2.portlet.interceptor;
+
+import java.util.Map;
+
+import javax.portlet.ActionResponse;
+import javax.portlet.RenderRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.portlet.PortletActionConstants;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
+import com.opensymphony.xwork2.util.CompoundRoot;
+import com.opensymphony.xwork2.util.TextUtils;
+import com.opensymphony.xwork2.util.ValueStack;
+
+public class PortletStateInterceptor extends AbstractInterceptor implements PortletActionConstants {
+
+ private final static Log LOG = LogFactory.getLog(PortletStateInterceptor.class);
+
+ private static final long serialVersionUID = 6138452063353911784L;
+
+ @Override
+ public String intercept(ActionInvocation invocation) throws Exception {
+ Integer phase = (Integer) invocation.getInvocationContext().get(PHASE);
+ if (RENDER_PHASE.equals(phase)) {
+ restoreStack(invocation);
+ return invocation.invoke();
+ } else if (EVENT_PHASE.equals(phase)) {
+ try {
+ return invocation.invoke();
+ } finally {
+ saveStack(invocation);
+ }
+ } else {
+ return invocation.invoke();
+ }
+ }
+
+ private void saveStack(ActionInvocation invocation) {
+ Map session = invocation.getInvocationContext().getSession();
+ session.put("struts.portlet.valueStackFromEventPhase", invocation.getStack());
+ ActionResponse actionResponse = (ActionResponse) invocation.getInvocationContext().get(RESPONSE);
+ actionResponse.setRenderParameter(EVENT_ACTION, "true");
+ }
+
+ private void restoreStack(ActionInvocation invocation) {
+ RenderRequest request = (RenderRequest) invocation.getInvocationContext().get(REQUEST);
+ if (TextUtils.stringSet(request.getParameter(EVENT_ACTION))) {
+ LOG.debug("Restoring value stack from event phase");
+ ValueStack oldStack = (ValueStack) invocation.getInvocationContext().getSession().get(
+ "struts.portlet.valueStackFromEventPhase");
+ if (oldStack != null) {
+ CompoundRoot oldRoot = oldStack.getRoot();
+ ValueStack currentStack = invocation.getStack();
+ CompoundRoot root = currentStack.getRoot();
+ root.addAll(oldRoot);
+ LOG.debug("Restored stack");
+ }
+ }
+ }
+
+}
Modified: struts/struts2/trunk/plugins/portlet/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/resources/struts-plugin.xml?view=diff&rev=564602&r1=564601&r2=564602
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/resources/struts-plugin.xml (original)
+++ struts/struts2/trunk/plugins/portlet/src/main/resources/struts-plugin.xml Fri Aug 10 07:16:24 2007
@@ -41,8 +41,9 @@
<interceptors>
<interceptor name="portletAware" class="org.apache.struts2.portlet.interceptor.PortletAwareInterceptor"/>
-
+ <interceptor name="portletState" class="org.apache.struts2.portlet.interceptor.PortletStateInterceptor"/>
<interceptor-stack name="portletDefaultStack">
+ <interceptor-ref name="portletState"/>
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="portletAware" />
</interceptor-stack>
Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java?view=diff&rev=564602&r1=564601&r2=564602
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java Fri Aug 10 07:16:24 2007
@@ -44,7 +44,6 @@
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.portlet.PortletActionConstants;
-import org.apache.struts2.portlet.context.ServletContextHolderListener;
import org.jmock.Mock;
import org.jmock.cglib.MockObjectTestCase;
import org.jmock.core.Constraint;
@@ -80,6 +79,7 @@
mockConfig = mock(PortletConfig.class);
mockCtx = mock(PortletContext.class);
mockConfig.stubs().method(ANYTHING);
+ mockCtx.stubs().method(ANYTHING);
setupStub(initParams, mockConfig, "getInitParameter");
mockCtx.stubs().method("getAttributeNames").will(returnValue(Collections.enumeration(attributes.keySet())));
setupStub(attributes, mockCtx, "getAttribute");
@@ -88,7 +88,6 @@
setupStub(initParams, mockCtx, "getInitParameter");
mockConfig.stubs().method("getInitParameterNames").will(returnValue(Collections.enumeration(initParams.keySet())));
setupStub(initParams, mockConfig, "getInitParameter");
-
mockConfig.stubs().method("getResourceBundle").will(returnValue(new ListResourceBundle() {
protected Object[][] getContents() {
return new String[][]{{"javax.portlet.title", "MyTitle"}};
@@ -116,10 +115,7 @@
public void testRender_ok() {
final Mock mockResponse = mock(RenderResponse.class);
mockResponse.stubs().method(ANYTHING);
- final Mock servletContext = mock(ServletContext.class);
- servletContext.stubs().method(ANYTHING);
- ServletContextEvent event = new ServletContextEvent((ServletContext)servletContext.proxy());
- new ServletContextHolderListener().contextInitialized(event);
+
PortletMode mode = PortletMode.VIEW;
Map requestParams = new HashMap();
@@ -170,16 +166,6 @@
initPortletConfig(initParams, new HashMap());
initRequest(requestParams, new HashMap(), new HashMap(), new HashMap(), PortletMode.VIEW, WindowState.NORMAL, true, null);
setupActionFactory("/view", "testAction", "success", ValueStackFactory.getFactory().createValueStack());
- Constraint[] paramConstraints = new Constraint[] {
- eq(PortletActionConstants.EVENT_ACTION), same(mockAction.proxy()) };
-
- mockSession.expects(once()).method("setAttribute").with(
- paramConstraints);
-
- mockResponse.expects(once()).method("setRenderParameter").with(
- new Constraint[] { eq(PortletActionConstants.EVENT_ACTION),
- eq("true") });
-
//mockSession.expects(once()).method("setAttribute").with(new Constraint[]{eq(PortletActionConstants.LAST_MODE), eq(PortletMode.VIEW)});
try {
dispatcher