Author: chris.laprun(a)jboss.com
Date: 2007-03-09 00:25:08 -0500 (Fri, 09 Mar 2007)
New Revision: 6614
Modified:
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/wsrp/invocation/WSRPInvocationContext.java
Log:
- JBPORTAL-1298: Resource URLs now use an absolute URL and properly adds the WSRP rewrite
tokens.
Modified:
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/wsrp/invocation/WSRPInvocationContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/wsrp/invocation/WSRPInvocationContext.java 2007-03-09
05:24:06 UTC (rev 6613)
+++
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/wsrp/invocation/WSRPInvocationContext.java 2007-03-09
05:25:08 UTC (rev 6614)
@@ -24,6 +24,7 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.common.util.URLTools;
import org.jboss.portal.portlet.PortletURL;
import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.impl.spi.AbstractInvocationContext;
@@ -62,6 +63,12 @@
private Mode mode;
private WindowContext windowContext;
+ private static final String SCH_END = "://";
+ private static final String PORT_END = ":";
+ private static final String EQ = "=";
+ private static final String AMP = "&";
+ private static final String EQ_TRUE = "=true";
+
public WSRPInvocationContext(StateString navigationalState, SecurityContext
securityContext,
HTTPStreamInfo streamInfo, PortalContext portalContext,
UserContext userContext,
InstanceContext instanceContext, WindowContext
windowContext, Mode mode, WindowState windowState)
@@ -111,15 +118,42 @@
/** Override the default behavior in order to avoid to encode when it is producer
written URL. */
public String encodeURL(String url)
{
- if (url != null &&
url.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE))
+ if (url != null)
{
- // We don't encode URL through this API when it is a wsrp URL
- return url;
+ if (url.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE))
+ {
+ // We don't encode URL through this API when it is a wsrp URL
+ return url;
+ }
+ else
+ {
+ StringBuffer sb;
+ if (!URLTools.isNetworkURL(url))
+ {
+ // URL is not an absolute URL so we need to build one
+ HttpServletRequest req = getClientRequest();
+ String scheme = req.getScheme();
+ String host = req.getServerName();
+ int port = req.getServerPort();
+ sb = new StringBuffer(url.length() * 2);
+
sb.append(scheme).append(SCH_END).append(host).append(PORT_END).append(port).append(url);
+ url = sb.toString();
+ }
+
+ url = URLTools.encodeXWWWFormURL(url);
+
+ // build the WSRP resource URL with rewrite tokens
+ sb = new StringBuffer(url.length() * 2);
+
sb.append(WSRPRewritingConstants.BEGIN_WSRP_REWRITE).append(WSRPRewritingConstants.URL_TYPE_NAME)
+ .append(EQ).append(WSRPRewritingConstants.URL_TYPE_RESOURCE).append(AMP)
+ .append(WSRPRewritingConstants.RESOURCE_URL).append(EQ).append(url)
+ .append(AMP).append(WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE)
+ .append(EQ_TRUE).append(WSRPRewritingConstants.END_WSRP_REWRITE);
+ return sb.toString();
+ }
}
- else
- {
- return super.encodeURL(url);
- }
+
+ return null;
}
/**
Show replies by date