Author: chris.laprun(a)jboss.com
Date: 2009-06-17 17:29:16 -0400 (Wed, 17 Jun 2009)
New Revision: 13470
Modified:
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/other/WSRPPortletURLTestCase.java
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPPortletURL.java
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPResourceURL.java
Log:
- JBPORTAL-2425:
+ WSRPPortletURL.create is now able to handle extra characters in an uninterpreted way
to allow for concatenation
+ Adapted toString methods.
- Fixed a bug in WSRPResourceURL.dealWithSpecificParams that wasn't properly removing
consumed parameters.
Modified:
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/other/WSRPPortletURLTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/other/WSRPPortletURLTestCase.java 2009-06-17
21:24:28 UTC (rev 13469)
+++
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/other/WSRPPortletURLTestCase.java 2009-06-17
21:29:16 UTC (rev 13470)
@@ -132,6 +132,21 @@
checkInvalidURL(stillInvalid, "Should have detected missing end token",
WSRPRewritingConstants.END_WSRP_REWRITE);
}
+ public void testExtraRelaxedValidation()
+ {
+ String valid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite/helloworld.jar";
+ WSRPPortletURL url = WSRPPortletURL.create(valid);
+ assertEquals("http://localhost:8080/helloworld/helloworld.jar",
url.toString());
+
+ String invalid =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&foo=bar/helloworld.jar";
+ checkInvalidURL(invalid, "Should have detected improper position of end
token", WSRPRewritingConstants.END_WSRP_REWRITE);
+
+ WSRPPortletURL.setStrict(false);
+ String validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&foo=bar/helloworld.jar";
+ url = WSRPPortletURL.create(validInRelaxedMode);
+
assertEquals("http://localhost:8080/helloworld&foo=bar/helloworld.jar",
url.toString());
+ }
+
public void testExtraParameters()
{
String validInRelaxedMode =
"wsrp_rewrite?wsrp-urlType=render&foo=bar/wsrp_rewrite";
Modified:
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPPortletURL.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPPortletURL.java 2009-06-17
21:24:28 UTC (rev 13469)
+++
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPPortletURL.java 2009-06-17
21:29:16 UTC (rev 13470)
@@ -65,9 +65,11 @@
private WindowState windowState;
/** Are we using strict rewriting parameters validation mode? */
- private static boolean strict = true;
+ protected static boolean strict = true;
/** Holds extra parameters if we are in relaxed validation mode */
private Map<String, String> extraParams;
+ /** Holds extra data after URL in relaxed mode */
+ protected String extra;
/** Remember position of extra parameters wrt end token */
private boolean extraParamsAfterEndToken = false;
@@ -115,6 +117,7 @@
{
WSRPPortletURL other = (WSRPPortletURL)portletURL;
url.setParams(other.extraParams, other.toString());
+ url.setExtra(other.extra);
}
return url;
@@ -131,6 +134,7 @@
String originalURL = encodedURL;
boolean extraAfterEnd = false;
+ String extra = null;
// URL needs to start wsrp_rewrite? and end with /wsrp_rewrite in strict validation
mode
if (!encodedURL.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE))
@@ -139,25 +143,44 @@
}
if (!encodedURL.endsWith(WSRPRewritingConstants.END_WSRP_REWRITE))
{
- if (strict)
+ // first remove prefix only (as suffix is not at the end of the string)
+ encodedURL =
encodedURL.substring(WSRPRewritingConstants.WSRP_REWRITE_PREFIX_LENGTH);
+
+ // end token should be marked by the first / in the URL and extract it
+ int endTokenIndex = encodedURL.indexOf('/');
+ if (endTokenIndex < 0)
{
- throw new IllegalArgumentException(encodedURL + " does not end with
" + WSRPRewritingConstants.END_WSRP_REWRITE);
+ throw new IllegalArgumentException(originalURL + " does not contain
" + WSRPRewritingConstants.END_WSRP_REWRITE);
}
+
+ encodedURL = encodedURL.substring(0, endTokenIndex)
+ + encodedURL.substring(endTokenIndex +
WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
+
+ /*
+ we need to deal with the case when a WSRP URL is concatenated to a context path
using something similar to:
+ renderResponse.encodeURL(renderRequest.getContextPath()) in which case, there
should be a slash still present.
+ How to process further depends on whether we're in strict mode or not...
+ */
+ int concatenationIndex = encodedURL.indexOf('/');
+
+ if (strict && concatenationIndex != endTokenIndex)
+ {
+ // in strict mode, the only character available after the end token is the
concatenating slash
+ throw new IllegalArgumentException(encodedURL + " does not end with
"
+ + WSRPRewritingConstants.END_WSRP_REWRITE + " or does not appear to
be a valid concatenation of URLs.");
+ }
else
{
- // first remove prefix only (as suffix is not at the end of the string)
- encodedURL =
encodedURL.substring(WSRPRewritingConstants.WSRP_REWRITE_PREFIX_LENGTH);
-
- // find end token and extract it
- int endTokenIndex = encodedURL.indexOf('/');
- if (endTokenIndex < 0)
+ // deal with extra characters: this should only happen when the URL is
concatenated to form a longer one
+ // hence, it should be possible to have param-value pairs followed by a slash
'/' then characters.
+ // Anything after the slash will be kept as is, uninterpreted.
+ if (concatenationIndex != -1)
{
- throw new IllegalArgumentException(originalURL + " does not contain
" + WSRPRewritingConstants.END_WSRP_REWRITE);
+ String tmp = encodedURL;
+ encodedURL = encodedURL.substring(0, concatenationIndex);
+ extra = tmp.substring(concatenationIndex);
}
- encodedURL = encodedURL.substring(0, endTokenIndex)
- + encodedURL.substring(endTokenIndex +
WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
-
// remember that we should position the extra params after the end token
extraAfterEnd = true;
}
@@ -228,6 +251,7 @@
url.setParams(params, originalURL);
url.setExtraParamsAfterEndToken(extraAfterEnd);
+ url.setExtra(extra);
return url;
}
@@ -378,16 +402,17 @@
if (extraParams != null && !extraParams.isEmpty())
{
StringBuffer extras = new StringBuffer();
- for (Map.Entry<String, String> entry : extraParams.entrySet())
- {
- createURLParameter(extras, entry.getKey(), entry.getValue());
- }
+ appendExtraParams(extras);
// if we had extra params, we need to figure out where thwy should be
positioned wrt end token
if (extraParamsAfterEndToken)
{
sb.append(WSRPRewritingConstants.END_WSRP_REWRITE);
sb.append(extras);
+ if (extra != null)
+ {
+ sb.append(extra);
+ }
}
else
{
@@ -403,6 +428,17 @@
return sb.toString();
}
+ protected void appendExtraParams(StringBuffer buffer)
+ {
+ if (extraParams != null)
+ {
+ for (Map.Entry<String, String> entry : extraParams.entrySet())
+ {
+ createURLParameter(buffer, entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
protected abstract void appendEnd(StringBuffer sb);
protected final void createURLParameter(StringBuffer sb, String name, String value)
@@ -522,4 +558,9 @@
{
this.extraParamsAfterEndToken = extraParamsAfterEndToken;
}
+
+ public void setExtra(String extra)
+ {
+ this.extra = extra;
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPResourceURL.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPResourceURL.java 2009-06-17
21:24:28 UTC (rev 13469)
+++
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPResourceURL.java 2009-06-17
21:29:16 UTC (rev 13470)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, 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. *
@@ -104,11 +104,12 @@
if (paramValue != null)
{
requiresRewrite = Boolean.valueOf(paramValue);
+ params.remove(WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE);
}
else
{
throw new IllegalArgumentException("The parsed parameters don't contain
a value for the required "
- + WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE + " parameter in
" + originalURL);
+ + WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE + " parameter in
" + originalURL);
}
paramValue = getRawParameterValueFor(params, WSRPRewritingConstants.RESOURCE_URL);
@@ -135,10 +136,11 @@
catch (MimeTypeParseException e)
{
log.debug("Couldn't determine (based on extension) MIME type of
file: " + file
- + "\nRetrieving the associated resource will probably
fail.");
+ + "\nRetrieving the associated resource will probably
fail.");
}
isSupported(mediaType);
+ params.remove(WSRPRewritingConstants.RESOURCE_URL);
}
catch (MalformedURLException e)
{
@@ -148,7 +150,7 @@
else
{
throw new IllegalArgumentException("The parsed parameters don't contain
a value for the required "
- + WSRPRewritingConstants.RESOURCE_URL + " parameter in " +
originalURL);
+ + WSRPRewritingConstants.RESOURCE_URL + " parameter in " +
originalURL);
}
}
@@ -161,7 +163,7 @@
if (!type.isAllowedSubType(mediaType))
{
log.debug("MIME type '" + mediaType
- + "' is not currently supported. Retrieving the
associated resource will probably fail.");
+ + "' is not currently supported. Retrieving the associated
resource will probably fail.");
return;
}
}
@@ -171,6 +173,16 @@
public String toString()
{
- return resourceURL.toExternalForm();
+ StringBuffer result = new StringBuffer(resourceURL.toExternalForm());
+
+ appendExtraParams(result);
+
+ // append extra characters if we have some
+ if (extra != null)
+ {
+ result.append(extra);
+ }
+
+ return result.toString();
}
}