Author: chris.laprun(a)jboss.com
Date: 2010-03-09 21:52:38 -0500 (Tue, 09 Mar 2010)
New Revision: 2068
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java
Log:
- Rewrote markup processing in RenderHandler so that we can generate URLs that will
trigger a ResourceInvocation that can be
intercepted by the consumer and proxied (initial work for GTNWSRP-7 &
JBPORTAL-2471).
- Improved WSRPResourceURL:
+ Encode resourceURL so that it can safely be sent over the wire when a WSRPResourceURL
is output.
+ Always output a value for wsrp-requiresRewrite.
+ Added support for resourceId.
+ Fixed resource test in WSRPPortletURLTestCase. Need to add more.
- Updated for move of String manipulation methods to TextTools.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java 2010-03-10
02:47:11 UTC (rev 2067)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java 2010-03-10
02:52:38 UTC (rev 2068)
@@ -24,7 +24,7 @@
package org.gatein.wsrp;
import org.gatein.common.text.FastURLDecoder;
-import org.gatein.common.util.Tools;
+import org.gatein.common.text.TextTools;
import org.gatein.pc.api.ActionURL;
import org.gatein.pc.api.ContainerURL;
import org.gatein.pc.api.Mode;
@@ -126,7 +126,10 @@
public static WSRPPortletURL create(String encodedURL, Set<String> customModes,
Set<String> customWindowStates)
{
- log.debug("Trying to build a WSRPPortletURL from <" + encodedURL +
">");
+ if (log.isDebugEnabled())
+ {
+ log.debug("Trying to build a WSRPPortletURL from <" + encodedURL +
">");
+ }
if (encodedURL == null || encodedURL.length() == 0)
{
@@ -204,8 +207,8 @@
{
throw new IllegalArgumentException(encodedURL + " contains a doubly encoded
&!");
}
- encodedURL = Tools.replace(encodedURL, ENCODED_AMPERSAND, PARAM_SEPARATOR);
- encodedURL = Tools.replace(encodedURL, AMPERSAND, PARAM_SEPARATOR);
+ encodedURL = TextTools.replace(encodedURL, ENCODED_AMPERSAND, PARAM_SEPARATOR);
+ encodedURL = TextTools.replace(encodedURL, AMPERSAND, PARAM_SEPARATOR);
// remove url type param name and extract value
encodedURL = encodedURL.substring(URL_TYPE_END);
@@ -223,7 +226,10 @@
}
else if (encodedURL.startsWith(WSRPRewritingConstants.URL_TYPE_RESOURCE))
{
- log.debug("Using experimental resource URL support...");
+ if (log.isDebugEnabled())
+ {
+ log.debug("Using experimental resource URL support...");
+ }
urlType = WSRPRewritingConstants.URL_TYPE_RESOURCE;
url = new WSRPResourceURL();
}
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java 2010-03-10
02:47:11 UTC (rev 2067)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java 2010-03-10
02:52:38 UTC (rev 2068)
@@ -92,13 +92,10 @@
{
if (resourceURL != null)
{
- createURLParameter(sb, WSRPRewritingConstants.RESOURCE_URL,
resourceURL.toExternalForm());
+ createURLParameter(sb, WSRPRewritingConstants.RESOURCE_URL,
URLTools.encodeXWWWFormURL(resourceURL.toExternalForm()));
}
- if (requiresRewrite)
- {
- createURLParameter(sb, WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE,
"true");
- }
+ createURLParameter(sb, WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE,
requiresRewrite ? "true" : "false");
}
@Override
@@ -123,9 +120,13 @@
{
try
{
+ // todo: deal with resourceId properly, right now just use resourceURL if
any
+ resourceId = paramValue; // keep the encoded value as it will be used in
URLs
+
paramValue = URLTools.decodeXWWWFormURL(paramValue);
resourceURL = new URL(paramValue);
+
String extension = URLTools.getFileExtensionOrNullFrom(resourceURL);
MediaType mediaType = SUPPORTED_RESOURCE_TYPES.get(extension);
@@ -149,11 +150,38 @@
}
}
+ /**
+ * @return
+ * @deprecated
+ */
+ public URL getResourceURL()
+ {
+ return resourceURL;
+ }
+
+ /**
+ * @param resourceURL
+ * @deprecated
+ */
+ public void setResourceURL(URL resourceURL)
+ {
+ this.resourceURL = resourceURL;
+ }
+
public String getResourceId()
{
return resourceId;
}
+ /**
+ * @param resourceId
+ * @deprecated
+ */
+ public void setResourceId(String resourceId)
+ {
+ this.resourceId = resourceId;
+ }
+
public StateString getResourceState()
{
return resourceState;
@@ -196,5 +224,16 @@
{
throw new IllegalArgumentException("Malformed URL: " + url, e);
}
+
+ log.info("Attempted to build resource URL that could be accessed directly from
consumer: " + resourceURL);
}
+
+ /**
+ * @return
+ * @deprecated
+ */
+ public boolean requiresRewrite()
+ {
+ return requiresRewrite;
+ }
}
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-03-10
02:47:11 UTC (rev 2067)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-03-10
02:52:38 UTC (rev 2068)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2010, 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.
@@ -23,8 +23,8 @@
package org.gatein.wsrp;
+import org.gatein.common.text.TextTools;
import org.gatein.common.util.ParameterValidation;
-import org.gatein.common.util.Tools;
import org.gatein.pc.api.ActionURL;
import org.gatein.pc.api.Mode;
import org.gatein.pc.api.OpaqueStateString;
@@ -716,8 +716,8 @@
private static String createTemplate(PortletInvocationContext context, PortletURL url,
Boolean secure)
{
String template = context.renderURL(url, new URLFormat(secure, null, null, true));
- template = Tools.replace(template, WSRPRewritingConstants.ENC_OPEN,
WSRPRewritingConstants.REWRITE_PARAMETER_OPEN);
- template = Tools.replace(template, WSRPRewritingConstants.ENC_CLOSE,
WSRPRewritingConstants.REWRITE_PARAMETER_CLOSE);
+ template = TextTools.replace(template, WSRPRewritingConstants.ENC_OPEN,
WSRPRewritingConstants.REWRITE_PARAMETER_OPEN);
+ template = TextTools.replace(template, WSRPRewritingConstants.ENC_CLOSE,
WSRPRewritingConstants.REWRITE_PARAMETER_CLOSE);
return template;
}
Modified:
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java
===================================================================
---
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java 2010-03-10
02:47:11 UTC (rev 2067)
+++
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java 2010-03-10
02:52:38 UTC (rev 2068)
@@ -29,6 +29,7 @@
import org.gatein.wsrp.WSRPActionURL;
import org.gatein.wsrp.WSRPPortletURL;
import org.gatein.wsrp.WSRPRenderURL;
+import org.gatein.wsrp.WSRPResourceURL;
import org.gatein.wsrp.WSRPRewritingConstants;
import java.util.HashSet;
@@ -51,10 +52,13 @@
public void testResource()
{
String expected =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif"
+
- "&wsrp-requiresRewrite=true/wsrp_rewrite";
+ "&wsrp-requiresRewrite=false/wsrp_rewrite";
WSRPPortletURL url = WSRPPortletURL.create(expected);
-
assertEquals("wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http:/...;,
url.toString());
+ assertTrue(url instanceof WSRPResourceURL);
+ WSRPResourceURL resource = (WSRPResourceURL)url;
+ assertFalse(resource.requiresRewrite());
+
assertEquals("http://test.com/images/test.gif",
resource.getResourceURL().toExternalForm());
}
/** Declare a secure interaction back to the Portlet */
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java 2010-03-10
02:47:11 UTC (rev 2067)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java 2010-03-10
02:52:38 UTC (rev 2068)
@@ -24,7 +24,8 @@
package org.gatein.wsrp.consumer;
import org.gatein.common.net.URLTools;
-import org.gatein.common.util.Tools;
+import org.gatein.common.text.TextTools;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.api.PortletInvokerException;
import org.gatein.pc.api.URLFormat;
import org.gatein.pc.api.cache.CacheScope;
@@ -51,6 +52,8 @@
import org.oasis.wsrp.v1.UserContext;
import javax.xml.ws.Holder;
+import java.net.URI;
+import java.net.URL;
import java.util.List;
/**
@@ -61,11 +64,7 @@
public class RenderHandler extends InvocationHandler
{
- /** The separator constant. */
- private static final String SEPARATOR = "_";
-
private static final org.gatein.pc.api.cache.CacheControl DEFAULT_CACHE_CONTROL = new
org.gatein.pc.api.cache.CacheControl(0, CacheScope.PRIVATE, null);
- private static final ResourceURLRewriter RESOURCE_REWRITER = new
ResourceURLRewriter();
public RenderHandler(WSRPConsumerImpl consumer)
{
@@ -183,23 +182,25 @@
throw new IllegalArgumentException("RenderHandler: Request is not a GetMarkup
request!");
}
- private String processMarkup(String markup, PortletInvocation invocation, boolean
rewriteURLs)
+ private String processMarkup(String markup, PortletInvocation invocation, boolean
needsRewriting)
{
- // fix-me: how to deal with fragment header? => interceptor?
- String prefix = getNamespaceFrom(invocation.getWindowContext());
- markup = Tools.replace(markup, WSRPRewritingConstants.WSRP_REWRITE_TOKEN, prefix);
-
- if (rewriteURLs)
+ if (needsRewriting)
{
+ // fix-me: how to deal with fragment header? => interceptor?
+ String prefix = getNamespaceFrom(invocation.getWindowContext());
+ markup = TextTools.replace(markup, WSRPRewritingConstants.WSRP_REWRITE_TOKEN,
prefix);
URLFormat format = new URLFormat(invocation.getSecurityContext().isSecure(),
invocation.getSecurityContext().isAuthenticated(), true, true);
- WSRPURLRewriter rewriter = new WSRPURLRewriter(invocation.getContext(), format,
consumer);
- markup = URLTools.replaceURLsBy(markup, rewriter);
+
+ /*WSRPURLRewriter rewriter = new WSRPURLRewriter(invocation.getContext(),
format, consumer);
+ markup = URLTools.replaceURLsBy(markup, rewriter);*/
+
+ markup = TextTools.replaceBoundedString(markup,
WSRPRewritingConstants.BEGIN_WSRP_REWRITE,
+ WSRPRewritingConstants.END_WSRP_REWRITE, new
ResourceURLStringReplacementGenerator(invocation.getContext(), format, consumer), true,
false);
}
- // means that the producer generated the URLs, so handle resources...
- return URLTools.replaceURLsBy(markup, RESOURCE_REWRITER);
+ return markup;
}
private org.gatein.pc.api.cache.CacheControl createCacheControl(MarkupContext
markupContext)
@@ -238,69 +239,70 @@
return result;
}
- private static class WSRPURLRewriter extends URLTools.URLReplacementGenerator
+ static class ResourceURLStringReplacementGenerator implements
TextTools.StringReplacementGenerator
{
private PortletInvocationContext context;
private URLFormat format;
private WSRPConsumer consumer;
- private static final String SLASH = "/";
- private WSRPURLRewriter(PortletInvocationContext context, URLFormat format,
WSRPConsumer consumer)
+ private ResourceURLStringReplacementGenerator(PortletInvocationContext context,
URLFormat format, WSRPConsumer consumer)
{
this.context = context;
this.format = format;
this.consumer = consumer;
}
- public String getReplacementFor(int currentIndex, URLTools.URLMatch currentMatch)
+ public String getReplacementFor(String match)
{
- String urlAsString = currentMatch.getURLAsString();
ProducerInfo info = consumer.getProducerInfo();
- if (urlAsString.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE))
+ WSRPPortletURL portletURL = WSRPPortletURL.create(match,
info.getSupportedCustomModes(), info.getSupportedCustomWindowStates());
+ if (portletURL instanceof WSRPResourceURL)
{
- WSRPPortletURL portletURL = WSRPPortletURL.create(urlAsString,
- info.getSupportedCustomModes(), info.getSupportedCustomWindowStates());
- if (portletURL instanceof WSRPResourceURL)
+ if (log.isDebugEnabled())
{
- log.debug("URL '" + urlAsString + "' seems to refer
to a resource which are not currently supported. " +
- "Trying to use the raw URL but this probably won't
work...");
- return portletURL.toString();
+ log.debug("URL '" + match + "' seems to refer to a
resource which are not currently well supported.");
}
- // todo: this is a hack to circumvent frameworks that don't properly
request resource encoding (icefaces)
- if (urlAsString.startsWith(SLASH))
+ WSRPResourceURL resource = (WSRPResourceURL)portletURL;
+
+ // get the parsed URL and add gtnresource to it so that the consumer can know
it needs to be intercepted
+ URL url = resource.getResourceURL();
+ try
{
- return info.getEndpointConfigurationInfo().getRemoteHostAddress() +
urlAsString;
+ String query = url.getQuery();
+ if (ParameterValidation.isNullOrEmpty(query))
+ {
+ query = "gtnresource";
+ }
+ else
+ {
+ query = "+gtnresource";
+ }
+ URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
url.getPort(),
+ url.getPath(), query, url.getRef());
+
+ // set the resulting URI as the new resource ID, must be encoded as it
will be used in URLs
+ String s = URLTools.safeEncodeForHTMLId(uri.toString());
+ s = s.replace('-', '_');
+ resource.setResourceId(s);
}
+ catch (Exception e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File |
Settings | File Templates.
+ }
- return context.renderURL(portletURL, format);
- }
- return urlAsString;
- }
- }
- static class ResourceURLRewriter extends URLTools.URLReplacementGenerator
- {
- public String getReplacementFor(int currentIndex, URLTools.URLMatch currentMatch)
- {
- String urlAsString = currentMatch.getURLAsString();
- String prefix = WSRPRewritingConstants.FAKE_RESOURCE_START;
- if (urlAsString.startsWith(prefix))
- {
- int index =
urlAsString.indexOf(WSRPRewritingConstants.FAKE_RESOURCE_REQ_REW);
- String requireRewriteStr = urlAsString.substring(index +
WSRPRewritingConstants.FAKE_RESOURCE_REQ_REW.length());
- boolean requireRewrite = Boolean.valueOf(requireRewriteStr);
-
- urlAsString = urlAsString.substring(prefix.length(), index);
- if (requireRewrite)
+ /*// todo: this is a hack to circumvent frameworks that don't properly
request resource encoding (icefaces)
+ if (resource.getResourceURL().toExternalForm().startsWith(SLASH))
{
- // FIX-ME: do something
- log.debug("Required re-writing but this is not yet
implemented...");
- }
- return URLTools.decodeXWWWFormURL(urlAsString);
+ return info.getEndpointConfigurationInfo().getRemoteHostAddress() +
match;
+ }*/
}
- return urlAsString;
+
+ return context.renderURL(portletURL, format);
}
}
+
+
}