Author: thomas.heute(a)jboss.com
Date: 2008-03-17 07:20:48 -0400 (Mon, 17 Mar 2008)
New Revision: 10285
Added:
branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/invocation/SessionAttributeResolver.java
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java
branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java
Log:
JBPORTAL-1952: Portal navigational state replication broken
JBPORTAL-1948: Render Parameters Not Replicated
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java 2008-03-15
01:55:13 UTC (rev 10284)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java 2008-03-17
11:20:48 UTC (rev 10285)
@@ -28,6 +28,7 @@
import org.jboss.portal.core.navstate.NavigationalStateContext;
import org.jboss.portal.core.navstate.NavigationalStateKey;
import org.jboss.portal.core.navstate.NavigationalStateObjectChange;
+import org.jboss.portal.core.model.portal.PortalObjectId;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -83,7 +84,8 @@
}
//
- return store.getAttribute(nsKey);
+ PortalObjectId id = (PortalObjectId)nsKey.getId();
+ return store.getAttribute(id.toString());
}
public void setAttribute(Object attrKey, Object attrValue) throws
IllegalArgumentException
@@ -198,7 +200,10 @@
maximizedKey = change.getKey();
}
}
- store.setAttribute(change.getKey(), change.getNewValue());
+
+ //
+ PortalObjectId id = (PortalObjectId)change.getKey().getId();
+ store.setAttribute(id.toString(), change.getNewValue());
}
// Unmaximize other windows if necessary
Modified:
branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java 2008-03-15
01:55:13 UTC (rev 10284)
+++
branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java 2008-03-17
11:20:48 UTC (rev 10285)
@@ -23,9 +23,7 @@
package org.jboss.portal.server.impl;
import org.jboss.portal.common.invocation.AbstractInvocationContext;
-import org.jboss.portal.common.invocation.resolver.PrincipalAttributeResolver;
import org.jboss.portal.common.invocation.resolver.RequestAttributeResolver;
-import org.jboss.portal.common.invocation.resolver.SessionAttributeResolver;
import org.jboss.portal.common.text.CharBuffer;
import org.jboss.portal.common.text.FastURLEncoder;
import org.jboss.portal.common.util.ParameterMap;
@@ -33,6 +31,7 @@
import org.jboss.portal.server.ServerInvocation;
import org.jboss.portal.server.ServerInvocationContext;
import org.jboss.portal.server.ServerURL;
+import org.jboss.portal.server.impl.invocation.SessionAttributeResolver;
import org.jboss.portal.server.request.URLContext;
import org.jboss.portal.server.request.URLFormat;
import org.jboss.portal.web.WebRequest;
@@ -133,8 +132,8 @@
//
addResolver(ServerInvocation.REQUEST_SCOPE, new RequestAttributeResolver(req));
- addResolver(ServerInvocation.SESSION_SCOPE, new SessionAttributeResolver(req,
PortalConstants.PORTAL_SESSION_MAP_KEY));
- addResolver(ServerInvocation.PRINCIPAL_SCOPE, new
PrincipalAttributeResolver(req));
+ addResolver(ServerInvocation.SESSION_SCOPE, new SessionAttributeResolver(req,
PortalConstants.PORTAL_SESSION_MAP_KEY, false));
+ addResolver(ServerInvocation.PRINCIPAL_SCOPE, new SessionAttributeResolver(req,
PortalConstants.PORTAL_PRINCIPAL_MAP_KEY, true));
}
public WebRequest getWebRequest()
Added:
branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/invocation/SessionAttributeResolver.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/invocation/SessionAttributeResolver.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/invocation/SessionAttributeResolver.java 2008-03-17
11:20:48 UTC (rev 10285)
@@ -0,0 +1,122 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.server.impl.invocation;
+
+import org.jboss.portal.common.invocation.AttributeResolver;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Enumeration;
+import java.util.Collections;
+import java.security.Principal;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class SessionAttributeResolver implements AttributeResolver
+{
+
+ /** . */
+ protected final HttpServletRequest req;
+
+ /** . */
+ protected final String prefix;
+
+ public SessionAttributeResolver(
+ HttpServletRequest req,
+ String prefix,
+ boolean principalScoped)
+ {
+ if (req == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (prefix == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ if (principalScoped)
+ {
+ Principal principal = req.getUserPrincipal();
+ if (principal != null)
+ {
+ prefix = prefix + principal.getName();
+ }
+ }
+
+ //
+ this.req = req;
+ this.prefix = prefix;
+ }
+
+ public Set getKeys()
+ {
+ HttpSession session = req.getSession(false);
+
+ //
+ if (session == null)
+ {
+ return Collections.EMPTY_SET;
+ }
+
+ //
+ Set keys = new HashSet();
+ for (Enumeration e = session.getAttributeNames();e.hasMoreElements();)
+ {
+ String key = (String)e.nextElement();
+
+ //
+ if (key.startsWith(prefix))
+ {
+ keys.add(key);
+ }
+ }
+
+ //
+ return keys;
+ }
+
+ public Object getAttribute(Object o) throws IllegalArgumentException
+ {
+ HttpSession session = req.getSession(false);
+
+ //
+ if (session == null)
+ {
+ return null;
+ }
+
+ //
+ return session.getAttribute(prefix + o);
+ }
+
+ public void setAttribute(Object o, Object o1) throws IllegalArgumentException
+ {
+ req.getSession().setAttribute(prefix + o, o1);
+ }
+}
\ No newline at end of file
Modified:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java
===================================================================
---
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java 2008-03-15
01:55:13 UTC (rev 10284)
+++
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java 2008-03-17
11:20:48 UTC (rev 10285)
@@ -25,6 +25,9 @@
import org.jboss.portal.common.util.ParameterMap;
import java.io.Serializable;
+import java.io.ObjectOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -149,4 +152,26 @@
return new PortletParameters(map);
}
}
+
+ private void writeObject(ObjectOutputStream out) throws IOException
+ {
+ out.writeInt(size());
+ for (Iterator i = entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Entry)i.next();
+ out.writeObject(entry.getKey());
+ out.writeObject(entry.getValue());
+ }
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException
+ {
+ int size = in.readInt();
+ while (size-- > 0)
+ {
+ String key = (String)in.readObject();
+ String[] values = (String[])in.readObject();
+ put(key, values);
+ }
+ }
}
Modified:
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java
===================================================================
---
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java 2008-03-15
01:55:13 UTC (rev 10284)
+++
modules/portlet/branches/JBP_PORTLET_BRANCH_1_0/portlet/src/main/org/jboss/portal/test/portlet/ParametersTestCase.java 2008-03-17
11:20:48 UTC (rev 10285)
@@ -23,11 +23,15 @@
package org.jboss.portal.test.portlet;
import org.jboss.portal.common.junit.ExtendedAssert;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.portlet.PortletParameters;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import java.util.Collections;
+import java.util.Set;
+import java.io.IOException;
import junit.framework.TestCase;
@@ -300,6 +304,17 @@
assertNull(param.getValue("a"));
}
+ public void testSerialization() throws IOException
+ {
+ param.setValue("foo", "bar");
+ PortletParameters clone = (PortletParameters)IOTools.clone(param);
+ assertNotNull(clone);
+ Set keys = clone.keySet();
+ assertEquals(1, keys.size());
+ assertTrue(keys.contains("foo"));
+ assertEquals("bar", clone.getValue("foo"));
+ }
+
public Class[] buildExceptionClasses()
{
return new Class[]