Author: chris.laprun(a)jboss.com
Date: 2010-03-19 12:26:02 -0400 (Fri, 19 Mar 2010)
New Revision: 2317
Added:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockEndpointConfigurationInfo.java
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ActionHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/InvocationHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/RenderHandlerTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/BehaviorBackedServiceFactory.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/TestPortletInvocationContext.java
Log:
- GTNWSRP-11: initial work
+ Re-added ResourceURLRewriter with a slightly improved implementation.
+ Re-worked RenderHandler.processMarkup to make more easily testable.
+ Re-wrote RenderHandlerTestCase to add lots of tests.
- Improved test support classes to help with RenderHandlerTestCase:
+ Added MockEndpoingConfigurationInfo that uses BehaviorBackedServiceFactory to provide
a remote host address.
+ Updated and improved TestPortletInvocationContext, in particular to provide an
implementation of renderURL.
+ Changed BehaviorBackedServiceFactory.DEFAULT_WSDL_URL to be a valid URL (needed when
remote host address is computed).
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ActionHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ActionHandler.java 2010-03-19
16:03:50 UTC (rev 2316)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ActionHandler.java 2010-03-19
16:26:02 UTC (rev 2317)
@@ -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.
@@ -70,7 +70,7 @@
*/
public class ActionHandler extends InvocationHandler
{
- public ActionHandler(WSRPConsumerImpl consumer)
+ protected ActionHandler(WSRPConsumerImpl consumer)
{
super(consumer);
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java 2010-03-19
16:03:50 UTC (rev 2316)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java 2010-03-19
16:26:02 UTC (rev 2317)
@@ -54,7 +54,7 @@
serviceFactory = new SOAPServiceFactory();
}
- EndpointConfigurationInfo(ServiceFactory serviceFactory)
+ protected EndpointConfigurationInfo(ServiceFactory serviceFactory)
{
ParameterValidation.throwIllegalArgExceptionIfNull(serviceFactory,
"ServiceFactory");
this.serviceFactory = serviceFactory;
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/InvocationHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/InvocationHandler.java 2010-03-19
16:03:50 UTC (rev 2316)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/InvocationHandler.java 2010-03-19
16:26:02 UTC (rev 2317)
@@ -62,7 +62,7 @@
private static final int MAXIMUM_RETRY_NUMBER = 3;
- public InvocationHandler(WSRPConsumerImpl consumer)
+ protected InvocationHandler(WSRPConsumerImpl consumer)
{
this.consumer = consumer;
}
@@ -146,7 +146,7 @@
return response;
}
- protected String getNamespaceFrom(WindowContext windowContext)
+ static String getNamespaceFrom(WindowContext windowContext)
{
if (windowContext != null)
{
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-19
16:03:50 UTC (rev 2316)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java 2010-03-19
16:26:02 UTC (rev 2317)
@@ -63,8 +63,9 @@
{
private static final org.gatein.pc.api.cache.CacheControl DEFAULT_CACHE_CONTROL = new
org.gatein.pc.api.cache.CacheControl(0, CacheScope.PRIVATE, null);
+ public static final ResourceURLRewriter GENERATOR = new ResourceURLRewriter();
- public RenderHandler(WSRPConsumerImpl consumer)
+ protected RenderHandler(WSRPConsumerImpl consumer)
{
super(consumer);
}
@@ -115,7 +116,17 @@
if (markup != null && markup.length() > 0)
{
- markup = processMarkup(markup, invocation,
Boolean.TRUE.equals(markupContext.isRequiresUrlRewriting()));
+ if (Boolean.TRUE.equals(markupContext.isRequiresUrlRewriting()))
+ {
+ markup = processMarkup(
+ markup,
+ getNamespaceFrom(invocation.getWindowContext()),
+ invocation.getContext(),
+ invocation.getTarget(),
+ new URLFormat(invocation.getSecurityContext().isSecure(),
invocation.getSecurityContext().isAuthenticated(), true, true),
+ consumer
+ );
+ }
}
else
{
@@ -180,30 +191,37 @@
throw new IllegalArgumentException("RenderHandler: Request is not a GetMarkup
request!");
}
- private String processMarkup(String markup, PortletInvocation invocation, boolean
needsRewriting)
+ static String processMarkup(String markup, String namespace, PortletInvocationContext
context, org.gatein.pc.api.PortletContext target, URLFormat format, WSRPConsumer
consumer)
{
- if (needsRewriting)
- {
- // fix-me: how to deal with fragment header? => interceptor?
+ // fix-me: how to deal with fragment header? => interceptor?
- // Replace rewrite token by namespace
- String prefix = getNamespaceFrom(invocation.getWindowContext());
- markup = TextTools.replace(markup, WSRPRewritingConstants.WSRP_REWRITE_TOKEN,
prefix);
+ // Replace rewrite token by namespace
+ markup = TextTools.replace(markup, WSRPRewritingConstants.WSRP_REWRITE_TOKEN,
namespace + '_');
- URLFormat format = new URLFormat(invocation.getSecurityContext().isSecure(),
- invocation.getSecurityContext().isAuthenticated(), true, true);
+ markup = URLTools.replaceURLsBy(markup, GENERATOR);
- // replace URL marked for rewriting by proper ones
- markup = TextTools.replaceBoundedString(
- markup,
- WSRPRewritingConstants.BEGIN_WSRP_REWRITE,
- WSRPRewritingConstants.END_WSRP_REWRITE,
- new ResourceURLStringReplacementGenerator(invocation.getContext(), format,
consumer, invocation.getTarget()),
- true,
- false
- );
- }
+ // replace URL marked for rewriting by proper ones
+ markup = TextTools.replaceBoundedString(
+ markup,
+ WSRPRewritingConstants.BEGIN_WSRP_REWRITE,
+ WSRPRewritingConstants.END_WSRP_REWRITE,
+ new OldResourceURLStringReplacementGenerator(context, target, format,
consumer.getProducerInfo()),
+ true,
+ false
+ );
+/*
+ markup = TextTools.replaceBoundedString(
+ markup,
+ WSRPRewritingConstants.WSRP_REWRITE,
+ WSRPRewritingConstants.END_WSRP_REWRITE,
+ new ResourceURLStringReplacementGenerator(namespace, context, target, format,
consumer.getProducerInfo()),
+ true,
+ false,
+ true
+ );
+*/
+
return markup;
}
@@ -243,7 +261,7 @@
return result;
}
- static class ResourceURLStringReplacementGenerator implements
TextTools.StringReplacementGenerator
+ static class OldResourceURLStringReplacementGenerator implements
TextTools.StringReplacementGenerator
{
private final PortletInvocationContext context;
private final URLFormat format;
@@ -252,11 +270,10 @@
private final String serverAddress;
private final String portletApplicationName;
- private ResourceURLStringReplacementGenerator(PortletInvocationContext context,
URLFormat format, WSRPConsumer consumer, org.gatein.pc.api.PortletContext target)
+ private OldResourceURLStringReplacementGenerator(PortletInvocationContext context,
org.gatein.pc.api.PortletContext target, URLFormat format, ProducerInfo info)
{
this.context = context;
this.format = format;
- ProducerInfo info = consumer.getProducerInfo();
supportedCustomModes = info.getSupportedCustomModes();
supportedCustomWindowStates = info.getSupportedCustomWindowStates();
serverAddress = info.getEndpointConfigurationInfo().getRemoteHostAddress();
@@ -265,7 +282,6 @@
public String getReplacementFor(String match)
{
-
WSRPPortletURL portletURL = WSRPPortletURL.create(match, supportedCustomModes,
supportedCustomWindowStates);
if (portletURL instanceof WSRPResourceURL)
{
@@ -280,45 +296,159 @@
}
return replacement;
+ }
+ return context.renderURL(portletURL, format);
+ }
+ }
- /*
- todo: use this code to reactivate primitive use of resources
- // get the parsed URL and add marker to it so that the consumer can know it
needs to be intercepted
- URL url = resource.getResourceURL();
- String query = url.getQuery();
- if (ParameterValidation.isNullOrEmpty(query))
+/*
+ static class ResourceURLStringReplacementGenerator implements
TextTools.StringReplacementGenerator
+ {
+ private final PortletInvocationContext context;
+ private final URLFormat format;
+ private final Set<String> supportedCustomModes;
+ private final Set<String> supportedCustomWindowStates;
+ private final String serverAddress;
+ private final String portletApplicationName;
+ private final String namespace;
+ public static final int URL_DELIMITER_LENGTH =
WSRPRewritingConstants.RESOURCE_URL_DELIMITER.length();
+
+ private ResourceURLStringReplacementGenerator(String namespace,
PortletInvocationContext context, org.gatein.pc.api.PortletContext target, URLFormat
format, ProducerInfo info)
+ {
+ this.namespace = namespace;
+ this.context = context;
+ this.format = format;
+ supportedCustomModes = info.getSupportedCustomModes();
+ supportedCustomWindowStates = info.getSupportedCustomWindowStates();
+ serverAddress = info.getEndpointConfigurationInfo().getRemoteHostAddress();
+ portletApplicationName = target.getApplicationName();
+ }
+
+ public String getReplacementFor(String match, String prefix, String suffix)
+ {
+ if (match.startsWith(WSRPRewritingConstants.RESOURCE_URL_DELIMITER))
+ {
+ // we have a resource URL coming from a template so extract URL
+ int index =
match.lastIndexOf(WSRPRewritingConstants.RESOURCE_URL_DELIMITER);
+
+ */
+/*
+ // todo: right now, no need to extract value of require rewrite..
+ String requireRewriteStr = match.substring(index + URL_DELIMITER_LENGTH);
+ boolean requireRewrite = Boolean.valueOf(requireRewriteStr);
+ if (requireRewrite)
{
- query = WSRPRewritingConstants.GTNRESOURCE;
- }
- else
+ // FIX-ME: do something
+ log.debug("Required re-writing but this is not yet
implemented...");
+ }*//*
+
+
+ match = match.substring(URL_DELIMITER_LENGTH, index);
+ return URLTools.decodeXWWWFormURL(match);
+ }
+ else if (prefix.equals(match))
+ {
+ return namespace;
+ }
+ else if (match.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE_END))
+ {
+ // remove end of rewrite token
+ match =
match.substring(WSRPRewritingConstants.BEGIN_WSRP_REWRITE_END.length());
+
+ WSRPPortletURL portletURL = WSRPPortletURL.create(match,
supportedCustomModes, supportedCustomWindowStates, true);
+ if (portletURL instanceof WSRPResourceURL)
{
- query = "+" + WSRPRewritingConstants.GTNRESOURCE;
+ WSRPResourceURL resource = (WSRPResourceURL)portletURL;
+ String replacement = getResourceURL(match, resource);
+
+ // if the URL starts with /, prepend the remote host address and the
portlet application name so that we
+ // can attempt to create a remotely available URL
+ if (replacement.startsWith(URLTools.SLASH))
+ {
+ replacement = WSRPResourceURL.createAbsoluteURLFrom(replacement,
serverAddress, portletApplicationName);
+ }
+
+ return replacement;
+
+ */
+/*
+ todo: use this code to reactivate primitive use of resources
+ // get the parsed URL and add marker to it so that the consumer can know
it needs to be intercepted
+ URL url = resource.getResourceURL();
+ String query = url.getQuery();
+ if (ParameterValidation.isNullOrEmpty(query))
+ {
+ query = WSRPRewritingConstants.GTNRESOURCE;
+ }
+ else
+ {
+ query = "+" + WSRPRewritingConstants.GTNRESOURCE;
+ }
+
+ try
+ {
+ 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.encodeXWWWFormURL(uri.toString());
+ resource.setResourceId(s);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Cannot parse specified
Resource as a URI: " + url);
+ }*//*
+
}
- try
- {
- URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
url.getPort(),
- url.getPath(), query, url.getRef());
+ return context.renderURL(portletURL, format);
+ }
+ else
+ {
+ // match is not something we know how to process
+ return match;
+ }
+ }
+ }
+*/
- // set the resulting URI as the new resource ID, must be encoded as it
will be used in URLs
- String s = URLTools.encodeXWWWFormURL(uri.toString());
- resource.setResourceId(s);
- }
- catch (Exception e)
+ static class ResourceURLRewriter extends URLTools.URLReplacementGenerator
+ {
+ public String getReplacementFor(int currentIndex, URLTools.URLMatch currentMatch)
+ {
+ String urlAsString = currentMatch.getURLAsString();
+ int beginning =
urlAsString.indexOf(WSRPRewritingConstants.FAKE_RESOURCE_START);
+ if (beginning != -1)
+ {
+ int index =
urlAsString.lastIndexOf(WSRPRewritingConstants.FAKE_RESOURCE_REQ_REW);
+
+ /*String requireRewriteStr = urlAsString.substring(
+ index + WSRPRewritingConstants.FAKE_RESOURCE_REQ_REW.length(),
+ urlAsString.indexOf(WSRPRewritingConstants.END_WSRP_REWRITE)
+ );
+ boolean requireRewrite = Boolean.valueOf(requireRewriteStr);
+ if (requireRewrite)
{
- throw new IllegalArgumentException("Cannot parse specified Resource
as a URI: " + url);
+ // FIX-ME: do something
+ log.debug("Required re-writing but this is not yet
implemented...");
}*/
+
+ urlAsString =
urlAsString.substring(WSRPRewritingConstants.FAKE_RESOURCE_START.length(), index);
+ return URLTools.decodeXWWWFormURL(urlAsString);
}
- return context.renderURL(portletURL, format);
+ return urlAsString;
}
}
private static String getResourceURL(String urlAsString, WSRPResourceURL resource)
{
String resourceURL = resource.getResourceURL().toExternalForm();
- log.info("URL '" + urlAsString + "' refers to a resource
which are not currently well supported. " +
- "Attempting to craft a URL that we might be able to work with: '"
+ resourceURL + "'");
+ if (log.isDebugEnabled())
+ {
+ log.debug("URL '" + urlAsString + "' refers to a resource
which are not currently well supported. " +
+ "Attempting to craft a URL that we might be able to work with:
'" + resourceURL + "'");
+ }
// right now the resourceURL should be output as is, because it will be used
directly but it really should be encoded
return resourceURL;
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/RenderHandlerTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/RenderHandlerTestCase.java 2010-03-19
16:03:50 UTC (rev 2316)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/RenderHandlerTestCase.java 2010-03-19
16:26:02 UTC (rev 2317)
@@ -24,23 +24,126 @@
package org.gatein.wsrp.consumer;
import junit.framework.TestCase;
+import org.gatein.common.net.URLTools;
+import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.URLFormat;
+import org.gatein.wsrp.WSRPRewritingConstants;
+import org.gatein.wsrp.test.support.MockWSRPConsumer;
+import org.gatein.wsrp.test.support.TestPortletInvocationContext;
/**
- * todo: FIX-ME!
- *
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision: 10507 $
* @since 2.6
*/
public class RenderHandlerTestCase extends TestCase
{
- public void testResourceURLRewriterProcessNonResource()
+ public static final String NAMESPACE = "NAMESPACE";
+ public static final String PORTLETID = "PORTLETID";
+ public static final MockWSRPConsumer CONSUMER = new
MockWSRPConsumer("foo");
+ public static final PortletContext PORTLET_CONTEXT =
PortletContext.createPortletContext(PORTLETID);
+ public static final TestPortletInvocationContext CONTEXT = new
TestPortletInvocationContext();
+ public static final URLFormat FORMAT = new URLFormat(false, false, true, true);
+
+ public void testProcessMarkup()
{
- /*String markup = "<a
href=\"/portal/portal/default/Test/EXAMPLE/EXAMPLE?action=1d&windowstate=&mode="
+
+ String markup;
+ String expected;
+ markup =
"khlaksdhjflkjhsadljkwsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite"
+
+
"fadsfadswsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewritefajdshfkjdshgfgrept";
+ expected = "khlaksdhjflkjhsadljkAction is=JBPNS_ ns=null ws=null m=null"
+
+ "fadsfadsRender ns=JBPNS_ ws=null m=nullfajdshfkjdshgfgrept";
+ processMarkupAndCheck(markup, expected);
+
+ markup = "<form method='post'
action='wsrp_rewrite?wsrp-urlType=blockingAction&wsrp" +
+ "-interactionState=JBPNS_/wsrp_rewrite'
id='wsrp_rewrite_portfolioManager'><table><tr><td>Stock
symbol</t" +
+ "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>";
+ expected = "<form method='post' action='Action is=JBPNS_
ns=null ws=null m=null' id='" + NAMESPACE
+ + "_portfolioManager'><table><tr><td>Stock
symbol</t" +
+ "d><td><input
name='symbol'/></td></tr><tr><td><input
type='submit'
value='Submit'></td></tr></table></form>";
+ processMarkupAndCheck(markup, expected);
+ }
+
+ public void testResourceURLs()
+ {
+ String markup;
+ String expected;
+ markup = "<img
src='wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Ftest-resource-portlet%2Fgif%2Flogo.gif&wsrp-requiresRewrite=true/wsrp_rewrite'/>";
+ expected = "<img
src='http://localhost:8080/test-resource-portlet/gif/logo.gif'/>";
+ processMarkupAndCheck(markup, expected);
+
+ markup = "<img
src='http://localhost:8080/test-resourcenoencodeurl-portlet/gif/logo.gif'/>";
+ processMarkupAndCheck(markup, markup);
+
+ markup =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite/helloworld.jar";
+ processMarkupAndCheck(markup,
"http://localhost:8080/helloworld/helloworld.jar");
+
+ markup =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Flocalhost%3A8080%2Fhelloworld&wsrp-requiresRewrite=true/wsrp_rewrite&foo=bar/helloworld.jar";
+ processMarkupAndCheck(markup,
"http://localhost:8080/helloworld&foo=bar/helloworld.jar");
+ }
+
+ public void testRegularURLIsNotAffected()
+ {
+ String markup;
+ markup = "<a
href=\"/portal/portal/default/Test/EXAMPLE/EXAMPLE?action=1d&windowstate=&mode="
+
"&ns=_next%3D%2Fdk%2Fskat%2Fportal%2Ffront%2Fportlets%2Fexample%2Findex.jsp"
+
"&is=_action%3D%252Fdk%252Fskat%252Fportal%252Ffront%252Fportlets%252Fexample%252FprocessLink"
+
"%26jbpns_2fdefault_2fTest_2fEXAMPLE_2fEXAMPLEsnpbjname%3DChris\">Press to
use default name.</a>";
- String result = URLTools.replaceURLsBy(markup, new
RenderHandler.WSRPURLRewriter());
- assertEquals(markup, result);*/
+ processMarkupAndCheck(markup, markup);
}
+
+ public void testProcessMarkupResourceFromTemplate()
+ {
+ String url =
"http%3a%2f%2fwsrp.netunitysoftware.com%2fWSRPTestService%2fWSRPTestService.asmx%3ftimeout%3d30000%2fgetResource%3fportletHandle%3d781F3EE5-22DF-4ef9-9664-F5FC759065DB%26Function%3dResource%26Name%3dNetUnity%26Type%3dGIF";
+ String markup = "<table cellpadding=\"2\"
cellspacing=\"0\" border=\"0\" width=\"100%\">\n" +
+ "\t<tr class=\"portlet-table-header\">\n" +
+ "\t\t<td>Symbol</td>\n" +
+ "\t\t<td>Name</td>\n" +
+ "\t\t<td align=\"right\">Price</td>\n" +
+ "\t\t<td></td>\n" +
+ "\t\t<td align=\"right\">Change</td>\n" +
+ "\t\t<td align=\"right\">% Chg</td>\n" +
+ "\t</tr>\n" +
+ "</table>\n" +
+ "<A HREF=\"http://www.netunitysoftware.com\"
TITLE=\"NetUnity WSRP .NET Framework\" >" +
+ "<img src=\"" + getResourceURL(url, false) + "\"
border=\"0\" /></A>";
+
+ String expected = "<table cellpadding=\"2\"
cellspacing=\"0\" border=\"0\" width=\"100%\">\n" +
+ "\t<tr class=\"portlet-table-header\">\n" +
+ "\t\t<td>Symbol</td>\n" +
+ "\t\t<td>Name</td>\n" +
+ "\t\t<td align=\"right\">Price</td>\n" +
+ "\t\t<td></td>\n" +
+ "\t\t<td align=\"right\">Change</td>\n" +
+ "\t\t<td align=\"right\">% Chg</td>\n" +
+ "\t</tr>\n" +
+ "</table>\n" +
+ "<A HREF=\"http://www.netunitysoftware.com\"
TITLE=\"NetUnity WSRP .NET Framework\" >" +
+ "<img src=\"" + URLTools.decodeXWWWFormURL(url) +
"\" border=\"0\" /></A>";
+ processMarkupAndCheck(markup, expected);
+ }
+
+ private void processMarkupAndCheck(String markup, String expected)
+ {
+ String result = null;
+ for (int i = 0; i < 100000; i++)
+ {
+ result = RenderHandler.processMarkup(
+ markup,
+ NAMESPACE,
+ CONTEXT,
+ PORTLET_CONTEXT,
+ FORMAT,
+ CONSUMER
+ );
+ }
+ assertEquals(expected, result);
+ }
+
+ private String getResourceURL(String encodedURL, boolean requiresRewrite)
+ {
+ String result =
WSRPRewritingConstants.FAKE_RESOURCE_URL.replace(WSRPRewritingConstants.WSRP_URL,
encodedURL);
+ result = result.replace(WSRPRewritingConstants.WSRP_REQUIRES_REWRITE,
Boolean.toString(requiresRewrite));
+ return result;
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/BehaviorBackedServiceFactory.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/BehaviorBackedServiceFactory.java 2010-03-19
16:03:50 UTC (rev 2316)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/BehaviorBackedServiceFactory.java 2010-03-19
16:26:02 UTC (rev 2317)
@@ -1,25 +1,25 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2007, 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * 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.
+ *
+ * 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.gatein.wsrp.test.support;
@@ -63,7 +63,7 @@
private final static String R_URL = "r";
private boolean initialized = false;
private String wsdl = DEFAULT_WSDL_URL;
- public static final String DEFAULT_WSDL_URL = "http://example.com?wsdl";
+ public static final String DEFAULT_WSDL_URL =
"http://example.com/producer?wsdl";
private int timeout;
Added:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockEndpointConfigurationInfo.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockEndpointConfigurationInfo.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockEndpointConfigurationInfo.java 2010-03-19
16:26:02 UTC (rev 2317)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, a division of Red Hat
+ * 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.
+ *
+ * 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.gatein.wsrp.test.support;
+
+import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class MockEndpointConfigurationInfo extends EndpointConfigurationInfo
+{
+ public MockEndpointConfigurationInfo()
+ {
+ super(new BehaviorBackedServiceFactory());
+ }
+}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2010-03-19
16:03:50 UTC (rev 2316)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2010-03-19
16:26:02 UTC (rev 2317)
@@ -1,25 +1,25 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2007, 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * 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.
+ *
+ * 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.gatein.wsrp.test.support;
@@ -36,7 +36,6 @@
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.ProducerSessionInformation;
import org.gatein.wsrp.consumer.RefreshResult;
-import org.gatein.wsrp.services.ServiceFactory;
import javax.servlet.http.HttpSession;
import java.util.List;
@@ -55,6 +54,7 @@
{
producerInfo = new ProducerInfo();
producerInfo.setId(id);
+ producerInfo.setEndpointConfigurationInfo(new MockEndpointConfigurationInfo());
}
public String getProducerId()
@@ -62,10 +62,6 @@
return producerInfo.getId();
}
- public void setServiceFactory(ServiceFactory serviceFactory)
- {
- }
-
public ProducerSessionInformation getProducerSessionInformationFrom(PortletInvocation
invocation)
{
return null;
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/TestPortletInvocationContext.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/TestPortletInvocationContext.java 2010-03-19
16:03:50 UTC (rev 2316)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/TestPortletInvocationContext.java 2010-03-19
16:26:02 UTC (rev 2317)
@@ -1,32 +1,34 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * 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.
+ *
+ * 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.gatein.wsrp.test.support;
import org.gatein.common.net.media.MediaType;
import org.gatein.common.util.MarkupInfo;
-import org.gatein.common.util.ParameterMap;
+import org.gatein.pc.api.ActionURL;
import org.gatein.pc.api.ContainerURL;
+import org.gatein.pc.api.RenderURL;
+import org.gatein.pc.api.ResourceURL;
import org.gatein.pc.api.StateString;
import org.gatein.pc.api.URLFormat;
import org.gatein.pc.api.spi.PortletInvocationContext;
@@ -34,9 +36,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -92,41 +91,25 @@
public String renderURL(ContainerURL containerURL, URLFormat urlFormat)
{
- return null;
- }
+ String result;
+ if (containerURL instanceof ActionURL)
+ {
+ ActionURL actionURL = (ActionURL)containerURL;
+ result = "Action is=" +
actionURL.getInteractionState().getStringValue();
+ }
+ else if (containerURL instanceof RenderURL)
+ {
+ result = "Render";
+ }
+ else
+ {
+ result = "Resource id=" +
((ResourceURL)containerURL).getResourceId();
+ }
- public String getCharacterEncoding()
- {
- return null;
- }
+ StateString ns = containerURL.getNavigationalState();
+ result += " ns=" + (ns != null ? ns.getStringValue() : null) + "
ws=" + containerURL.getWindowState() + " m="
+ + containerURL.getMode();
- public int getContentLength()
- {
- return 0;
+ return result;
}
-
- public BufferedReader getReader() throws IOException
- {
- return null;
- }
-
- public InputStream getInputStream() throws IOException
- {
- return null;
- }
-
- public String getContentType()
- {
- return null;
- }
-
- public StateString getInteractionState()
- {
- return null;
- }
-
- public ParameterMap getForm()
- {
- return null;
- }
}