Author: chris.laprun(a)jboss.com
Date: 2008-07-10 07:26:34 -0400 (Thu, 10 Jul 2008)
New Revision: 11400
Added:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/AbsoluteURLReplacementGenerator.java
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPPortletInvocationContext.java
Log:
- JBPORTAL-2067: Added more rewriting of URLs on both Consumer and Producer.
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java 2008-07-10
10:03:46 UTC (rev 11399)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java 2008-07-10
11:26:34 UTC (rev 11400)
@@ -57,6 +57,7 @@
// transient variables
/** Access to the WS */
private ServiceFactory serviceFactory;
+ private transient String remoteHostAddress;
static final String SERVICE_DESCRIPTION = "service description";
static final String MARKUP = "markup";
@@ -394,7 +395,7 @@
catch (Exception e)
{
throw new InvokerUnavailableException("Couldn't access " +
description + " service. Cause: "
- + e.getLocalizedMessage(), e);
+ + e.getLocalizedMessage(), e);
}
}
@@ -440,7 +441,7 @@
private boolean areURLsDirty()
{
return !clean.get(SD) || !clean.get(M) || (persistentPortletManagementURL != null
&& !clean.get(PM))
- || (persistentRegistrationURL != null && !clean.get(R));
+ || (persistentRegistrationURL != null && !clean.get(R));
}
public void refresh() throws InvokerUnavailableException
@@ -468,4 +469,16 @@
}
}
}
+
+ public String getRemoteHostAddress()
+ {
+ if (remoteHostAddress == null || areURLsDirty())
+ {
+ // extract host URL
+ int hostBegin = persistentMarkupURL.indexOf("://") + 3;
+ remoteHostAddress = persistentMarkupURL.substring(0,
persistentMarkupURL.indexOf('/', hostBegin));
+ }
+
+ return remoteHostAddress;
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java 2008-07-10
10:03:46 UTC (rev 11399)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java 2008-07-10
11:26:34 UTC (rev 11400)
@@ -95,7 +95,7 @@
// process the response
consumer.getSessionHandler().updateSessionIfNeeded(markupResponse.getSessionContext(),
invocation,
- requestPrecursor.getPortletHandle());
+ requestPrecursor.getPortletHandle());
MarkupContext markupContext = markupResponse.getMarkupContext();
String markup = markupContext.getMarkupString();
@@ -103,7 +103,7 @@
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 specification, this is a
Producer error."));
}
if (markup == null && binary == null)
@@ -115,7 +115,7 @@
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 specification, this is
a Producer error."));
}
}
@@ -228,6 +228,7 @@
private Boolean secure;
private Boolean authenticated;
private WSRPConsumer consumer;
+ private static final String SLASH = "/";
public void setContext(PortletInvocationContext context)
{
@@ -236,12 +237,12 @@
public void setSecure(boolean secure)
{
- this.secure = Boolean.valueOf(secure);
+ this.secure = secure;
}
public void setAuthenticated(boolean authenticated)
{
- this.authenticated = Boolean.valueOf(authenticated);
+ this.authenticated = authenticated;
}
public void setConsumer(WSRPConsumer consumer)
@@ -252,19 +253,28 @@
public String getReplacementFor(int currentIndex, URLTools.URLMatch currentMatch)
{
String urlAsString = currentMatch.getURLAsString();
+ ProducerInfo info = consumer.getProducerInfo();
+
if (urlAsString.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE))
{
WSRPPortletURL portletURL = WSRPPortletURL.create(urlAsString,
- consumer.getProducerInfo().getSupportedCustomModes(),
consumer.getProducerInfo().getSupportedCustomWindowStates());
+ info.getSupportedCustomModes(),
info.getSupportedCustomWindowStates());
if (portletURL instanceof WSRPResourceURL)
{
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...");
+ "Trying to use the raw URL but this probably won't
work...");
return portletURL.toString();
}
return context.renderURL(portletURL, secure, authenticated, true);
}
+
+ // todo: this is a hack to circumvent frameworks that don't properly request
resource encoding (icefaces)
+ if (urlAsString.startsWith(SLASH))
+ {
+ return info.getEndpointConfigurationInfo().getRemoteHostAddress() +
urlAsString;
+ }
+
return urlAsString;
}
}
@@ -280,7 +290,7 @@
{
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).booleanValue();
+ boolean requireRewrite = Boolean.valueOf(requireRewriteStr);
urlAsString = urlAsString.substring(prefix.length(), index);
if (requireRewrite)
Added:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/AbsoluteURLReplacementGenerator.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/AbsoluteURLReplacementGenerator.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/AbsoluteURLReplacementGenerator.java 2008-07-10
11:26:34 UTC (rev 11400)
@@ -0,0 +1,62 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.portal.wsrp.producer;
+
+import org.jboss.portal.common.net.URLTools;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class AbsoluteURLReplacementGenerator extends URLTools.URLReplacementGenerator
+{
+ private String serverAddress;
+ static final String SCH_END = "://";
+ static final String PORT_END = ":";
+
+ public AbsoluteURLReplacementGenerator(HttpServletRequest request)
+ {
+ String scheme = request.getScheme();
+ String host = request.getServerName();
+ int port = request.getServerPort();
+
+ serverAddress = scheme + SCH_END + host + PORT_END + port;
+ }
+
+ public String getReplacementFor(int i, URLTools.URLMatch urlMatch)
+ {
+ return getAbsoluteURLFor(urlMatch.getURLAsString());
+ }
+
+ public String getAbsoluteURLFor(String url)
+ {
+ if (!URLTools.isNetworkURL(url))
+ {
+ return serverAddress + url;
+ }
+
+ return url;
+ }
+}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java 2008-07-10
10:03:46 UTC (rev 11399)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java 2008-07-10
11:26:34 UTC (rev 11400)
@@ -23,6 +23,7 @@
package org.jboss.portal.wsrp.producer;
+import org.jboss.portal.common.net.URLTools;
import org.jboss.portal.common.util.MarkupInfo;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.portlet.StateString;
@@ -65,8 +66,8 @@
private final GetMarkup getMarkup;
public RenderRequestProcessor(WSRPProducerImpl producer, GetMarkup getMarkup) throws
UnsupportedMimeTypeFault,
- UnsupportedWindowStateFault, InvalidHandleFault, UnsupportedModeFault,
MissingParametersFault,
- InvalidRegistrationFault, OperationFailedFault
+ UnsupportedWindowStateFault, InvalidHandleFault, UnsupportedModeFault,
MissingParametersFault,
+ InvalidRegistrationFault, OperationFailedFault
{
super(producer);
this.getMarkup = getMarkup;
@@ -115,9 +116,9 @@
)
{
WSRPRenderContext renderContext = new WSRPRenderContext(navigationalState,
securityContext, markupInfo,
- portalContext, userContext, instanceContext, windowContext,
- WSRPUtils.getJSR168PortletModeFromWSRPName(markupRequest.getMode()),
- WSRPUtils.getJSR168WindowStateFromWSRPName(markupRequest.getWindowState()));
+ portalContext, userContext, instanceContext, windowContext,
+ WSRPUtils.getJSR168PortletModeFromWSRPName(markupRequest.getMode()),
+
WSRPUtils.getJSR168WindowStateFromWSRPName(markupRequest.getWindowState()));
setInvocation(new RenderInvocation(renderContext));
renderContext.contextualize(invocation);
@@ -182,10 +183,13 @@
*/
private String processFragmentString(String renderString)
{
- return Tools.replaceAllInstancesOfBoundedString(
- renderString,
- PortletUtils.PREFIX,
- PortletUtils.SUFFIX,
- WSRPRewritingConstants.WSRP_REWRITE_TOKEN);
+ String result = Tools.replaceAllInstancesOfBoundedString(
+ renderString,
+ PortletUtils.PREFIX,
+ PortletUtils.SUFFIX,
+ WSRPRewritingConstants.WSRP_REWRITE_TOKEN);
+
+ result = URLTools.replaceURLsBy(result, new
AbsoluteURLReplacementGenerator(invocation.getDispatchedRequest()));
+ return result;
}
}
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPPortletInvocationContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPPortletInvocationContext.java 2008-07-10
10:03:46 UTC (rev 11399)
+++
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPPortletInvocationContext.java 2008-07-10
11:26:34 UTC (rev 11400)
@@ -62,8 +62,6 @@
private InstanceContext instanceContext;
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";
@@ -111,28 +109,19 @@
}
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();
- }
+ // make root relative URLs absolute
+ url = new
AbsoluteURLReplacementGenerator(getClientRequest()).getAbsoluteURLFor(url);
+ // properly encode the URL
url = URLTools.encodeXWWWFormURL(url);
// build the WSRP resource URL with rewrite tokens
- sb = new StringBuffer(url.length() * 2);
+ StringBuffer 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);
+
.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();
}
}