Author: mwringe
Date: 2010-10-06 10:37:52 -0400 (Wed, 06 Oct 2010)
New Revision: 4541
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v1/MarkupEndpoint.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
Log:
GTNWSRP-92: Setup the default values for RuntimeContext PortletInstanceKey and
NamespacePrefix when converting from V1 (optional) to V2 (required).
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java 2010-10-06
14:23:40 UTC (rev 4540)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java 2010-10-06
14:37:52 UTC (rev 4541)
@@ -27,6 +27,7 @@
import com.google.common.collect.Lists;
import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.api.OpaqueStateString;
+import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
import org.gatein.wsrp.WSRPConstants;
import org.gatein.wsrp.WSRPExceptionFactory;
import org.gatein.wsrp.WSRPTypeFactory;
@@ -269,11 +270,31 @@
}
}
- public static RuntimeContext toV2RuntimeContext(V1RuntimeContext v1RuntimeContext)
+ public static RuntimeContext toV2RuntimeContext(V1RuntimeContext v1RuntimeContext,
String portletHandle)
{
if (v1RuntimeContext != null)
{
- RuntimeContext runtimeContext =
WSRPTypeFactory.createRuntimeContext(v1RuntimeContext.getUserAuthentication(),
v1RuntimeContext.getPortletInstanceKey(), v1RuntimeContext.getNamespacePrefix());
+ String portletInstanceKey;
+ String namespacePrefix;
+ if
(ParameterValidation.isNullOrEmpty(v1RuntimeContext.getPortletInstanceKey()))
+ {
+ portletInstanceKey = portletHandle;
+ }
+ else
+ {
+ portletInstanceKey = v1RuntimeContext.getPortletInstanceKey();
+ }
+
+ if (ParameterValidation.isNullOrEmpty(v1RuntimeContext.getNamespacePrefix()))
+ {
+ namespacePrefix = PortletUtils.generateNamespaceFrom(portletHandle);
+ }
+ else
+ {
+ namespacePrefix = v1RuntimeContext.getNamespacePrefix();
+ }
+
+ RuntimeContext runtimeContext =
WSRPTypeFactory.createRuntimeContext(v1RuntimeContext.getUserAuthentication(),
portletInstanceKey, namespacePrefix);
SessionParams sessionParams =
WSRPTypeFactory.createSessionParams(v1RuntimeContext.getSessionID());
@@ -868,7 +889,7 @@
if (getMarkup != null)
{
PortletContext portletContext =
toV2PortletContext(getMarkup.getPortletContext());
- RuntimeContext runtimeContext =
toV2RuntimeContext(getMarkup.getRuntimeContext());
+ RuntimeContext runtimeContext =
toV2RuntimeContext(getMarkup.getRuntimeContext(), portletContext.getPortletHandle());
MarkupParams markupParams = toV2MarkupParams(getMarkup.getMarkupParams());
RegistrationContext registrationContext =
toV2RegistrationContext(getMarkup.getRegistrationContext());
UserContext userContext = toV2UserContext(getMarkup.getUserContext());
@@ -921,7 +942,7 @@
InteractionParams interactionParams =
toV2InteractionParams(performBlockingInteraction.getInteractionParams());
MarkupParams markupParams =
toV2MarkupParams(performBlockingInteraction.getMarkupParams());
PortletContext portletContext =
toV2PortletContext(performBlockingInteraction.getPortletContext());
- RuntimeContext runtimeContext =
toV2RuntimeContext(performBlockingInteraction.getRuntimeContext());
+ RuntimeContext runtimeContext =
toV2RuntimeContext(performBlockingInteraction.getRuntimeContext(),
portletContext.getPortletHandle());
return
WSRPTypeFactory.createPerformBlockingInteraction(toV2RegistrationContext(performBlockingInteraction.getRegistrationContext()),
portletContext, runtimeContext,
toV2UserContext(performBlockingInteraction.getUserContext()), markupParams,
interactionParams);
Modified:
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v1/MarkupEndpoint.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v1/MarkupEndpoint.java 2010-10-06
14:23:40 UTC (rev 4540)
+++
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v1/MarkupEndpoint.java 2010-10-06
14:37:52 UTC (rev 4541)
@@ -117,7 +117,7 @@
PerformBlockingInteraction performBlockingInteraction =
WSRPTypeFactory.createPerformBlockingInteraction(
V1ToV2Converter.toV2RegistrationContext(registrationContext),
V1ToV2Converter.toV2PortletContext(portletContext),
- V1ToV2Converter.toV2RuntimeContext(runtimeContext),
+ V1ToV2Converter.toV2RuntimeContext(runtimeContext,
portletContext.getPortletHandle()),
V1ToV2Converter.toV2UserContext(userContext),
V1ToV2Converter.toV2MarkupParams(markupParams),
V1ToV2Converter.toV2InteractionParams(interactionParams)
);
@@ -265,7 +265,7 @@
GetMarkup getMarkup = WSRPTypeFactory.createGetMarkup(
V1ToV2Converter.toV2RegistrationContext(registrationContext),
V1ToV2Converter.toV2PortletContext(portletContext),
- V1ToV2Converter.toV2RuntimeContext(runtimeContext),
+ V1ToV2Converter.toV2RuntimeContext(runtimeContext,
portletContext.getPortletHandle()),
V1ToV2Converter.toV2UserContext(userContext),
V1ToV2Converter.toV2MarkupParams(markupParams)
);
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-10-06
14:23:40 UTC (rev 4540)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-10-06
14:37:52 UTC (rev 4541)
@@ -125,6 +125,31 @@
}
@Test
+ public void testGetMarkupNoPortletInstanceKeyNoNamespacePrefix() throws Exception
+ {
+ V1GetMarkup getMarkup = createMarkupRequest();
+ getMarkup.getRuntimeContext().setNamespacePrefix(null);
+ getMarkup.getRuntimeContext().setPortletInstanceKey(null);
+
+ assertNull(getMarkup.getRuntimeContext().getNamespacePrefix());
+ assertNull(getMarkup.getRuntimeContext().getPortletInstanceKey());
+
+ V1MarkupResponse response = producer.getMarkup(getMarkup);
+
+ checkMarkupResponse(response, DEFAULT_VIEW_MARKUP);
+
+ getMarkup.getRuntimeContext().setNamespacePrefix("");
+ getMarkup.getRuntimeContext().setPortletInstanceKey("");
+
+ assertSame("", getMarkup.getRuntimeContext().getNamespacePrefix());
+ assertSame("", getMarkup.getRuntimeContext().getPortletInstanceKey());
+
+ response = producer.getMarkup(getMarkup);
+
+ checkMarkupResponse(response, DEFAULT_VIEW_MARKUP);
+ }
+
+ @Test
public void testInvalidGetMarkup() throws Exception
{
V1GetMarkup getMarkup = createMarkupRequest();
Show replies by date