Author: mwringe
Date: 2010-10-15 13:46:17 -0400 (Fri, 15 Oct 2010)
New Revision: 4689
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
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/V2ToV1Converter.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/WSRP1TypeFactory.java
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V1ToV2ConverterTestCase.java
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V2ToV1ConverterTestCase.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/MarkupBehavior.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/MarkupBehavior.java
Log:
GTNWSRP-101: update how we handle markup contexts so that at handled more correctly, we
need to take into consideration the isUseCachedMarkup when determining if the required
values are set. Update tests to check for this behaviour.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-10-15
16:39:36 UTC (rev 4688)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-10-15
17:46:17 UTC (rev 4689)
@@ -583,39 +583,35 @@
* case this character set MAY be different than the response message.
* <p/>
*/
- public static MarkupContext createMarkupContext(String mediaType, String
markupString)
+ public static MarkupContext createMarkupContext(String mediaType, String markupString,
byte[] markupBinary, Boolean useCachedItem)
{
- //TODO: this should be allowed to be null
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mediaType, "Media
type", "MarkupContext");
- if (markupString == null)
- {
- throw new IllegalArgumentException("MarkupContext requires either a
non-null markup string or binary markup.");
- }
+ boolean isUseCachedItem = (useCachedItem == null) ? false :
useCachedItem.booleanValue();
+
MarkupContext markupContext = new MarkupContext();
markupContext.setMimeType(mediaType);
- markupContext.setItemString(markupString);
- return markupContext;
- }
-
- /**
- * @param mediaType The mime type of the returned markup. The mimeType field MUST be
specified whenever markup is
- * returned, and if the markupBinary field is used to return the
markup, the mime type MUST include
- * the character set for textual mime types using the syntax
specified in RFC1522[14] (e.g.
- * "text/html; charset=UTF-8"). In this particular case
this character set MAY be different than the
- * response message.
- * @return a new MarkupContext
- */
- public static MarkupContext createMarkupContext(String mediaType, byte[]
markupBinary)
- {
- //TODO: this should be allowed to be null
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mediaType, "MIME
type", "MarkupContext");
- if (markupBinary == null || markupBinary.length == 0)
+
+ if (isUseCachedItem)
{
- throw new IllegalArgumentException("MarkupContext requires either a
non-null markup string or binary markup.");
+ markupContext.setUseCachedItem(useCachedItem);
}
- MarkupContext markupContext = new MarkupContext();
- markupContext.setMimeType(mediaType);
- markupContext.setItemBinary(markupBinary);
+ else
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mediaType, "Media
type", "MarkupContext");
+
+ if (markupBinary != null)
+ {
+ markupContext.setItemBinary(markupBinary);
+ }
+ else if (markupString != null)
+ {
+ markupContext.setItemString(markupString);
+ }
+ else
+ {
+ throw new IllegalArgumentException("MarkupContext required either a true
useCacheItem or a non-null markup string or binary markup");
+ }
+ }
+
return markupContext;
}
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-15
16:39:36 UTC (rev 4688)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java 2010-10-15
17:46:17 UTC (rev 4689)
@@ -772,25 +772,13 @@
{
if (v1MarkupContext != null)
{
- MarkupContext result;
-
- byte[] binary = v1MarkupContext.getMarkupBinary();
- String string = v1MarkupContext.getMarkupString();
-
- if (string != null)
- {
- result = WSRPTypeFactory.createMarkupContext(v1MarkupContext.getMimeType(),
string);
- }
- else
- {
- result = WSRPTypeFactory.createMarkupContext(v1MarkupContext.getMimeType(),
binary);
- }
+ MarkupContext result =
WSRPTypeFactory.createMarkupContext(v1MarkupContext.getMimeType(),
v1MarkupContext.getMarkupString(), v1MarkupContext.getMarkupBinary(),
v1MarkupContext.isUseCachedMarkup());
+
result.setCacheControl(toV2CacheControl(v1MarkupContext.getCacheControl()));
result.setLocale(v1MarkupContext.getLocale());
result.setMimeType(v1MarkupContext.getMimeType());
result.setPreferredTitle(v1MarkupContext.getPreferredTitle());
result.setRequiresRewriting(v1MarkupContext.isRequiresUrlRewriting());
- result.setUseCachedItem(v1MarkupContext.isUseCachedMarkup());
List<V1Extension> extensions = v1MarkupContext.getExtensions();
if (extensions != null)
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java 2010-10-15
16:39:36 UTC (rev 4688)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java 2010-10-15
17:46:17 UTC (rev 4689)
@@ -515,23 +515,12 @@
public static V1MarkupContext toV1MarkupContext(MarkupContext markupContext)
{
if (markupContext != null)
- {
- byte[] binary = markupContext.getItemBinary();
- String string = markupContext.getItemString();
- V1MarkupContext v1MarkupContext;
- if (string != null)
- {
- v1MarkupContext =
WSRP1TypeFactory.createMarkupContext(markupContext.getMimeType(), string);
- }
- else
- {
- v1MarkupContext =
WSRP1TypeFactory.createMarkupContext(markupContext.getMimeType(), binary);
- }
+ {
+ V1MarkupContext v1MarkupContext =
WSRP1TypeFactory.createMarkupContext(markupContext.getMimeType(),
markupContext.getItemString(), markupContext.getItemBinary(),
markupContext.isUseCachedItem());
v1MarkupContext.setCacheControl(toV1CacheControl(markupContext.getCacheControl()));
v1MarkupContext.setLocale(markupContext.getLocale());
v1MarkupContext.setPreferredTitle(markupContext.getPreferredTitle());
v1MarkupContext.setRequiresUrlRewriting(markupContext.isRequiresRewriting());
- v1MarkupContext.setUseCachedMarkup(markupContext.isUseCachedItem());
List<Extension> extensions = markupContext.getExtensions();
if (extensions != null)
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/WSRP1TypeFactory.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/WSRP1TypeFactory.java 2010-10-15
16:39:36 UTC (rev 4688)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/WSRP1TypeFactory.java 2010-10-15
17:46:17 UTC (rev 4689)
@@ -505,41 +505,34 @@
*
* @return
*/
- public static V1MarkupContext createMarkupContext(String mediaType, String
markupString)
+ public static V1MarkupContext createMarkupContext(String mediaType, String
markupString, byte[] markupBinary, Boolean useCacheItem)
{
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mediaType, "Media
type", "MarkupContext");
- if (markupString == null)
- {
- throw new IllegalArgumentException("MarkupContext requires either a
non-null markup string or binary markup.");
- }
+ boolean isUseCacheItem = (useCacheItem == null) ? false :
useCacheItem.booleanValue();
+
V1MarkupContext markupContext = new V1MarkupContext();
markupContext.setMimeType(mediaType);
- markupContext.setMarkupString(markupString);
- return markupContext;
- }
-
- /**
- * useCachedMarkup(xsd:boolean[false])?, mimeType(xsd:string)?,
(markupString(xsd:string) |
- * markupBinary(xsd:base64Binary)), locale(xsd:string)?,
requiresUrlRewriting(xsd:boolean[false])?,
- * cacheControl(CacheControl)?, preferredTitle(xsd:string)?, extensions(Extension)*
- *
- * @param mediaType The mime type of the returned markup. The mimeType field MUST be
specified whenever markup is
- * returned, and if the markupBinary field is used to return the
markup, the mime type MUST include
- * the character set for textual mime types using the syntax
specified in RFC1522[14] (e.g.
- * "text/html; charset=UTF-8"). In this particular case
this character set MAY be different than the
- * response message.
- * @return a new MarkupContext
- */
- public static V1MarkupContext createMarkupContext(String mediaType, byte[]
markupBinary)
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mediaType, "MIME
type", "MarkupContext");
- if (markupBinary == null || markupBinary.length == 0)
+
+ if (isUseCacheItem)
{
- throw new IllegalArgumentException("MarkupContext requires either a
non-null markup string or binary markup.");
+ markupContext.setUseCachedMarkup(useCacheItem);
}
- V1MarkupContext markupContext = new V1MarkupContext();
- markupContext.setMimeType(mediaType);
- markupContext.setMarkupBinary(markupBinary);
+ else
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mediaType, "MIME
type", "MarkupContext");
+ if (markupBinary != null)
+ {
+ markupContext.setMarkupBinary(markupBinary);
+ }
+ else if (markupString != null)
+ {
+ markupContext.setMarkupString(markupString);
+ }
+ else
+ {
+ throw new IllegalArgumentException("MarkupContext required either a true
useCacheItem or a non-null markup string or binary markup");
+ }
+ }
+
return markupContext;
}
Modified:
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V1ToV2ConverterTestCase.java
===================================================================
---
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V1ToV2ConverterTestCase.java 2010-10-15
16:39:36 UTC (rev 4688)
+++
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V1ToV2ConverterTestCase.java 2010-10-15
17:46:17 UTC (rev 4689)
@@ -24,9 +24,13 @@
package org.gatein.wsrp.spec.v1;
import junit.framework.TestCase;
+
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.oasis.wsrp.v1.V1MarkupContext;
import org.oasis.wsrp.v1.V1OperationFailed;
import org.oasis.wsrp.v1.V1OperationFailedFault;
import org.oasis.wsrp.v2.InvalidSession;
+import org.oasis.wsrp.v2.MarkupContext;
import org.oasis.wsrp.v2.OperationFailed;
/**
@@ -89,4 +93,69 @@
// expected
}
}
+
+ public void testToV2MarkupContext()
+ {
+ //test with mimetype and markupstring
+ V1MarkupContext v1MarkupContext = new V1MarkupContext();
+ v1MarkupContext.setMarkupString("test_1");
+ v1MarkupContext.setMimeType("mimeType_1");
+ MarkupContext markupContext = V1ToV2Converter.toV2MarkupContext(v1MarkupContext);
+ assertEquals("test_1", markupContext.getItemString());
+ assertEquals("mimeType_1", markupContext.getMimeType());
+ assertNull(markupContext.getItemBinary());
+
+ //test without the mimetype
+ v1MarkupContext.setMimeType(null);
+ try
+ {
+ V1ToV2Converter.toV2MarkupContext(v1MarkupContext);
+ ExtendedAssert.fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ //expected
+ }
+
+ //test with mimetype and markupbinary
+ v1MarkupContext = new V1MarkupContext();
+ v1MarkupContext.setMarkupBinary(new byte[]{1,2,3});
+ v1MarkupContext.setMimeType("mimeType_2");
+ markupContext = V1ToV2Converter.toV2MarkupContext(v1MarkupContext);
+ ExtendedAssert.assertEquals(new byte[]{1,2,3}, markupContext.getItemBinary());
+ assertEquals("mimeType_2", markupContext.getMimeType());
+ assertNull(markupContext.getItemString());
+
+ //test without the mimetype
+ v1MarkupContext.setMimeType(null);
+ try
+ {
+ V1ToV2Converter.toV2MarkupContext(v1MarkupContext);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ //expected
+ }
+
+ //test with useCachedMarkup
+ v1MarkupContext = new V1MarkupContext();
+ v1MarkupContext.setUseCachedMarkup(Boolean.TRUE);
+ markupContext = V1ToV2Converter.toV2MarkupContext(v1MarkupContext);
+ assertNull(markupContext.getItemString());
+ assertNull(markupContext.getItemBinary());
+ assertTrue(markupContext.isUseCachedItem().booleanValue());
+
+ v1MarkupContext = new V1MarkupContext();
+ v1MarkupContext.setUseCachedMarkup(Boolean.FALSE);
+ try
+ {
+ V1ToV2Converter.toV2MarkupContext(v1MarkupContext);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ //expected
+ }
+ }
}
Modified:
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V2ToV1ConverterTestCase.java
===================================================================
---
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V2ToV1ConverterTestCase.java 2010-10-15
16:39:36 UTC (rev 4688)
+++
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V2ToV1ConverterTestCase.java 2010-10-15
17:46:17 UTC (rev 4689)
@@ -31,15 +31,18 @@
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.spec.v2.ErrorCodes;
import org.gatein.wsrp.spec.v2.ErrorCodes.Codes;
+import org.gatein.wsrp.test.ExtendedAssert;
import org.oasis.wsrp.v1.V1DestroyFailed;
import org.oasis.wsrp.v1.V1InvalidSession;
import org.oasis.wsrp.v1.V1ItemDescription;
+import org.oasis.wsrp.v1.V1MarkupContext;
import org.oasis.wsrp.v1.V1NamedString;
import org.oasis.wsrp.v1.V1OperationFailed;
import org.oasis.wsrp.v1.V1SessionContext;
import org.oasis.wsrp.v2.FailedPortlets;
import org.oasis.wsrp.v2.ItemDescription;
import org.oasis.wsrp.v2.LocalizedString;
+import org.oasis.wsrp.v2.MarkupContext;
import org.oasis.wsrp.v2.NamedString;
import org.oasis.wsrp.v2.OperationFailed;
import org.oasis.wsrp.v2.SessionContext;
@@ -227,5 +230,71 @@
return destroyFailedList.iterator().next();
}
+
+ public void testToV1MarkupContext()
+ {
+ //test with mimetype and markupstring
+ MarkupContext markupContext = new MarkupContext();
+ markupContext.setMimeType("mimeType_1");
+ markupContext.setItemString("string_1");
+ V1MarkupContext v1MarkupContext =
V2ToV1Converter.toV1MarkupContext(markupContext);
+ assertEquals("mimeType_1", v1MarkupContext.getMimeType());
+ assertEquals("string_1", v1MarkupContext.getMarkupString());
+ assertNull(v1MarkupContext.getMarkupBinary());
+
+ //test without the mimetype
+ markupContext.setMimeType(null);
+ try
+ {
+ V2ToV1Converter.toV1MarkupContext(markupContext);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ //expected
+ }
+
+ //test with mimetype and markupbinary
+ markupContext = new MarkupContext();
+ markupContext.setMimeType("mimeType_2");
+ markupContext.setItemBinary(new byte[]{2,1,3});
+ v1MarkupContext = V2ToV1Converter.toV1MarkupContext(markupContext);
+ assertEquals("mimeType_2", v1MarkupContext.getMimeType());
+ ExtendedAssert.assertEquals(new byte[]{2,1,3}, v1MarkupContext.getMarkupBinary());
+ assertNull(v1MarkupContext.getMarkupString());
+
+ //test without the mimetype
+ markupContext.setMimeType(null);
+ try
+ {
+ V2ToV1Converter.toV1MarkupContext(markupContext);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ //expected
+ }
+
+ //test with useCachedMarkup
+ markupContext = new MarkupContext();
+ markupContext.setUseCachedItem(Boolean.TRUE);
+ v1MarkupContext = V2ToV1Converter.toV1MarkupContext(markupContext);
+ assertNull(v1MarkupContext.getMarkupString());
+ assertNull(v1MarkupContext.getMarkupBinary());
+ assertTrue(v1MarkupContext.isUseCachedMarkup().booleanValue());
+
+ markupContext = new MarkupContext();
+ markupContext.setUseCachedItem(Boolean.FALSE);
+ try
+ {
+ V2ToV1Converter.toV1MarkupContext(markupContext);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ //expected
+ }
+
+ }
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java 2010-10-15
16:39:36 UTC (rev 4688)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java 2010-10-15
17:46:17 UTC (rev 4689)
@@ -76,19 +76,19 @@
if (markup != null && binary != null)
{
return new ErrorResponse(new IllegalArgumentException("Markup response
cannot contain both string and binary " +
- "markup. Per Section 6.1.10 of the WSRP specification, this is a
Producer error."));
+ "markup. Per Section 6.1.10 of the WSRP 1.0 specification, this is a
Producer error."));
}
if (markup == null && binary == null)
{
- if (mimeResponse.isUseCachedItem())
+ if (mimeResponse.isUseCachedItem() != null &&
mimeResponse.isUseCachedItem())
{
//todo: deal with cache GTNWSRP-40
}
else
{
return new ErrorResponse(new IllegalArgumentException("Markup response
must contain at least string or binary" +
- " markup. Per Section 6.1.10 of the WSRP specification, this is a
Producer error."));
+ " markup. Per Section 6.1.10 of the WSRP 1.0 specification, this is a
Producer error."));
}
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/MarkupBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/MarkupBehavior.java 2010-10-15
16:39:36 UTC (rev 4688)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/MarkupBehavior.java 2010-10-15
17:46:17 UTC (rev 4689)
@@ -165,7 +165,7 @@
String markupString =
getMarkupString(WSRPUtils.getJSR168PortletModeFromWSRPName(markupParams.getMode()),
WSRPUtils.getJSR168WindowStateFromWSRPName(markupParams.getWindowState()),
markupParams.getNavigationalState(), gm);
- markupContext.value =
WSRP1TypeFactory.createMarkupContext(MediaType.TEXT_HTML.getValue(), markupString);
+ markupContext.value =
WSRP1TypeFactory.createMarkupContext(MediaType.TEXT_HTML.getValue(), markupString, null,
null);
markupContext.value.setRequiresUrlRewriting(Boolean.TRUE);
V1MarkupResponse markupResponse =
WSRP1TypeFactory.createMarkupResponse(markupContext.value);
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/MarkupBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/MarkupBehavior.java 2010-10-15
16:39:36 UTC (rev 4688)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/MarkupBehavior.java 2010-10-15
17:46:17 UTC (rev 4689)
@@ -177,7 +177,7 @@
navigationalContext != null ? navigationalContext.getOpaqueValue() : null,
gm);
- markupContext.value =
WSRPTypeFactory.createMarkupContext(MediaType.TEXT_HTML.getValue(), markupString);
+ markupContext.value =
WSRPTypeFactory.createMarkupContext(MediaType.TEXT_HTML.getValue(), markupString, null,
null);
markupContext.value.setRequiresRewriting(Boolean.TRUE);
MarkupResponse markupResponse =
WSRPTypeFactory.createMarkupResponse(markupContext.value);