Author: chris.laprun(a)jboss.com
Date: 2010-12-07 07:12:39 -0500 (Tue, 07 Dec 2010)
New Revision: 5499
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/InitCookieMarkupBehavior.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/InitCookieMarkupBehavior.java
Log:
- GTNWSRP-182: Removed CookieProtocol field from SessionHandler and get the needed value
from the consumer instead so that the value never gets out of synch. Added test cases and
fixed existing test cases that didn't properly check that initCookie was called
*before* other methods.
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-12-07
12:04:01 UTC (rev 5498)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-12-07
12:12:39 UTC (rev 5499)
@@ -673,9 +673,7 @@
private RefreshResult refreshProducerInfo(boolean forceRefresh) throws
PortletInvokerException
{
- RefreshResult refreshResult = producerInfo.detailedRefresh(forceRefresh);
- sessionHandler.setRequiresInitCookie(producerInfo.getRequiresInitCookie());
- return refreshResult;
+ return producerInfo.detailedRefresh(forceRefresh);
}
public void releaseSessions() throws PortletInvokerException
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java 2010-12-07
12:04:01 UTC (rev 5498)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java 2010-12-07
12:12:39 UTC (rev 5499)
@@ -63,9 +63,6 @@
protected WSRPConsumerImpl consumer;
private static Logger log = LoggerFactory.getLogger(SessionHandler.class);
- /** Cookie protocol required by the producer with the consumer */
- private CookieProtocol requiresInitCookie;
-
/** The prefix used to isolate WSRP-related session information in the actual session
object. */
private static final String SESSION_ID_PREFIX = "org.gatein.wsrp.session.";
@@ -84,19 +81,14 @@
public boolean isPerUserCookieInit()
{
- return CookieProtocol.PER_USER.equals(requiresInitCookie);
+ return CookieProtocol.PER_USER.equals(getRequiresInitCookie());
}
public boolean requiresInitCookie()
{
- return requiresInitCookie != null &&
!CookieProtocol.NONE.equals(requiresInitCookie);
+ return getRequiresInitCookie() != null &&
!CookieProtocol.NONE.equals(getRequiresInitCookie());
}
- public void setRequiresInitCookie(CookieProtocol requiresInitCookie)
- {
- this.requiresInitCookie = requiresInitCookie;
- }
-
void initProducerSessionInformation(PortletInvocation invocation) throws
PortletInvokerException
{
// if we need cookies, set the current group id
@@ -116,7 +108,7 @@
private boolean requiresGroupInitCookie()
{
- return requiresInitCookie() &&
CookieProtocol.PER_GROUP.equals(requiresInitCookie);
+ return requiresInitCookie() &&
CookieProtocol.PER_GROUP.equals(getRequiresInitCookie());
}
/** Resets the information held by RequestHeaderClientHandler for the current
interaction. */
@@ -450,4 +442,10 @@
info.updateHandleAssociatedInfo(originalHandle, newHandle);
}
}
+
+ /** Cookie protocol required by the producer with the consumer */
+ private CookieProtocol getRequiresInitCookie()
+ {
+ return consumer.getProducerInfo().getRequiresInitCookie();
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java 2010-12-07
12:04:01 UTC (rev 5498)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java 2010-12-07
12:12:39 UTC (rev 5499)
@@ -31,8 +31,10 @@
import org.gatein.wsrp.test.protocol.v2.PortletManagementBehavior;
import org.gatein.wsrp.test.protocol.v2.RegistrationBehavior;
import org.gatein.wsrp.test.protocol.v2.ServiceDescriptionBehavior;
+import
org.gatein.wsrp.test.protocol.v2.behaviors.GroupedPortletsServiceDescriptionBehavior;
import org.gatein.wsrp.test.support.MockConsumerRegistry;
import org.oasis.wsrp.v2.AccessDenied;
+import org.oasis.wsrp.v2.CookieProtocol;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.InconsistentParameters;
import org.oasis.wsrp.v2.InvalidHandle;
@@ -55,6 +57,7 @@
import javax.jws.WebParam;
import javax.xml.namespace.QName;
import javax.xml.ws.Holder;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -445,6 +448,17 @@
assertNull(info.getInfoForEvent(null));
}
+ public void testRequiresInitCookieIsProperlySet() throws PortletInvokerException
+ {
+ ServiceDescriptionBehavior sdb = new GroupedPortletsServiceDescriptionBehavior(new
ArrayList<PortletDescription>(3));
+ sdb.setRequiresInitCookie(CookieProtocol.PER_GROUP);
+ serviceFactory.getRegistry().setServiceDescriptionBehavior(sdb);
+
+ info.refresh(false);
+
+ assertEquals(CookieProtocol.PER_GROUP, info.getRequiresInitCookie());
+ }
+
private static class TestPortletManagementBehavior extends PortletManagementBehavior
{
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-12-07
12:04:01 UTC (rev 5498)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-12-07
12:12:39 UTC (rev 5499)
@@ -238,6 +238,9 @@
// set init cookie requirement
producer.setRequiresInitCookie(cookieProtocol);
+ // Force ProducerInfo refresh so that we make sure that the consumer knows about
the new CookieProtocol
+ consumer.refreshProducerInfo();
+
// tell the producer which markup behavior we want to use
producer.setCurrentMarkupBehaviorHandle(handle);
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java 2010-12-07
12:04:01 UTC (rev 5498)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java 2010-12-07
12:12:39 UTC (rev 5499)
@@ -186,7 +186,6 @@
String handle = PerUserInitCookieMarkupBehavior.PER_USER_INIT_COOKIE_HANDLE;
InitCookieMarkupBehavior behavior =
(InitCookieMarkupBehavior)producer.getBehaviorRegistry().getMarkupBehaviorFor(handle);
-
ProducerSessionInformation sessionInfo = commonInitCookieTest(handle, behavior,
CookieProtocol.PER_USER.value());
ExtendedAssert.assertFalse(sessionInfo.isPerGroupCookies());
@@ -242,6 +241,9 @@
// set init cookie requirement
producer.setRequiresInitCookie(CookieProtocol.fromValue(cookieProtocol));
+ // Force ProducerInfo refresh so that we make sure that the consumer knows about
the new CookieProtocol
+ consumer.refreshProducerInfo();
+
// tell the producer which markup behavior we want to use
producer.setCurrentMarkupBehaviorHandle(handle);
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java 2010-12-07
12:04:01 UTC (rev 5498)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java 2010-12-07
12:12:39 UTC (rev 5499)
@@ -20,14 +20,36 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
*/
+
package org.gatein.wsrp.protocol.v2;
import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.test.ExtendedAssert;
import org.gatein.wsrp.test.protocol.v1.behaviors.BasicMarkupBehavior;
import org.gatein.wsrp.test.protocol.v1.behaviors.SessionMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.BehaviorRegistry;
+import org.gatein.wsrp.test.protocol.v2.ServiceDescriptionBehavior;
+import
org.gatein.wsrp.test.protocol.v2.behaviors.GroupedPortletsServiceDescriptionBehavior;
+import org.oasis.wsrp.v2.CookieProtocol;
+import org.oasis.wsrp.v2.EventDescription;
+import org.oasis.wsrp.v2.ExportDescription;
+import org.oasis.wsrp.v2.Extension;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.ItemDescription;
+import org.oasis.wsrp.v2.ModelDescription;
+import org.oasis.wsrp.v2.ModelTypes;
+import org.oasis.wsrp.v2.ModifyRegistrationRequired;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PortletDescription;
+import org.oasis.wsrp.v2.ResourceList;
+import org.oasis.wsrp.v2.ResourceSuspended;
+import javax.xml.ws.Holder;
+import java.util.List;
+
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -66,4 +88,48 @@
portlet =
consumer.getPortlet(PortletContext.createPortletContext(SessionMarkupBehavior.PORTLET_HANDLE));
checkPortlet(portlet, "2", SessionMarkupBehavior.PORTLET_HANDLE);
}
+
+ public void testRequiresInitCookieIsProperlySetOnConsumerInitiatedRefresh() throws
OperationFailed, ResourceSuspended, ModifyRegistrationRequired, InvalidRegistration,
PortletInvokerException
+ {
+ BehaviorRegistry registry = producer.getBehaviorRegistry();
+
+ Holder<List<PortletDescription>> offeredPortlets = new
Holder<List<PortletDescription>>();
+ registry.getServiceDescriptionBehavior().getServiceDescription(null, null, null,
null, new Holder<Boolean>(),
+ offeredPortlets, new Holder<List<ItemDescription>>(),
+ null, new Holder<List<ItemDescription>>(), new
Holder<List<ItemDescription>>(), new Holder<CookieProtocol>(), new
Holder<ModelDescription>(), new Holder<List<String>>(),
+ new Holder<ResourceList>(), new
Holder<List<EventDescription>>(), new Holder<ModelTypes>(), new
Holder<List<String>>(), new Holder<ExportDescription>(), new
Holder<Boolean>(), new Holder<List<Extension>>());
+ setServiceDescriptionBehavior(new
GroupedPortletsServiceDescriptionBehavior(offeredPortlets.value));
+ ServiceDescriptionBehavior sdb = new
GroupedPortletsServiceDescriptionBehavior(offeredPortlets.value);
+ sdb.setRequiresInitCookie(CookieProtocol.PER_GROUP);
+ setServiceDescriptionBehavior(sdb);
+
+ consumer.refreshProducerInfo();
+
+ ProducerInfo producerInfo = consumer.getProducerInfo();
+ assertEquals(CookieProtocol.PER_GROUP, producerInfo.getRequiresInitCookie());
+ assertTrue(consumer.getSessionHandler().requiresInitCookie());
+ }
+
+ public void testRequiresInitCookieIsProperlySetOnProducerInfoInitiatedRefresh() throws
OperationFailed, ResourceSuspended, ModifyRegistrationRequired, InvalidRegistration,
PortletInvokerException
+ {
+ BehaviorRegistry registry = producer.getBehaviorRegistry();
+
+ Holder<List<PortletDescription>> offeredPortlets = new
Holder<List<PortletDescription>>();
+ registry.getServiceDescriptionBehavior().getServiceDescription(null, null, null,
null, new Holder<Boolean>(),
+ offeredPortlets, new Holder<List<ItemDescription>>(),
+ null, new Holder<List<ItemDescription>>(), new
Holder<List<ItemDescription>>(), new Holder<CookieProtocol>(), new
Holder<ModelDescription>(), new Holder<List<String>>(),
+ new Holder<ResourceList>(), new
Holder<List<EventDescription>>(), new Holder<ModelTypes>(), new
Holder<List<String>>(), new Holder<ExportDescription>(), new
Holder<Boolean>(), new Holder<List<Extension>>());
+ setServiceDescriptionBehavior(new
GroupedPortletsServiceDescriptionBehavior(offeredPortlets.value));
+ ServiceDescriptionBehavior sdb = new
GroupedPortletsServiceDescriptionBehavior(offeredPortlets.value);
+ sdb.setRequiresInitCookie(CookieProtocol.PER_GROUP);
+ setServiceDescriptionBehavior(sdb);
+
+ consumer.getProducerInfo().refresh(true);
+
+ ProducerInfo producerInfo = consumer.getProducerInfo();
+ assertEquals(CookieProtocol.PER_GROUP, producerInfo.getRequiresInitCookie());
+
+ // SessionHandler needs to be updated if ProducerInfo is refreshed
+ assertTrue(consumer.getSessionHandler().requiresInitCookie());
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/InitCookieMarkupBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/InitCookieMarkupBehavior.java 2010-12-07
12:04:01 UTC (rev 5498)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/InitCookieMarkupBehavior.java 2010-12-07
12:12:39 UTC (rev 5499)
@@ -48,6 +48,7 @@
{
protected String portletHandle;
protected int initCookieCallCount;
+ private boolean initCookieCalled;
public InitCookieMarkupBehavior(BehaviorRegistry registry)
{
@@ -61,6 +62,11 @@
protected String getMarkupString(Mode mode, WindowState windowState, String
navigationalState, V1GetMarkup getMarkup) throws V1OperationFailed, V1InvalidCookie
{
+ if (!initCookieCalled)
+ {
+ throw new IllegalStateException("initCookie should have been called
first!");
+ }
+
String handle = getMarkup.getPortletContext().getPortletHandle();
if (portletHandle.equals(handle))
@@ -92,6 +98,7 @@
@Override
public List<V1Extension> initCookie(@WebParam(name =
"registrationContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v1:types") V1RegistrationContext registrationContext)
throws V1InvalidRegistration, V1AccessDenied, V1OperationFailed
{
+ initCookieCalled = true;
initCookieCallCount++;
return null;
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/InitCookieMarkupBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/InitCookieMarkupBehavior.java 2010-12-07
12:04:01 UTC (rev 5498)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/InitCookieMarkupBehavior.java 2010-12-07
12:12:39 UTC (rev 5499)
@@ -52,6 +52,7 @@
{
protected String portletHandle;
protected int initCookieCallCount;
+ private boolean initCookieCalled = false;
public InitCookieMarkupBehavior(BehaviorRegistry registry)
{
@@ -65,6 +66,11 @@
protected String getMarkupString(Mode mode, WindowState windowState, String
navigationalState, GetMarkup getMarkup) throws OperationFailed, InvalidCookie
{
+ if (!initCookieCalled)
+ {
+ throw new IllegalStateException("initCookie should have been called
first!");
+ }
+
String handle = getMarkup.getPortletContext().getPortletHandle();
if (portletHandle.equals(handle))
@@ -96,6 +102,7 @@
@Override
public List<Extension> initCookie(@WebParam(name =
"registrationContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") RegistrationContext registrationContext,
@WebParam(name = "userContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") UserContext userContext) throws
AccessDenied, InvalidRegistration, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
{
+ initCookieCalled = true;
initCookieCallCount++;
return null;
}