Author: chris.laprun(a)jboss.com
Date: 2008-07-10 07:27:02 -0400 (Thu, 10 Jul 2008)
New Revision: 11401
Added:
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/AbsoluteURLReplacementGenerator.java
Modified:
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java
branches/JBoss_Portal_Branch_2_7/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_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java 2008-07-10
11:26:34 UTC (rev 11400)
+++
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/EndpointConfigurationInfo.java 2008-07-10
11:27:02 UTC (rev 11401)
@@ -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_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java 2008-07-10
11:26:34 UTC (rev 11400)
+++
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/RenderHandler.java 2008-07-10
11:27:02 UTC (rev 11401)
@@ -86,7 +86,7 @@
// process the response
consumer.getSessionHandler().updateSessionIfNeeded(markupResponse.getSessionContext(),
invocation,
- requestPrecursor.getPortletHandle());
+ requestPrecursor.getPortletHandle());
MarkupContext markupContext = markupResponse.getMarkupContext();
String markup = markupContext.getMarkupString();
@@ -94,19 +94,19 @@
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)
{
- if (markupContext.getUseCachedMarkup().booleanValue())
+ if (markupContext.getUseCachedMarkup())
{
//todo: deal with cache
}
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."));
}
}
@@ -129,7 +129,7 @@
org.jboss.portal.portlet.cache.CacheControl cacheControl =
createCacheControl(markupContext);
FragmentResponse result = new FragmentResponse(null, null, mimeType, null, markup,
- markupContext.getPreferredTitle(), cacheControl,
invocation.getPortalContext().getModes());
+ markupContext.getPreferredTitle(), cacheControl,
invocation.getPortalContext().getModes());
log.debug("Response processed");
return result;
@@ -177,7 +177,7 @@
if (rewriteURLs)
{
URLFormat format = new URLFormat(invocation.getSecurityContext().isSecure(),
- invocation.getSecurityContext().isAuthenticated(), true, true);
+ invocation.getSecurityContext().isAuthenticated(), true, true);
WSRPURLRewriter rewriter = new WSRPURLRewriter(invocation.getContext(), format,
consumer);
markup = URLTools.replaceURLsBy(markup, rewriter);
}
@@ -228,6 +228,7 @@
private PortletInvocationContext context;
private URLFormat format;
private WSRPConsumer consumer;
+ private static final String SLASH = "/";
private WSRPURLRewriter(PortletInvocationContext context, URLFormat format,
WSRPConsumer consumer)
{
@@ -239,17 +240,24 @@
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());
+ WSRPPortletURL portletURL = WSRPPortletURL.create(urlAsString,
+ 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();
}
+ // 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 context.renderURL(portletURL, format);
}
return urlAsString;
@@ -267,7 +275,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_7/wsrp/src/main/org/jboss/portal/wsrp/producer/AbsoluteURLReplacementGenerator.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/AbsoluteURLReplacementGenerator.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/AbsoluteURLReplacementGenerator.java 2008-07-10
11:27:02 UTC (rev 11401)
@@ -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_7/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java 2008-07-10
11:26:34 UTC (rev 11400)
+++
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java 2008-07-10
11:27:02 UTC (rev 11401)
@@ -23,6 +23,7 @@
package org.jboss.portal.wsrp.producer;
+import org.jboss.portal.common.net.URLTools;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
import org.jboss.portal.portlet.invocation.PortletInvocation;
@@ -60,8 +61,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;
@@ -166,10 +167,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_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPPortletInvocationContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPPortletInvocationContext.java 2008-07-10
11:26:34 UTC (rev 11400)
+++
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPPortletInvocationContext.java 2008-07-10
11:27:02 UTC (rev 11401)
@@ -22,8 +22,6 @@
******************************************************************************/
package org.jboss.portal.wsrp.producer;
-import org.jboss.portal.common.invocation.resolver.MapAttributeResolver;
-import org.jboss.portal.common.invocation.resolver.RequestAttributeResolver;
import org.jboss.portal.common.net.URLTools;
import org.jboss.portal.common.util.MarkupInfo;
import org.jboss.portal.portlet.ContainerURL;
@@ -63,8 +61,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";
@@ -108,28 +104,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();
}
}