Author: chris.laprun(a)jboss.com
Date: 2010-10-06 05:47:42 -0400 (Wed, 06 Oct 2010)
New Revision: 4524
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPWindowContext.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/RenderHandlerTestCase.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPInstanceContext.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/NeedPortletHandleTest.java
Log:
- GTNWSRP-87: work on namespace being doubly encoded.
+ CFixed MimeResponseHandler.processMarkup as it wasn't properly working for WSRP 1.
Will probably need TextTools support from new version of common to avoid double parsing of
markup.
+ Properly use the WSRP-provided namespace using a custom WindowContext implementation:
WSRPWindowContext.
+ Moved namespace initialization to MimeResponseProcessor on producer since the behavior
is the same in all subclasses and deactivated it for now as it's not needed anymore in
WSRP 2. Need to check that it works properly with WSRP 1.
+ Introduced ProducerHelper interface to decouple processors from WSRPProducerImpl so
that they're easier to test.
+ Adapted test cases.
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -34,7 +34,6 @@
import org.gatein.pc.api.spi.PortletInvocationContext;
import org.gatein.pc.api.spi.SecurityContext;
import org.gatein.pc.api.spi.WindowContext;
-import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
import org.gatein.wsrp.WSRPConstants;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
@@ -199,8 +198,7 @@
{
if (windowContext != null)
{
- // MUST match namespace generation used in PortletResponseImpl.getNamespace in
portlet module...
- return PortletUtils.generateNamespaceFrom(windowContext.getId());
+ return windowContext.getNamespace();
}
return null;
@@ -334,15 +332,15 @@
SecurityContext securityContext = invocation.getSecurityContext();
ParameterValidation.throwIllegalArgExceptionIfNull(securityContext,
SECURITY_CONTEXT);
String authType =
WSRPUtils.convertRequestAuthTypeToWSRPAuthType(securityContext.getAuthType());
-
+
String portletInstanceKey = invocation.getInstanceContext().getId();
String namespacePrefix = getNamespaceFrom(invocation.getWindowContext());
-
+
if (namespacePrefix == null)
{
namespacePrefix = getPortletHandle();
}
-
+
runtimeContext = WSRPTypeFactory.createRuntimeContext(authType,
portletInstanceKey, namespacePrefix);
// user context
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/MimeResponseHandler.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -136,14 +136,18 @@
markup = TextTools.replaceBoundedString(
markup,
- WSRPRewritingConstants.WSRP_REWRITE,
+ WSRPRewritingConstants.BEGIN_WSRP_REWRITE,
WSRPRewritingConstants.END_WSRP_REWRITE,
new MarkupProcessor(namespace, context, target, format,
consumer.getProducerInfo()),
true,
- false,
- true
+ false
);
+ if (!consumer.isUsingWSRP2())
+ {
+ markup = markup.replaceAll(WSRPRewritingConstants.WSRP_REWRITE_TOKEN,
namespace);
+ }
+
return markup;
}
@@ -209,23 +213,8 @@
public String getReplacementFor(String match, String prefix, String suffix)
{
- 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);
- return context.renderURL(portletURL, format);
- }
- else
- {
- // match is not something we know how to process
- return match;
- }
+ WSRPPortletURL portletURL = WSRPPortletURL.create(match, supportedCustomModes,
supportedCustomWindowStates, true);
+ return context.renderURL(portletURL, format);
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/RenderHandlerTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/RenderHandlerTestCase.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/handlers/RenderHandlerTestCase.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -44,8 +44,17 @@
public static final TestPortletInvocationContext CONTEXT = new
TestPortletInvocationContext();
public static final URLFormat FORMAT = new URLFormat(false, false, true, true);
- public void testProcessMarkup()
+ @Override
+ protected void setUp() throws Exception
{
+ CONSUMER.setUsingWSRP2(true);
+ }
+
+ public void testProcessMarkupV1()
+ {
+ // fake using WSRP 1
+ CONSUMER.setUsingWSRP2(false);
+
String markup;
String expected;
markup =
"khlaksdhjflkjhsadljkwsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite"
+
@@ -58,11 +67,31 @@
"-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" +
+ + "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 testProcessMarkupV2()
+ {
+ 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);
+
+ // in WSRP 2, we don't process wsrp_rewrite_ tokens anymore as the consumer
MUST to provide a namespace
+ // so the producer can generate the proper markup directly
+ 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='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>";
+ processMarkupAndCheck(markup, expected);
+ }
+
/*public void testResourceURLs()
{
String markup;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -43,6 +43,7 @@
import org.gatein.wsrp.producer.handlers.PortletManagementHandler;
import org.gatein.wsrp.producer.handlers.RegistrationHandler;
import org.gatein.wsrp.producer.handlers.ServiceDescriptionHandler;
+import org.gatein.wsrp.producer.handlers.processors.ProducerHelper;
import org.gatein.wsrp.producer.v2.WSRP2Producer;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.oasis.wsrp.v2.AccessDenied;
@@ -123,7 +124,7 @@
* @version $Revision: 12286 $
* @since 2.4
*/
-public class WSRPProducerImpl implements WSRP2Producer
+public class WSRPProducerImpl implements WSRP2Producer, ProducerHelper
{
/** logger used for logging ;) */
private static final Logger log = LoggerFactory.getLogger(WSRPProducerImpl.class);
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -32,7 +32,6 @@
import org.gatein.pc.api.state.AccessMode;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.producer.WSRPProducerImpl;
import org.gatein.wsrp.producer.handlers.MarkupHandler;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.oasis.wsrp.v2.BlockingInteractionResponse;
@@ -61,7 +60,7 @@
{
private final PerformBlockingInteraction performBlockingInteraction;
- ActionRequestProcessor(WSRPProducerImpl producer, PerformBlockingInteraction
performBlockingInteraction)
+ ActionRequestProcessor(ProducerHelper producer, PerformBlockingInteraction
performBlockingInteraction)
throws UnsupportedMimeType, UnsupportedWindowState, InvalidHandle, UnsupportedMode,
MissingParameters,
InvalidRegistration, OperationFailed
{
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -33,7 +33,6 @@
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.payload.PayloadUtils;
-import org.gatein.wsrp.producer.WSRPProducerImpl;
import org.gatein.wsrp.producer.handlers.MarkupHandler;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.oasis.wsrp.v2.Event;
@@ -67,7 +66,7 @@
{
private HandleEvents handleEvents;
- public EventRequestProcessor(WSRPProducerImpl producer, HandleEvents handleEvents)
throws OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters,
UnsupportedMimeType, UnsupportedWindowState, InvalidRegistration, OperationNotSupported
+ public EventRequestProcessor(ProducerHelper producer, HandleEvents handleEvents)
throws OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters,
UnsupportedMimeType, UnsupportedWindowState, InvalidRegistration, OperationNotSupported
{
super(producer);
this.handleEvents = handleEvents;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -24,13 +24,12 @@
package org.gatein.wsrp.producer.handlers.processors;
import org.gatein.common.net.URLTools;
+import org.gatein.pc.api.invocation.PortletInvocation;
import org.gatein.pc.api.invocation.response.ContentResponse;
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
import org.gatein.wsrp.WSRPConstants;
-import org.gatein.wsrp.WSRPRewritingConstants;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.producer.WSRPProducerImpl;
import org.gatein.wsrp.servlet.ServletAccess;
import org.oasis.wsrp.v2.MimeResponse;
@@ -40,14 +39,22 @@
*/
abstract class MimeResponseProcessor<LocalMimeResponse extends MimeResponse,
Response> extends RequestProcessor<Response>
{
- protected String namespace;
+// private String namespace;
private static final String EMPTY = "";
- protected MimeResponseProcessor(WSRPProducerImpl producer)
+ protected MimeResponseProcessor(ProducerHelper producer)
{
super(producer);
}
+ @Override
+ PortletInvocation initInvocation(WSRPPortletInvocationContext context)
+ {
+// namespace = getRuntimeContext().getNamespacePrefix();
+
+ return internalInitInvocation(context);
+ }
+
/**
* Process String returned from RenderResult to add rewriting token if necessary,
replacing namespaces by the WSRP
* rewrite token. fix-me: need to check for producer rewriting
@@ -57,10 +64,9 @@
*/
protected String processFragmentString(String renderString)
{
- String result = renderString.replaceAll(namespace,
WSRPRewritingConstants.WSRP_REWRITE);
+// String result = renderString.replaceAll(namespace,
WSRPRewritingConstants.WSRP_REWRITE);
- result = URLTools.replaceURLsBy(result, new
WSRPUtils.AbsoluteURLReplacementGenerator(ServletAccess.getRequest()));
- return result;
+ return URLTools.replaceURLsBy(renderString, new
WSRPUtils.AbsoluteURLReplacementGenerator(ServletAccess.getRequest()));
}
public Response processResponse(PortletInvocationResponse response)
@@ -125,4 +131,6 @@
{
// default implementation does nothing
}
+
+ protected abstract PortletInvocation
internalInitInvocation(WSRPPortletInvocationContext context);
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -23,7 +23,6 @@
package org.gatein.wsrp.producer.handlers.processors;
-import org.gatein.wsrp.producer.WSRPProducerImpl;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.oasis.wsrp.v2.GetMarkup;
import org.oasis.wsrp.v2.GetResource;
@@ -44,7 +43,7 @@
*/
public class ProcessorFactory
{
- public static RequestProcessor getProcessorFor(WSRPProducerImpl producer, Object
request)
+ public static RequestProcessor getProcessorFor(ProducerHelper producer, Object
request)
throws OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters,
UnsupportedMimeType,
UnsupportedWindowState, InvalidRegistration
{
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -0,0 +1,51 @@
+/*
+ * 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.producer.handlers.processors;
+
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.registration.Registration;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.PortletDescription;
+import org.oasis.wsrp.v2.RegistrationContext;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public interface ProducerHelper
+{
+ Portlet getPortletWith(org.gatein.pc.api.PortletContext portletContext, Registration
registration) throws InvalidHandle, PortletInvokerException;
+
+ PortletDescription getPortletDescription(PortletContext portletContext,
List<String> locales, Registration registration) throws InvalidHandle,
OperationFailed;
+
+ PortletDescription getPortletDescription(Portlet portlet, List<String>
locales);
+
+ Registration getRegistrationOrFailIfInvalid(RegistrationContext registrationContext)
throws InvalidRegistration, OperationFailed;
+}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -27,9 +27,7 @@
import org.gatein.pc.api.invocation.RenderInvocation;
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
import org.gatein.pc.api.state.AccessMode;
-import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.producer.WSRPProducerImpl;
import org.gatein.wsrp.producer.handlers.MarkupHandler;
import org.oasis.wsrp.v2.GetMarkup;
import org.oasis.wsrp.v2.InvalidHandle;
@@ -55,7 +53,7 @@
{
private final GetMarkup getMarkup;
- public RenderRequestProcessor(WSRPProducerImpl producer, GetMarkup getMarkup) throws
UnsupportedMimeType,
+ public RenderRequestProcessor(ProducerHelper producer, GetMarkup getMarkup) throws
UnsupportedMimeType,
UnsupportedWindowState, InvalidHandle, UnsupportedMode, MissingParameters,
InvalidRegistration, OperationFailed
{
super(producer);
@@ -98,12 +96,8 @@
return AccessMode.READ_ONLY;
}
- @Override
- PortletInvocation initInvocation(WSRPPortletInvocationContext context)
+ protected PortletInvocation internalInitInvocation(WSRPPortletInvocationContext
context)
{
- // MUST match namespace generation used in PortletResponseImpl.getNamespace in
portlet module...
- namespace =
PortletUtils.generateNamespaceFrom(context.getWindowContext().getId());
-
return new RenderInvocation(context);
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -38,12 +38,12 @@
import org.gatein.pc.api.spi.UserContext;
import org.gatein.pc.api.spi.WindowContext;
import org.gatein.pc.api.state.AccessMode;
+import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
import org.gatein.registration.Registration;
import org.gatein.wsrp.UserContextConverter;
import org.gatein.wsrp.WSRPConstants;
import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.producer.Utils;
-import org.gatein.wsrp.producer.WSRPProducerImpl;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.InvalidRegistration;
@@ -85,10 +85,10 @@
protected PortletDescription portletDescription;
protected Portlet portlet;
protected WSRPInstanceContext instanceContext;
- protected WSRPProducerImpl producer;
+ protected ProducerHelper producer;
- protected RequestProcessor(WSRPProducerImpl producer)
+ protected RequestProcessor(ProducerHelper producer)
{
this.producer = producer;
}
@@ -145,7 +145,8 @@
MarkupInfo streamInfo = createStreamInfo(markupRequest);
PortalContext portalContext = createPortalContext(params, markupRequest);
UserContext userContext = createUserContext(wsrpUserContext,
markupRequest.getLocale(), desiredLocales);
- instanceContext = createInstanceContext(portletContext, getAccessMode(),
runtimeContext.getPortletInstanceKey());
+ String portletInstanceKey = runtimeContext.getPortletInstanceKey();
+ instanceContext = createInstanceContext(portletContext, getAccessMode(),
portletInstanceKey);
WindowContext windowContext = createWindowContext(portletContext.getId(),
runtimeContext);
// prepare the invocation
@@ -376,22 +377,19 @@
private WindowContext createWindowContext(final String portletHandle, final
RuntimeContext runtimeContext)
{
- return new WindowContext()
+ String id = runtimeContext.getPortletInstanceKey();
+ if (ParameterValidation.isNullOrEmpty(id))
{
- public String getId()
- {
- String prefix = runtimeContext.getNamespacePrefix();
- if (prefix != null && prefix.length() > 0)
- {
- return prefix;
- }
- else
- {
- // No provided namespace prefix for portlet, using portlet handle instead
- return portletHandle;
- }
- }
- };
+ id = portletHandle;
+ }
+
+ String namespacePrefix = runtimeContext.getNamespacePrefix();
+ if (ParameterValidation.isNullOrEmpty(namespacePrefix))
+ {
+ namespacePrefix = PortletUtils.generateNamespaceFrom(portletHandle);
+ }
+
+ return new WSRPWindowContext(id, namespacePrefix);
}
private UserContext createUserContext(final org.oasis.wsrp.v2.UserContext
userContext,
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -26,11 +26,9 @@
import org.gatein.pc.api.invocation.PortletInvocation;
import org.gatein.pc.api.invocation.ResourceInvocation;
import org.gatein.pc.api.state.AccessMode;
-import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
import org.gatein.wsrp.WSRPResourceURL;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.producer.WSRPProducerImpl;
import org.gatein.wsrp.producer.handlers.MarkupHandler;
import org.oasis.wsrp.v2.GetResource;
import org.oasis.wsrp.v2.InvalidHandle;
@@ -57,7 +55,7 @@
{
private final GetResource getResource;
- public ResourceRequestProcessor(WSRPProducerImpl producer, GetResource getResource)
throws InvalidRegistration, OperationFailed, MissingParameters, InvalidHandle,
UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode
+ public ResourceRequestProcessor(ProducerHelper producer, GetResource getResource)
throws InvalidRegistration, OperationFailed, MissingParameters, InvalidHandle,
UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode
{
super(producer);
this.getResource = getResource;
@@ -105,11 +103,8 @@
return getResource.getUserContext();
}
- @Override
- PortletInvocation initInvocation(WSRPPortletInvocationContext context)
+ protected PortletInvocation internalInitInvocation(WSRPPortletInvocationContext
context)
{
- // MUST match namespace generation used in PortletResponseImpl.getNamespace in
portlet module...
- namespace =
PortletUtils.generateNamespaceFrom(context.getWindowContext().getId());
ResourceInvocation resourceInvocation = new ResourceInvocation(context);
ResourceParams resourceParams = this.getResource.getResourceParams();
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -27,7 +27,6 @@
import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.producer.WSRPProducerImpl;
import org.oasis.wsrp.v2.NavigationalContext;
import org.oasis.wsrp.v2.PortletContext;
import org.oasis.wsrp.v2.UpdateResponse;
@@ -40,7 +39,7 @@
*/
abstract class UpdateNavigationalStateResponseProcessor<Response> extends
RequestProcessor<Response>
{
- public UpdateNavigationalStateResponseProcessor(WSRPProducerImpl producer)
+ public UpdateNavigationalStateResponseProcessor(ProducerHelper producer)
{
super(producer);
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPInstanceContext.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPInstanceContext.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPInstanceContext.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -51,7 +51,7 @@
this.context = portletContext;
this.accessMode = accessMode;
- if (instanceId != null && instanceId.length() > 0)
+ if (!ParameterValidation.isNullOrEmpty(instanceId))
{
this.instanceId = instanceId;
}
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPWindowContext.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPWindowContext.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPWindowContext.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -0,0 +1,55 @@
+/*
+ * 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.producer.handlers.processors;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.spi.WindowContext;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class WSRPWindowContext implements WindowContext
+{
+ private final String id;
+ private final String ns;
+
+ public WSRPWindowContext(String id, String namespacePrefix)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "id",
"WSRPWindowContext");
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(namespacePrefix,
"namespace", "WSRPWindowContext");
+ this.id = id;
+ this.ns = namespacePrefix;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public String getNamespace()
+ {
+ return ns;
+ }
+}
Added:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java
(rev 0)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -0,0 +1,121 @@
+/*
+ * 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.producer.handlers.processors;
+
+import junit.framework.TestCase;
+import org.gatein.common.net.media.MediaType;
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.info.PortletInfo;
+import org.gatein.registration.Registration;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.servlet.ServletAccess;
+import org.gatein.wsrp.test.support.MockHttpServletRequest;
+import org.gatein.wsrp.test.support.MockHttpServletResponse;
+import org.gatein.wsrp.test.support.MockHttpSession;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.MarkupType;
+import org.oasis.wsrp.v2.MissingParameters;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PortletDescription;
+import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.UnsupportedMimeType;
+import org.oasis.wsrp.v2.UnsupportedMode;
+import org.oasis.wsrp.v2.UnsupportedWindowState;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class MimeResponseProcessorTestCase extends TestCase
+{
+ private static final String PORTLET_HANDLE = "portletHandle";
+
+ public void testShouldUseProvidedNamespace() throws OperationFailed, UnsupportedMode,
InvalidHandle, MissingParameters, UnsupportedMimeType, UnsupportedWindowState,
InvalidRegistration
+ {
+ String namespace = "namespace";
+
ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(MockHttpSession.createMockSession()),
MockHttpServletResponse.createMockResponse());
+
+ MimeResponseProcessor processor = new RenderRequestProcessor(new
TestProducerHelper(), WSRPTypeFactory.createGetMarkup(null,
+ WSRPTypeFactory.createPortletContext(PORTLET_HANDLE),
+ WSRPTypeFactory.createRuntimeContext(WSRPConstants.NONE_USER_AUTHENTICATION,
"foo", namespace), null,
+ WSRPTypeFactory.createMarkupParams(false, WSRPConstants.getDefaultLocales(),
WSRPConstants.getDefaultMimeTypes(), WSRPConstants.VIEW_MODE,
WSRPConstants.NORMAL_WINDOW_STATE)));
+
+ assertEquals("namespace",
processor.invocation.getWindowContext().getNamespace());
+ }
+
+ private static class TestProducerHelper implements ProducerHelper
+ {
+ public Portlet getPortletWith(PortletContext portletContext, Registration
registration) throws InvalidHandle, PortletInvokerException
+ {
+ return new Portlet()
+ {
+ public PortletContext getContext()
+ {
+ return PortletContext.createPortletContext(PORTLET_HANDLE);
+ }
+
+ public PortletInfo getInfo()
+ {
+ return null; //To change body of implemented methods use File | Settings
| File Templates.
+ }
+
+ public boolean isRemote()
+ {
+ return false;
+ }
+ };
+ }
+
+ public PortletDescription getPortletDescription(org.oasis.wsrp.v2.PortletContext
portletContext, List<String> locales, Registration registration) throws
InvalidHandle, OperationFailed
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public PortletDescription getPortletDescription(Portlet portlet, List<String>
locales)
+ {
+ List<String> modeNames = new ArrayList<String>(1);
+ modeNames.add(WSRPConstants.VIEW_MODE);
+
+ List<String> windowStateNames = new ArrayList<String>(1);
+ windowStateNames.add(WSRPConstants.NORMAL_WINDOW_STATE);
+
+ List<MarkupType> markupTypes = new ArrayList<MarkupType>(1);
+ markupTypes.add(WSRPTypeFactory.createMarkupType(MediaType.TEXT_HTML.getValue(),
modeNames, windowStateNames, locales));
+
+ return WSRPTypeFactory.createPortletDescription(PORTLET_HANDLE, markupTypes);
+ }
+
+ public Registration getRegistrationOrFailIfInvalid(RegistrationContext
registrationContext) throws InvalidRegistration, OperationFailed
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+ }
+}
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -167,8 +167,9 @@
V1MarkupResponse response = producer.getMarkup(getMarkup);
+ String namespacePrefix = getMarkup.getRuntimeContext().getNamespacePrefix();
checkMarkupResponse(response, "<form method='post'
action='wsrp_rewrite?wsrp-urlType=blockingAction&wsrp" +
- "-interactionState=JBPNS_/wsrp_rewrite'
id='wsrp_rewriteportfolioManager'><table><tr><td>Stock
symbol</t" +
+ "-interactionState=JBPNS_/wsrp_rewrite' id='" +
namespacePrefix + "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>");
}
@@ -230,6 +231,7 @@
}
// fix-me: add more tests
+
@Test
public void testGetMarkupSession() throws Exception
{
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -183,8 +183,9 @@
MarkupResponse response = producer.getMarkup(getMarkup);
+ String namespacePrefix = getMarkup.getRuntimeContext().getNamespacePrefix();
checkMarkupResponse(response, "<form method='post'
action='wsrp_rewrite?wsrp-urlType=blockingAction&wsrp" +
- "-interactionState=JBPNS_/wsrp_rewrite'
id='wsrp_rewriteportfolioManager'><table><tr><td>Stock
symbol</t" +
+ "-interactionState=JBPNS_/wsrp_rewrite' id='" +
namespacePrefix + "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>");
}
@@ -246,6 +247,7 @@
}
// fix-me: add more tests
+
@Test
public void testGetMarkupSession() throws Exception
{
@@ -655,7 +657,7 @@
{
System.out.println("ERROR during " + this.getClass() + "
testImplicitCloning");
e.printStackTrace();
- throw new Exception (e);
+ throw new Exception(e);
}
}
@@ -845,7 +847,7 @@
// send event
HandleEvents handleEvents = WSRPTypeFactory.createHandleEvents(null,
- WSRPTypeFactory.createPortletContext(consumerHandle),
createDefaultRuntimeContext(consumerHandle), null,
+ WSRPTypeFactory.createPortletContext(consumerHandle),
createDefaultRuntimeContext(), null,
createDefaultMarkupParams(), WSRPTypeFactory.createEventParams(events,
StateChange.READ_ONLY));
HandleEventsResponse handleEventsResponse =
producer.handleEvents(handleEvents);
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/NeedPortletHandleTest.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/NeedPortletHandleTest.java 2010-10-06
09:28:23 UTC (rev 4523)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/NeedPortletHandleTest.java 2010-10-06
09:47:42 UTC (rev 4524)
@@ -202,8 +202,8 @@
* @param handle
* @return
* @throws RemoteException
- * @throws V1InvalidRegistrationFault
- * @throws V1OperationFailedFault
+ * @throws InvalidRegistration
+ * @throws OperationFailed
* @since 2.6.3
*/
protected GetMarkup createMarkupRequest(String handle) throws RemoteException,
InvalidRegistration, OperationFailed
@@ -213,40 +213,37 @@
return getMarkup;
}
-
+
protected GetMarkup createDefaultGetMarkup(String handle)
{
PortletContext portletContext = WSRPTypeFactory.createPortletContext(handle);
- RuntimeContext runtimeContext = createDefaultRuntimeContext(handle);
- MarkupParams runtimeParams = createDefaultMarkupParams();
+ RuntimeContext runtimeContext = createDefaultRuntimeContext();
return WSRPTypeFactory.createGetMarkup(null, portletContext, runtimeContext, null,
createDefaultMarkupParams());
}
-
+
protected PerformBlockingInteraction createDefaultPerformBlockingInteraction(String
handle)
{
PortletContext portletContext = WSRPTypeFactory.createPortletContext(handle);
- return WSRPTypeFactory.createPerformBlockingInteraction(null, portletContext,
createDefaultRuntimeContext(handle), null, createDefaultMarkupParams(),
- createDefaultInteractionParams());
+ return WSRPTypeFactory.createPerformBlockingInteraction(null, portletContext,
createDefaultRuntimeContext(), null, createDefaultMarkupParams(),
+ createDefaultInteractionParams());
}
-
+
protected InteractionParams createDefaultInteractionParams()
{
return WSRPTypeFactory.createInteractionParams(StateChange.READ_ONLY);
}
-
- protected RuntimeContext createDefaultRuntimeContext(String handle)
+
+ protected RuntimeContext createDefaultRuntimeContext()
{
- String portletInstanceKey = "foo";
- String namespacePrefix = handle;
- return WSRPTypeFactory.createRuntimeContext(WSRPConstants.NONE_USER_AUTHENTICATION,
portletInstanceKey, namespacePrefix);
+ return WSRPTypeFactory.createRuntimeContext(WSRPConstants.NONE_USER_AUTHENTICATION,
"foo", "ns");
}
protected MarkupParams createDefaultMarkupParams()
{
return WSRPTypeFactory.createMarkupParams(false, WSRPConstants.getDefaultLocales(),
WSRPConstants.getDefaultMimeTypes(),
- WSRPConstants.VIEW_MODE, WSRPConstants.NORMAL_WINDOW_STATE);
+ WSRPConstants.VIEW_MODE, WSRPConstants.NORMAL_WINDOW_STATE);
}
-
+
protected String getPortletHandleFrom(String partialHandle)
{
List<String> handles = getHandlesForCurrentlyDeployedArchive();