Author: chris.laprun(a)jboss.com
Date: 2008-06-13 19:49:32 -0400 (Fri, 13 Jun 2008)
New Revision: 11051
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/NeedPortletHandleTest.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPProducer.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
Log:
- JBPORTAL-857: Setting strict mode relaxes language code validation. Should probably be
implemented as
an interceptor to actually replace the in-out values before they make it to the
Producer.
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java 2008-06-13
21:58:52 UTC (rev 11050)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java 2008-06-13
23:49:32 UTC (rev 11051)
@@ -280,4 +280,9 @@
{
throw new UnsupportedOperationException("setProducerConfiguration not
implemented");
}
+
+ public void setUseStrictMode(boolean strict)
+ {
+ throw new UnsupportedOperationException("setUseStrictMode not
implemented");
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java 2008-06-13
21:58:52 UTC (rev 11050)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java 2008-06-13
23:49:32 UTC (rev 11051)
@@ -335,7 +335,7 @@
}
}
- public void testGetMarkupWithNonStandardLocales() throws Exception
+ public void testGetMarkupWithNonStandardLocalesStrictMode() throws Exception
{
undeploy(DEFAULT_MARKUP_PORTLET_WAR);
String getLocalesPortletArchive = "test-getlocales-portlet.war";
@@ -344,10 +344,9 @@
GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
getMarkup.getMarkupParams().setLocales(new String[]{"en_US"});
- MarkupResponse response = null;
try
{
- response = markupService.getMarkup(getMarkup);
+ markupService.getMarkup(getMarkup);
//fail("Should have trown an UnsupportetLocaleFault"); // ideally cf
http://jira.jboss.com/jira/browse/JBPORTAL-857
ExtendedAssert.fail("Should have trown an exception"); // right now
}
@@ -361,6 +360,23 @@
}
}
+ public void testGetMarkupWithNonStandardLocalesLenientMode() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String getLocalesPortletArchive = "test-getlocales-portlet.war";
+ deploy(getLocalesPortletArchive);
+
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+ getMarkup.getMarkupParams().setLocales(new String[]{"en_US"});
+
+ // Use the lenient mode
+ producer.setUseStrictMode(false);
+
+ // markup should be properly generated
+ checkMarkupResponse(markupService.getMarkup(getMarkup),
"GetLocalesPortlet");
+ undeploy(getLocalesPortletArchive);
+ }
+
public void testGetMarkupWithEncodedURLs() throws Exception
{
undeploy(DEFAULT_MARKUP_PORTLET_WAR);
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/NeedPortletHandleTest.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/NeedPortletHandleTest.java 2008-06-13
21:58:52 UTC (rev 11050)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/NeedPortletHandleTest.java 2008-06-13
23:49:32 UTC (rev 11051)
@@ -162,6 +162,9 @@
super.setUp();
this.mostUsedPortletWARFileName = getMostUsedPortletWARFileName();
deploy(mostUsedPortletWARFileName);
+
+ // reset strict mode
+ producer.setUseStrictMode(true);
}
/**
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPProducer.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPProducer.java 2008-06-13
21:58:52 UTC (rev 11050)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPProducer.java 2008-06-13
23:49:32 UTC (rev 11051)
@@ -114,4 +114,14 @@
* @since 2.6
*/
void setProducerConfiguration(ProducerConfiguration producerConfiguration);
+
+ /**
+ * Specifies whether conformance to WSRP specification should be strict or lenient
(this can help when working with
+ * non-complying consumers).
+ *
+ * @param strict <code>true</code> to be strict about WSRP conformance,
<code>false</code> to allow for some
+ * flexibility in the validation of received WSRP data
+ * @since 2.6.6
+ */
+ void setUseStrictMode(boolean strict);
}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2008-06-13
21:58:52 UTC (rev 11050)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2008-06-13
23:49:32 UTC (rev 11051)
@@ -23,6 +23,7 @@
package org.jboss.portal.wsrp;
+import org.jboss.logging.Logger;
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
import org.jboss.portal.common.i18n.LocaleFormat;
@@ -66,6 +67,15 @@
private static final String WSRP_WINDOW_STATE_NAME = "wsrp window state
name";
private static final String WINDOW_STATE = "WindowState";
+ private static boolean strict = true;
+ private static Logger log = Logger.getLogger(WSRPUtils.class);
+
+ public static void setStrict(boolean strict)
+ {
+ WSRPUtils.strict = strict;
+ log.debug("Using " + (strict ? "strict" : "lenient")
+ " language code validation mode.");
+ }
+
static
{
JSR168_WSRP_WINDOW_STATES.put(WindowState.MAXIMIZED.toString(),
WSRPConstants.MAXIMIZED_WINDOW_STATE);
@@ -299,7 +309,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(propertyDescription,
"RegistrationPropertyDescription");
PropertyDescription propDesc =
WSRPTypeFactory.createPropertyDescription(propertyDescription.getName().toString(),
- propertyDescription.getType());
+ propertyDescription.getType());
// todo: deal with languages properly!!
LocalizedString hint = propertyDescription.getHint();
@@ -324,7 +334,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(propertyDescription,
"PropertyDescription");
RegistrationPropertyDescription desc = new
RegistrationPropertyDescription(propertyDescription.getName(),
- propertyDescription.getType());
+ propertyDescription.getType());
desc.setLabel(getLocalizedStringOrNull(propertyDescription.getLabel()));
desc.setHint(getLocalizedStringOrNull(propertyDescription.getHint()));
@@ -376,7 +386,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(regLocalizedString,
"LocalizedString");
return
WSRPTypeFactory.createLocalizedString(toString(regLocalizedString.getLocale()),
- regLocalizedString.getResourceName(), regLocalizedString.getValue());
+ regLocalizedString.getResourceName(), regLocalizedString.getValue());
}
/**
@@ -416,13 +426,20 @@
public static Locale getLocale(String lang) throws IllegalArgumentException
{
+ String possiblyRelaxed = lang;
+ if (!WSRPUtils.strict)
+ {
+ // treat en_US as valid by en_US => en-US
+ // todo: maybe this should be handled by an interceptor...
+ possiblyRelaxed = lang.replace('_', '-');
+ }
+
try
{
- return LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale(lang);
+ return LocaleFormat.RFC3066_LANGUAGE_TAG.getLocale(possiblyRelaxed);
}
catch (ConversionException e)
{
- // Previous behavior on using ConversionException was like that
throw new IllegalArgumentException(e);
}
}
@@ -435,7 +452,6 @@
}
catch (ConversionException e)
{
- // Previous behavior on using ConversionException was like that
throw new IllegalArgumentException(e);
}
}
@@ -457,7 +473,7 @@
sb.append("(secure)");
}
sb.append("[M=").append(params.getMode()).append("][WS=").append(params.getWindowState()).append("]")
-
.append("[NS=").append(params.getNavigationalState()).append("]");
+
.append("[NS=").append(params.getNavigationalState()).append("]");
return sb.toString();
}
return null;
@@ -476,7 +492,7 @@
{
StringBuffer sb = new StringBuffer("InteractionParams");
sb.append("[IS=").append(interactionParams.getInteractionState()).append("]")
-
.append("[StateChange=").append(interactionParams.getPortletStateChange().getValue()).append("]");
+
.append("[StateChange=").append(interactionParams.getPortletStateChange().getValue()).append("]");
NamedString[] formParams = interactionParams.getFormParameters();
if (formParams != null)
{
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2008-06-13
21:58:52 UTC (rev 11050)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2008-06-13
23:49:32 UTC (rev 11051)
@@ -38,6 +38,7 @@
import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPExceptionFactory;
import org.jboss.portal.wsrp.WSRPProducer;
+import org.jboss.portal.wsrp.WSRPUtils;
import org.jboss.portal.wsrp.core.AccessDeniedFault;
import org.jboss.portal.wsrp.core.BlockingInteractionResponse;
import org.jboss.portal.wsrp.core.ClonePortlet;
@@ -272,6 +273,7 @@
public void setUseStrictMode(boolean strict)
{
RegistrationUtils.setStrict(strict);
+ WSRPUtils.setStrict(strict);
}
protected void startService() throws Exception