Author: mwringe
Date: 2010-08-10 21:19:02 -0400 (Tue, 10 Aug 2010)
New Revision: 3794
Added:
components/wsrp/trunk/wsrp-producer-war/src/test/assembly/test-portletstate-portlet.xml
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java
components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-portletstate-portlet-war/
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportPortletData.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java
components/wsrp/trunk/producer/src/test/java/org/gatein/export/ExportTestCase.java
components/wsrp/trunk/wsrp-producer-war/pom.xml
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
Log:
GTNWSRP-55: fixed issue with importing/exporting with states. Updated tests.
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-08-10
15:35:03 UTC (rev 3793)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2010-08-11
01:19:02 UTC (rev 3794)
@@ -23,6 +23,7 @@
package org.gatein.wsrp.consumer;
+import org.gatein.common.NotYetImplemented;
import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.api.InvokerUnavailableException;
import org.gatein.pc.api.NoSuchPortletException;
@@ -390,8 +391,20 @@
}
}
+ public PortletContext exportPortletContext(PortletStateType stateType, PortletContext
originalPortletContext)
+ throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public PortletContext importPortletContext(PortletStateType stateType, PortletContext
originalPortletContext)
+ throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
// Accessors
********************************************************************************************************
-
+
public String getProducerId()
{
return producerInfo.getId();
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-08-10
15:35:03 UTC (rev 3793)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2010-08-11
01:19:02 UTC (rev 3794)
@@ -23,12 +23,14 @@
package org.gatein.wsrp.test.support;
+import org.gatein.common.NotYetImplemented;
import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.PortletContext;
import org.gatein.pc.api.PortletInvokerException;
import org.gatein.pc.api.PortletStateType;
import org.gatein.pc.api.invocation.PortletInvocation;
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.pc.api.state.DestroyCloneFailure;
import org.gatein.pc.api.state.PropertyChange;
import org.gatein.pc.api.state.PropertyMap;
import org.gatein.wsrp.WSRPConsumer;
@@ -167,4 +169,16 @@
public void onSessionEvent(SessionEvent event)
{
}
+
+ public PortletContext exportPortletContext(PortletStateType stateType, PortletContext
originalPortletContext)
+ throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public PortletContext importPortletContext(PortletStateType stateType, PortletContext
originalPortletContext)
+ throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java 2010-08-10
15:35:03 UTC (rev 3793)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java 2010-08-11
01:19:02 UTC (rev 3794)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.gatein.exports;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.gatein.exports.data.ExportContext;
@@ -50,9 +51,9 @@
ExportPortletData createExportPortletData(ExportContext exportContext, Lifetime
lifetime, byte[] bytes) throws OperationFailed;
- byte[] encodeExportPortletData(ExportContext exportContextData, ExportPortletData
exportPortletData) throws UnsupportedEncodingException;
+ byte[] encodeExportPortletData(ExportContext exportContextData, ExportPortletData
exportPortletData) throws UnsupportedEncodingException, IOException;
- byte[] encodeExportContextData (ExportContext exportContextData) throws
UnsupportedEncodingException;
+ byte[] encodeExportContextData (ExportContext exportContextData) throws
UnsupportedEncodingException, IOException;
Lifetime setExportLifetime(ExportContext exportContext, Lifetime lifetime) throws
OperationFailed, OperationNotSupported;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java 2010-08-10
15:35:03 UTC (rev 3793)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java 2010-08-11
01:19:02 UTC (rev 3794)
@@ -22,10 +22,13 @@
******************************************************************************/
package org.gatein.exports.data;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.UnsupportedEncodingException;
-import org.gatein.common.NotYetImplemented;
-
/**
* @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
* @version $Revision$
@@ -36,7 +39,7 @@
public abstract double getVersion();
public abstract String getType();
- protected abstract byte[] internalEncodeAsBytes() throws
UnsupportedEncodingException;
+ protected abstract byte[] internalEncodeAsBytes() throws UnsupportedEncodingException,
IOException;
//The encoding used to create the byte array
@@ -44,33 +47,37 @@
protected static final String SEPARATOR = "_@_";
- public byte[] encodeAsBytes() throws UnsupportedEncodingException
+ public byte[] encodeAsBytes() throws IOException
{
byte[] internalBytes = internalEncodeAsBytes();
- String token = this.getType() + SEPARATOR + this.getVersion() + SEPARATOR;
- String dataString = new String(internalBytes, ENCODING);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
- return (token + dataString).getBytes(ENCODING);
+ oos.writeUTF(this.getType());
+ oos.writeDouble(this.getVersion());
+
+ if (internalBytes != null)
+ {
+ oos.write(internalBytes);
+ }
+
+ oos.close();
+
+ return baos.toByteArray();
}
- public static double getVersion(byte[] bytes) throws UnsupportedEncodingException
+ public static double getVersion(byte[] bytes) throws IOException
{
if (bytes != null && bytes.length > 0)
{
- String dataString = new String(bytes, ENCODING);
- String[] split = dataString.split(SEPARATOR, 3);
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(bais);
- if (split.length >= 2)
- {
- double version = Double.parseDouble(split[1]);
- return version;
- }
- else
- {
- //if a version could not be found, return -1
- return -1;
- }
+ String type = ois.readUTF();
+ Double version = ois.readDouble();
+
+ return version.doubleValue();
}
else
{
@@ -78,21 +85,14 @@
}
}
- public static String getType(byte[] bytes) throws UnsupportedEncodingException
+ public static String getType(byte[] bytes) throws IOException
{
if (bytes != null && bytes.length > 0)
{
- String dataString = new String(bytes, ENCODING);
- String[] split = dataString.split(SEPARATOR, 2);
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(bais);
- if (split.length >= 2)
- {
- return split[0];
- }
- else
- {
- return null;
- }
+ return ois.readUTF();
}
else
{
@@ -100,29 +100,28 @@
}
}
- public static byte[] getInternalBytes(byte[] bytes) throws
UnsupportedEncodingException
+ public static byte[] getInternalBytes(byte[] bytes) throws IOException
{
if (bytes != null && bytes.length > 0)
{
- String dataString = new String(bytes, ENCODING);
- String[] split = dataString.split(SEPARATOR, 3);
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(bais);
- if (split.length >= 3)
+ String type = ois.readUTF();
+ Double version = ois.readDouble();
+
+ byte[] internalBytes = null;
+ if (ois.available() > 0)
{
- String internalString = split[2];
- return internalString.getBytes(ENCODING);
+ internalBytes = new byte[ois.available()];
+ ois.readFully(internalBytes);
}
- else
- {
- //if we could not find the internal bytes, return null
- return null;
- }
+ return internalBytes;
}
else
{
return null;
}
}
-
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportPortletData.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportPortletData.java 2010-08-10
15:35:03 UTC (rev 3793)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportPortletData.java 2010-08-11
01:19:02 UTC (rev 3794)
@@ -22,12 +22,12 @@
******************************************************************************/
package org.gatein.exports.data;
-import java.io.UnsupportedEncodingException;
-import java.util.Map;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
-import org.gatein.pc.api.ParametersStateString;
-import org.gatein.pc.api.StateString;
-
/**
* @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
* @version $Revision$
@@ -71,51 +71,46 @@
return VERSION;
}
- public static ExportPortletData create(byte[] bytes) throws
UnsupportedEncodingException
+ public static ExportPortletData create(byte[] bytes) throws IOException
{
- //why isn't there a way for a ParameterStateString to directly create itself
from the string?
- Map<String, String[]> map = StateString.decodeOpaqueValue(new String(bytes,
ENCODING));
-
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+
String portletHandle;
byte[] portletState;
-
- String[] portletHandles = map.get(PORTLETHANDLEKEY);
- if (portletHandles != null && portletHandles.length > 0)
+
+ portletHandle = ois.readUTF();
+
+ if (ois.available() > 0)
{
- portletHandle = portletHandles[0];
+ portletState = new byte[ois.available()];
+ ois.readFully(portletState);
}
else
{
- return null; //TODO: should probably throw an error here about not getting a
proper value
- }
-
- String[] portletStates = map.get(PORTLETSTATEKEY);
- if (portletStates != null && portletStates.length > 0)
- {
- portletState = portletStates[0].getBytes(ENCODING);
- }
- else
- {
portletState = null;
}
+
+ ois.close();
return new ExportPortletData(portletHandle, portletState);
}
- protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingException
+ protected byte[] internalEncodeAsBytes() throws IOException
{
- ParametersStateString parameterStateString = ParametersStateString.create();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+ oos.writeUTF(portletHandle);
+
if (portletState != null)
{
- //TODO: if might be better to use something other than a statestring that can
handle byte[] directly
- String state = new String(portletState, ENCODING);
- parameterStateString.setValue(PORTLETSTATEKEY, state);
+ oos.write(portletState);
}
-
- parameterStateString.setValue(PORTLETHANDLEKEY, portletHandle);
- String stateString = parameterStateString.getStringValue();
- return stateString.getBytes(ENCODING);
+ oos.close();
+
+ return baos.toByteArray();
}
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java 2010-08-10
15:35:03 UTC (rev 3793)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java 2010-08-11
01:19:02 UTC (rev 3794)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.gatein.exports.impl;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.gatein.common.NotYetImplemented;
@@ -97,6 +98,10 @@
{
throw WSRPExceptionFactory.createWSException(OperationFailed.class, "Could
not decode the byte array.", e);
}
+ catch (IOException e)
+ {
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class, "Could
not decode the byte array.", e);
+ }
}
public ExportPortletData createExportPortletData(ExportContext exportContextData,
String portletHandle,
@@ -125,9 +130,13 @@
{
throw WSRPExceptionFactory.createWSException(OperationFailed.class, "Could
not decode the byte array.", e);
}
+ catch (IOException e)
+ {
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class, "Could
not decode the byte array.", e);
+ }
}
- public byte[] encodeExportPortletData(ExportContext exportContextData,
ExportPortletData exportPortletData) throws UnsupportedEncodingException
+ public byte[] encodeExportPortletData(ExportContext exportContextData,
ExportPortletData exportPortletData) throws IOException
{
if (exportContextData.isExportByValue())
{
@@ -139,7 +148,7 @@
}
}
- public byte[] encodeExportContextData(ExportContext exportContextData) throws
UnsupportedEncodingException
+ public byte[] encodeExportContextData(ExportContext exportContextData) throws
IOException
{
if (exportContextData.isExportByValue())
{
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java 2010-08-10
15:35:03 UTC (rev 3793)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java 2010-08-11
01:19:02 UTC (rev 3794)
@@ -524,7 +524,16 @@
if (portletHandle != null)
{
org.gatein.pc.api.PortletContext portalPC =
WSRPUtils.convertToPortalPortletContext(portletContext);
- if (producer.getPortletInvoker().getPortlet(portalPC) == null)
+
+ producer.getPortletInvoker().getPortlet(portalPC);
+
+ org.gatein.pc.api.PortletContext exportedPortalPC =
producer.getPortletInvoker().exportPortletContext(PortletStateType.OPAQUE, portalPC);
+
+ PortletContext exportedPortalContext =
WSRPUtils.convertToWSRPPortletContext(exportedPortalPC);
+ portletHandle = exportedPortalContext.getPortletHandle();
+ portletState = exportedPortalContext.getPortletState();
+
+ if (exportedPortalPC == null)
{
WSRP2ExceptionFactory.throwWSException(InvalidHandle.class,
"Could not find a portlet with handle " + portletHandle + " in the
producer", null);
}
@@ -642,7 +651,7 @@
PortletContext pc = WSRPTypeFactory.createPortletContext(portletHandle,
portletState);
org.gatein.pc.api.PortletContext pcPortletContext =
WSRPUtils.convertToPortalPortletContext(pc);
- org.gatein.pc.api.PortletContext cpc =
producer.getPortletInvoker().createClone(PortletStateType.OPAQUE, pcPortletContext);
+ org.gatein.pc.api.PortletContext cpc =
producer.getPortletInvoker().importPortletContext(PortletStateType.OPAQUE,
pcPortletContext);
PortletContext wpc = WSRPUtils.convertToWSRPPortletContext(cpc);
ImportedPortlet importedPortlet =
WSRPTypeFactory.createImportedPortlet(importPortlet.getImportID(), wpc);
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/export/ExportTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/export/ExportTestCase.java 2010-08-10
15:35:03 UTC (rev 3793)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/export/ExportTestCase.java 2010-08-11
01:19:02 UTC (rev 3794)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.gatein.export;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.gatein.exports.data.ExportData;
@@ -36,7 +37,7 @@
*/
public class ExportTestCase extends TestCase
{
- public void testTransformationByValueStateless() throws UnsupportedEncodingException
+ public void testTransformationByValueStateless() throws IOException
{
String portletId = "TestPortletID_123";
double version = 1.0;
@@ -48,8 +49,6 @@
byte[] bytes = exportPortletData.encodeAsBytes();
- String dataAsString = new String(bytes, "UTF-8");
-
byte[] internalBytes = ExportData.getInternalBytes(bytes);
ExportPortletData portletDataFromBytes = ExportPortletData.create(internalBytes);
assertEquals(version, portletDataFromBytes.getVersion());
@@ -59,11 +58,11 @@
assertNull(portletDataFromBytes.getPortletState());
}
- public void testTransformationByValueStatefull() throws UnsupportedEncodingException
+ public void testTransformationByValueStatefull() throws IOException
{
String portletId = "TestPortletID_123";
double version = 1.0;
- byte[] state = new byte[]{0, 1, 2, 3, 'a', 'b', 'c'};
+ byte[] state = new byte[]{-66, 0, 1, 2, 3, 'a', 'b', 'c'};
ExportPortletData exportPortletData = new ExportPortletData(portletId, state);
assertEquals(version, exportPortletData.getVersion());
@@ -73,18 +72,17 @@
byte[] bytes = exportPortletData.encodeAsBytes();
- String dataAsString = new String(bytes, "UTF-8");
-
byte[] internalBytes = ExportData.getInternalBytes(bytes);
ExportPortletData portletDataFromBytes = ExportPortletData.create(internalBytes);
assertEquals(version, portletDataFromBytes.getVersion());
assertEquals(portletId, portletDataFromBytes.getPortletHandle());
assertEquals(version, portletDataFromBytes.getVersion());
+ assertNotNull(portletDataFromBytes.getPortletState());
+ assertEquals(state.length, portletDataFromBytes.getPortletState().length);
ExtendedAssert.assertEquals(state, portletDataFromBytes.getPortletState());
}
-
/**
* ADD MORE TESTS
* - decode from a stored byte array
Modified: components/wsrp/trunk/wsrp-producer-war/pom.xml
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/pom.xml 2010-08-10 15:35:03 UTC (rev 3793)
+++ components/wsrp/trunk/wsrp-producer-war/pom.xml 2010-08-11 01:19:02 UTC (rev 3794)
@@ -175,6 +175,7 @@
<descriptor>src/test/assembly/test-resource-portlet.xml</descriptor>
<descriptor>src/test/assembly/test-resourcenoencodeurl-portlet.xml</descriptor>
<descriptor>src/test/assembly/test-applicationscope-portlet.xml</descriptor>
+
<descriptor>src/test/assembly/test-portletstate-portlet.xml</descriptor>
</descriptors>
</configuration>
<executions>
Added:
components/wsrp/trunk/wsrp-producer-war/src/test/assembly/test-portletstate-portlet.xml
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/assembly/test-portletstate-portlet.xml
(rev 0)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/assembly/test-portletstate-portlet.xml 2010-08-11
01:19:02 UTC (rev 3794)
@@ -0,0 +1,25 @@
+<assembly>
+ <id>portletstate-portlet</id>
+ <formats>
+ <format>war</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <fileSets>
+ <!-- Test Classes -->
+ <fileSet>
+ <directory>target/test-classes</directory>
+ <outputDirectory>WEB-INF/classes</outputDirectory>
+ <includes>
+ <include>org/gatein/wsrp/portlet/StatePortlet.class</include>
+ </includes>
+ </fileSet>
+ <!-- Fileset for the sar strucuture -->
+ <fileSet>
+
<directory>src/test/test-portlets/test-portletstate-portlet-war</directory>
+ <outputDirectory></outputDirectory>
+ </fileSet>
+ </fileSets>
+
+</assembly>
+
Added:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java
(rev 0)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java 2010-08-11
01:19:02 UTC (rev 3794)
@@ -0,0 +1,91 @@
+/******************************************************************************
+ * 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.portlet;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletSecurityException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class StatePortlet extends GenericPortlet
+{
+ private static final String COUNT = "count";
+
+ public void processAction(ActionRequest request, ActionResponse response) throws
PortletException, PortletSecurityException, IOException
+ {
+ System.out.println("PROCESSACTION");
+ String value = request.getParameter("value");
+ if (value == null)
+ {
+ value = "default";
+ }
+
+ PortletPreferences pp = request.getPreferences();
+ pp.setValue("name", value);
+ pp.store();
+ }
+
+ protected void doView(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
+ {
+ System.out.println("DOVIEW");
+ resp.setContentType("text/html");
+ PortletPreferences pp = req.getPreferences();
+ String value = pp.getValue("name", "default");
+ resp.getWriter().write(value);
+ }
+
+
+// protected void doView(RenderRequest req, RenderResponse resp) throws
PortletException, PortletSecurityException, IOException
+// {
+// resp.setContentType("text/html");
+// PrintWriter writer = resp.getWriter();
+//
+// PortletPreferences pp = req.getPreferences();
+// int count = 0;
+//
+// if (!pp.getValue(COUNT, "0").equals("0"))
+// {
+// count = Integer.parseInt(pp.getValue(COUNT, "0")) + 1;
+// }
+//
+// pp.setValue(COUNT, "" + count);
+// pp.store();
+//
+// writer.write("<p>count = " + count + "</p>");
+//
+// //
+// writer.close();
+// }
+}
+
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-10
15:35:03 UTC (rev 3793)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-11
01:19:02 UTC (rev 3794)
@@ -22,17 +22,30 @@
******************************************************************************/
package org.gatein.wsrp.protocol.v2;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.rmi.RemoteException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.gatein.exports.ExportManager;
import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportData;
import org.gatein.exports.data.ExportPortletData;
import org.gatein.exports.impl.ExportManagerImpl;
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletStateType;
+import org.gatein.pc.api.state.PropertyMap;
+import org.gatein.pc.portlet.state.SimplePropertyMap;
+import org.gatein.pc.portlet.state.producer.PortletState;
+import org.gatein.pc.portlet.state.producer.ProducerPortletInvoker;
import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.producer.WSRPProducerBaseTest;
import org.gatein.wsrp.servlet.ServletAccess;
+import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
import org.gatein.wsrp.test.ExtendedAssert;
import org.gatein.wsrp.test.support.MockHttpServletRequest;
import org.gatein.wsrp.test.support.MockHttpServletResponse;
@@ -44,6 +57,8 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.oasis.wsrp.v2.AccessDenied;
+import org.oasis.wsrp.v2.BlockingInteractionResponse;
import org.oasis.wsrp.v2.ExportPortlets;
import org.oasis.wsrp.v2.ExportPortletsResponse;
import org.oasis.wsrp.v2.ExportedPortlet;
@@ -53,14 +68,30 @@
import org.oasis.wsrp.v2.ImportPortlets;
import org.oasis.wsrp.v2.ImportPortletsResponse;
import org.oasis.wsrp.v2.ImportedPortlet;
+import org.oasis.wsrp.v2.InconsistentParameters;
+import org.oasis.wsrp.v2.InvalidCookie;
+import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.InvalidSession;
+import org.oasis.wsrp.v2.InvalidUserCategory;
import org.oasis.wsrp.v2.Lifetime;
+import org.oasis.wsrp.v2.MarkupContext;
+import org.oasis.wsrp.v2.MarkupParams;
import org.oasis.wsrp.v2.MarkupResponse;
import org.oasis.wsrp.v2.MissingParameters;
+import org.oasis.wsrp.v2.ModifyRegistrationRequired;
+import org.oasis.wsrp.v2.NamedString;
import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PerformBlockingInteraction;
import org.oasis.wsrp.v2.PortletContext;
import org.oasis.wsrp.v2.RegistrationContext;
import org.oasis.wsrp.v2.RegistrationData;
+import org.oasis.wsrp.v2.ResourceSuspended;
+import org.oasis.wsrp.v2.StateChange;
+import org.oasis.wsrp.v2.UnsupportedLocale;
+import org.oasis.wsrp.v2.UnsupportedMimeType;
+import org.oasis.wsrp.v2.UnsupportedMode;
+import org.oasis.wsrp.v2.UnsupportedWindowState;
import org.oasis.wsrp.v2.UserContext;
/**
@@ -71,7 +102,6 @@
public class PortletManagementTestCase extends NeedPortletHandleTest
{
private static final String TEST_BASIC_PORTLET_WAR =
"test-markup-portlet.war";
-
public PortletManagementTestCase() throws Exception
{
@@ -111,7 +141,6 @@
/*TODO:
* - tests usercontexts (not sure exactly what needs to be tested for this)
- * - test portlet states
*/
@Test
@@ -220,7 +249,7 @@
try
{
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- ExtendedAssert.fail("ImportPortlets should fail if registration is required
and non is provided");
+ ExtendedAssert.fail("ExportPortlets should fail if registration is required
and none is provided");
}
catch (InvalidRegistration e)
{
@@ -229,6 +258,32 @@
}
@Test
+ public void testExportBadRegistrationHandle() throws Exception
+ {
+
producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+
+ RegistrationContext registrationContext =
WSRPTypeFactory.createRegistrationContext("foo123");
+
+ List<PortletContext> portletContexts =
createPortletContextList(getDefaultHandle());
+
+ boolean exportByValueRequired = true;
+ Lifetime lifetime = null;
+ UserContext userContext = null;
+
+ ExportPortlets exportPortlets =
WSRPTypeFactory.createExportPortlets(registrationContext, portletContexts, userContext,
lifetime, exportByValueRequired);
+
+ try
+ {
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+ ExtendedAssert.fail("ExportPortlets should fail if registration is required
and an invalid registration handle is provided");
+ }
+ catch (InvalidRegistration e)
+ {
+ //expected
+ }
+ }
+
+ @Test
public void testExportRegistrationRequired() throws Exception
{
producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
@@ -335,9 +390,7 @@
assertEquals(importID, portlet.getImportID());
PortletContext portletContext = portlet.getNewPortletContext();
- //check that we are getting a new portlet handle back and not the original one
- ExtendedAssert.assertNotSame(getDefaultHandle(),
portletContext.getPortletHandle());
-
+
//check that the new portlet handle is valid and we can access the portlet
GetMarkup markup = createMarkupRequest(portletContext.getPortletHandle());
MarkupResponse markupResponse = producer.getMarkup(markup);
@@ -400,8 +453,6 @@
assertEquals(importID, portlet.getImportID());
PortletContext portletContext = portlet.getNewPortletContext();
- //check that we are getting a new portlet handle back and not the original one
- ExtendedAssert.assertNotSame(getDefaultHandle(),
portletContext.getPortletHandle());
//check that the new portlet handle is valid and we can access the portlet
GetMarkup markup = createMarkupRequest(portletContext.getPortletHandle());
@@ -413,6 +464,38 @@
}
@Test
+ public void testImportBadRegistration() throws Exception
+ {
+
producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+
+ RegistrationContext registrationContext =
WSRPTypeFactory.createRegistrationContext("FAkeREgistrationHAndle");
+
+ String importID = "foo";
+
+ Lifetime lifetime = null;
+ UserContext userContext = null;
+
+ List<String> portletList = new ArrayList<String>();
+ portletList.add(getDefaultHandle());
+ ExportContext exportContextData = new ExportContext();
+ byte[] importContext = exportContextData.encodeAsBytes();
+
+ ImportPortlet importPortlet = createSimpleImportPortlet(importID,
getDefaultHandle());
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+
+ ImportPortlets importPortlets =
WSRPTypeFactory.createImportPortlets(registrationContext, importContext,
importPortletsList, userContext, lifetime);
+ try
+ {
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+ ExtendedAssert.fail("Should have failed when registration is required and
an invalid registration handle is used.");
+ }
+ catch (InvalidRegistration e)
+ {
+ //expected
+ }
+ }
+
+ @Test
public void testImportNullImportContext() throws Exception
{
String importId = "importInvalidPortletContext";
@@ -581,8 +664,6 @@
assertEquals(importID, portlet.getImportID());
PortletContext portletContext = portlet.getNewPortletContext();
- //check that we are getting a new portlet handle back and not the original one
- ExtendedAssert.assertNotSame(getDefaultHandle(),
portletContext.getPortletHandle());
//check that the new portlet handle is valid and we can access the portlet
GetMarkup markup = createMarkupRequest(portletContext.getPortletHandle());
@@ -590,9 +671,208 @@
assertNotNull(markupResponse.getMarkupContext());
assertEquals("<p>symbol unset stock value: value unset</p>",
new String(markupResponse.getMarkupContext().getItemString()));
}
+
+ @Test
+ public void testExportWithState() throws Exception
+ {
+ undeploy(TEST_BASIC_PORTLET_WAR);
+ String sessionPortletArchive = "test-portletstate-portlet.war";
+ deploy(sessionPortletArchive);
+
+ try
+ {
+ String originalHandle = getHandleForCurrentlyDeployedArchive();
+
+ //check the session portlet to make sure its at the inital state
+ checkStatePortlet(originalHandle, "initial");
+
+ PortletContext portletContext =
performBlockingInteractionOnSessionPortlet(originalHandle, "new value",
StateChange.CLONE_BEFORE_WRITE);
+ //check that we have a new portlet context
+
ExtendedAssert.assertFalse(originalHandle.equals(portletContext.getPortletHandle()));
+
+ checkStatePortlet(portletContext.getPortletHandle(), "new value");
+
+ List<PortletContext> portletContexts =
createPortletContextList(portletContext.getPortletHandle());
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+
+ ExtendedAssert.assertFalse(response.getExportedPortlet().isEmpty());
+
+ List<PortletContext> portletContextsFromExport =
getPortletContext(response);
+
+ ExtendedAssert.assertNotNull(portletContextsFromExport.isEmpty());
+ ExtendedAssert.assertEquals(1,portletContexts.size());
+
+ PortletContext portletContextFromExport = portletContextsFromExport.get(0);
+ //we should be getting the handle of the stateless portlet
+ assertEquals(originalHandle, portletContextFromExport.getPortletHandle());
+ //assert that we have a portlet state returned
+ assertNotNull(portletContextFromExport.getPortletState());
+
+ //quick check that the imported portlet has the right state
+ ImportPortletsResponse importResponse =
createImportPortletsResponse("foo", portletContextFromExport);
+
checkStatePortlet(importResponse.getImportedPortlets().get(0).getNewPortletContext().getPortletHandle(),
"new value");
+
+ }
+ finally
+ {
+ undeploy(sessionPortletArchive);
+ }
+ }
- protected ImportPortlet createSimpleImportPortlet(String importId, String handle)
throws UnsupportedEncodingException
+ //Tests the situation in which we have a stateful export from one server and importing
into another
+ @Test
+ public void testImportWithState() throws Exception
{
+ undeploy(TEST_BASIC_PORTLET_WAR);
+ String sessionPortletArchive = "test-portletstate-portlet.war";
+ deploy(sessionPortletArchive);
+
+ try
+ {
+ String importStringValue = "import value";
+ byte[] portletState =
createSessionByteValue(getHandleForCurrentlyDeployedArchive(), importStringValue);
+
+ String importID = "foo";
+
+ List<String> portletList = new ArrayList<String>();
+ portletList.add(getDefaultHandle());
+ byte[] importContext = new ExportContext().encodeAsBytes();
+
+ ExportPortletData exportPortletData = new
ExportPortletData(getHandleForCurrentlyDeployedArchive(), portletState);
+ byte[] exportData = exportPortletData.encodeAsBytes();
+ ImportPortlet importPortlet = WSRPTypeFactory.createImportPortlet(importID,
exportData);
+
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+
+ ImportPortlets importPortlets = createSimpleImportPortlets(importContext,
importPortletsList);
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+
+ ImportedPortlet importedPortlet = response.getImportedPortlets().get(0);
+
+ //since its a stateful, the portlet handles shouldn't be the same
+ assertNotSame(getHandleForCurrentlyDeployedArchive(),
importedPortlet.getNewPortletContext().getPortletHandle());
+ //the pc should be storing the state, so it shouldn't appear in the imported
portlet context
+ assertNull(importedPortlet.getNewPortletContext().getPortletState());
+
+ checkStatePortlet(importedPortlet.getNewPortletContext().getPortletHandle(),
importStringValue);
+
+ }
+ finally
+ {
+ undeploy(sessionPortletArchive);
+ }
+ }
+
+ protected ImportPortletsResponse createImportPortletsResponse(String importID,
PortletContext portletContext) throws Exception
+ {
+ byte[] importContext = new ExportContext().encodeAsBytes();
+ ExportPortletData exportPortletData = new
ExportPortletData(portletContext.getPortletHandle(), portletContext.getPortletState());
+ byte[] exportData = exportPortletData.encodeAsBytes();
+ ImportPortlet importPortlet = WSRPTypeFactory.createImportPortlet(importID,
exportData);
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+ ImportPortlets importPortlets = createSimpleImportPortlets(importContext,
importPortletsList);
+ return producer.importPortlets(importPortlets);
+ }
+
+ protected byte[] createSessionByteValue(String portletHandle, String value) throws
Exception
+ {
+ ProducerPortletInvoker ppinvoker = (ProducerPortletInvoker)
producer.getPortletInvoker();
+ Map<String, List<String>> properties = new HashMap<String,
List<String>>();
+ List<String> values = new ArrayList<String>();
+ values.add(value);
+ properties.put("name", values);
+
+ PropertyMap property = new SimplePropertyMap(properties);
+ PortletState sstate = new PortletState(portletHandle, property);
+ return ppinvoker.getStateConverter().marshall(PortletStateType.OPAQUE, sstate);
+ }
+
+ @Test
+ public void testExportWithoutSession() throws Exception
+ {
+ undeploy(TEST_BASIC_PORTLET_WAR);
+ String sessionPortletArchive = "test-portletstate-portlet.war";
+ deploy(sessionPortletArchive);
+
+ try
+ {
+ String originalHandle = getHandleForCurrentlyDeployedArchive();
+
+ //check the session portlet to make sure its at the inital state
+ checkStatePortlet(originalHandle, "initial");
+
+ //export the cloned portlet context we get from the performBlockingInteraction
+ List<PortletContext> portletContexts =
createPortletContextList(originalHandle);
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+
+ ExtendedAssert.assertFalse(response.getExportedPortlet().isEmpty());
+
+ List<PortletContext> portletContextsFromExport =
getPortletContext(response);
+
+ ExtendedAssert.assertNotNull(portletContextsFromExport.isEmpty());
+ ExtendedAssert.assertEquals(1,portletContexts.size());
+
+ PortletContext portletContextFromExport = portletContextsFromExport.get(0);
+ assertEquals(originalHandle, portletContextFromExport.getPortletHandle());
+ assertNull(portletContextFromExport.getPortletState());
+ }
+ finally
+ {
+ undeploy(sessionPortletArchive);
+ }
+ }
+
+ protected List<PortletContext> getPortletContext(ExportPortletsResponse
exportPortletsResponse) throws Exception
+ {
+ List<PortletContext> portletContexts = new
ArrayList<PortletContext>();
+
+ ExportManager exportManager = new ExportManagerImpl();
+ ExportContext exportContext =
exportManager.createExportContext(exportPortletsResponse.getExportContext());
+
+ List<ExportedPortlet> exportedPortlets =
exportPortletsResponse.getExportedPortlet();
+
+ for (ExportedPortlet exportPortlet : exportedPortlets)
+ {
+ ExportPortletData exportPortletData =
exportManager.createExportPortletData(exportContext, exportPortletsResponse.getLifetime(),
exportPortlet.getExportData());
+ String portletHandle = exportPortletData.getPortletHandle();
+ byte[] portletState = exportPortletData.getPortletState();
+ portletContexts.add(WSRPTypeFactory.createPortletContext(portletHandle,
portletState));
+ }
+
+ return portletContexts;
+ }
+
+ protected void checkStatePortlet(String handle, String expectedValue) throws
Exception
+ {
+ GetMarkup getMarkupOriginalStateless = createMarkupRequest(handle);
+ MarkupResponse responseOriginalStateless =
producer.getMarkup(getMarkupOriginalStateless);
+ ExtendedAssert.assertEquals(expectedValue,
responseOriginalStateless.getMarkupContext().getItemString());
+ }
+
+ protected PortletContext performBlockingInteractionOnSessionPortlet(String handle,
String value, StateChange stateChange) throws Exception
+ {
+ //perform a blocking interaction to set a state on the portlet;
+ PerformBlockingInteraction pbi =
WSRPTypeFactory.createDefaultPerformBlockingInteraction(handle);
+ pbi.getInteractionParams().setPortletStateChange(stateChange);
+
pbi.getInteractionParams().getFormParameters().add(createNamedString("value",
value));
+ BlockingInteractionResponse response = producer.performBlockingInteraction(pbi);
+ PortletContext portletContext = response.getUpdateResponse().getPortletContext();
+
+ return portletContext;
+ }
+
+ private NamedString createNamedString(String name, String value)
+ {
+ NamedString namedString = new NamedString();
+ namedString.setName(name);
+ namedString.setValue(value);
+ return namedString;
+ }
+
+ protected ImportPortlet createSimpleImportPortlet(String importId, String handle)
throws IOException
+ {
ExportPortletData exportPortletData = new ExportPortletData(handle, null);
byte[] exportData = exportPortletData.encodeAsBytes();
return WSRPTypeFactory.createImportPortlet(importId, exportData);
@@ -618,7 +898,6 @@
return WSRPTypeFactory.createImportPortlets(registrationContext, importContext,
importPortletsList, userContext, lifetime);
}
- @Override
protected String getMostUsedPortletWARFileName()
{
return TEST_BASIC_PORTLET_WAR;