Author: mwringe
Date: 2010-08-05 10:53:28 -0400 (Thu, 05 Aug 2010)
New Revision: 3760
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/
components/wsrp/trunk/producer/src/test/java/org/gatein/export/
components/wsrp/trunk/producer/src/test/java/org/gatein/export/ExportTestCase.java
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/PortletManagementTestCase.java
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v2/ErrorCodes.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementInterface.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java
components/wsrp/trunk/wsrp-producer-war/pom.xml
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v2/PortletManagementEndpoint.java
components/wsrp/trunk/wsrp-producer-war/src/test/producer-sar/META-INF/jboss-beans.xml
Log:
GTNWSRP-55: Initial checkin of rough import/export implementation.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-08-05
13:14:29 UTC (rev 3759)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -50,6 +50,9 @@
import org.oasis.wsrp.v2.EventDescription;
import org.oasis.wsrp.v2.EventParams;
import org.oasis.wsrp.v2.EventPayload;
+import org.oasis.wsrp.v2.ExportPortlets;
+import org.oasis.wsrp.v2.ExportPortletsResponse;
+import org.oasis.wsrp.v2.ExportedPortlet;
import org.oasis.wsrp.v2.FailedPortlets;
import org.oasis.wsrp.v2.GetMarkup;
import org.oasis.wsrp.v2.GetPortletDescription;
@@ -59,8 +62,14 @@
import org.oasis.wsrp.v2.GetServiceDescription;
import org.oasis.wsrp.v2.HandleEvents;
import org.oasis.wsrp.v2.HandleEventsResponse;
+import org.oasis.wsrp.v2.ImportPortlet;
+import org.oasis.wsrp.v2.ImportPortlets;
+import org.oasis.wsrp.v2.ImportPortletsFailed;
+import org.oasis.wsrp.v2.ImportPortletsResponse;
+import org.oasis.wsrp.v2.ImportedPortlet;
import org.oasis.wsrp.v2.InitCookie;
import org.oasis.wsrp.v2.InteractionParams;
+import org.oasis.wsrp.v2.Lifetime;
import org.oasis.wsrp.v2.LocalizedString;
import org.oasis.wsrp.v2.MarkupContext;
import org.oasis.wsrp.v2.MarkupParams;
@@ -82,14 +91,17 @@
import org.oasis.wsrp.v2.PropertyList;
import org.oasis.wsrp.v2.RegistrationContext;
import org.oasis.wsrp.v2.RegistrationData;
+import org.oasis.wsrp.v2.ReleaseExport;
import org.oasis.wsrp.v2.ReleaseSessions;
import org.oasis.wsrp.v2.ResetProperty;
import org.oasis.wsrp.v2.ResourceContext;
+import org.oasis.wsrp.v2.ResourceList;
import org.oasis.wsrp.v2.ResourceParams;
import org.oasis.wsrp.v2.ResourceResponse;
import org.oasis.wsrp.v2.RuntimeContext;
import org.oasis.wsrp.v2.ServiceDescription;
import org.oasis.wsrp.v2.SessionContext;
+import org.oasis.wsrp.v2.SetExportLifetime;
import org.oasis.wsrp.v2.SetPortletProperties;
import org.oasis.wsrp.v2.StateChange;
import org.oasis.wsrp.v2.Templates;
@@ -1194,19 +1206,19 @@
* @param reason
* @return
*/
- public static FailedPortlets createFailedPortlets(Collection<String>
portletHandles, String reason)
+ public static FailedPortlets createFailedPortlets(Collection<String>
portletHandles, ErrorCodes.Codes errorCode, String reason)
{
+ //TODO: reason should be a LocalizedString
+ ParameterValidation.throwIllegalArgExceptionIfNull(errorCode,
"ErrorCode");
if (ParameterValidation.existsAndIsNotEmpty(portletHandles))
{
- //TODO: reason should be able to be null
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(reason, "Reason
for failure", "createFailedPortlets");
FailedPortlets failedPortlets = new FailedPortlets();
failedPortlets.getPortletHandles().addAll(portletHandles);
if (reason != null)
{
failedPortlets.setReason(createLocalizedString(reason));
}
- failedPortlets.setErrorCode(ErrorCodes.OperationFailed);
+ failedPortlets.setErrorCode(ErrorCodes.getQname(errorCode));
return failedPortlets;
}
@@ -1364,4 +1376,147 @@
result.setNamedStringArray(value);
return result;
}
+
+ public static ExportPortlets createExportPortlets(RegistrationContext
registrationContext, List<PortletContext> portletContexts, UserContext userContext,
Lifetime lifetime, Boolean exportByValue)
+ {
+ if (!ParameterValidation.existsAndIsNotEmpty(portletContexts))
+ {
+ throw new IllegalArgumentException("Must provide at least one
PortletContext to ExportPortlets.");
+ }
+
+ ExportPortlets exportPortlets = new ExportPortlets();
+ exportPortlets.setRegistrationContext(registrationContext);
+ exportPortlets.getPortletContext().addAll(portletContexts);
+ exportPortlets.setUserContext(userContext);
+ exportPortlets.setLifetime(lifetime);
+ exportPortlets.setExportByValueRequired(exportByValue);
+
+ return exportPortlets;
+ }
+
+ public static ExportPortletsResponse createExportPortletsResponse(byte[]
exportContext, List<ExportedPortlet> exportedPortlets, List<FailedPortlets>
failedPortlets, Lifetime lifetime, ResourceList resourceList)
+ {
+ // everything can be empty or nillable, there is no need to check for null values
+ ExportPortletsResponse response = new ExportPortletsResponse();
+ response.setExportContext(exportContext);
+ response.getExportedPortlet().addAll(exportedPortlets);
+ response.getFailedPortlets().addAll(failedPortlets);
+ response.setLifetime(lifetime);
+ response.setResourceList(resourceList);
+
+ return response;
+ }
+
+ public static ExportedPortlet createExportedPortlet(String portletHandle, byte[]
exportData)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletHandle,
"PortletHandle");
+
+ ExportedPortlet exportedPortlet = new ExportedPortlet();
+ exportedPortlet.setPortletHandle(portletHandle);
+ exportedPortlet.setExportData(exportData);
+
+ return exportedPortlet;
+ }
+
+ public static ImportPortlets createImportPortlets(RegistrationContext
registrationContext, byte[] importContext, List<ImportPortlet> importPortlet,
UserContext userContext, Lifetime lifetime)
+ {
+ if (!ParameterValidation.existsAndIsNotEmpty(importPortlet))
+ {
+ throw new IllegalArgumentException("Must provide at least one ImportPortlet
to ImportPortlets.");
+ }
+
+ ImportPortlets importPortlets = new ImportPortlets();
+ importPortlets.setRegistrationContext(registrationContext);
+ importPortlets.setImportContext(importContext);
+ importPortlets.getImportPortlet().addAll(importPortlet);
+ importPortlets.setUserContext(userContext);
+ importPortlets.setLifetime(lifetime);
+
+ return importPortlets;
+ }
+
+ public static ImportPortlet createImportPorlet(String importID, byte[] exportData)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(importID,
"ImportID");
+ ParameterValidation.throwIllegalArgExceptionIfNull(exportData,
"ExportData");
+
+ ImportPortlet importPortlet = new ImportPortlet();
+ importPortlet.setImportID(importID);
+ importPortlet.setExportData(exportData);
+ return importPortlet;
+ }
+
+ public static ImportPortletsResponse createImportPortletsResponse
(List<ImportedPortlet> importedPortlets, List<ImportPortletsFailed>
importPortletsFailed, ResourceList resourceList)
+ {
+ // everything can be empty or nillable, no need to check for null values
+ ImportPortletsResponse response = new ImportPortletsResponse();
+ response.getImportedPortlets().addAll(importedPortlets);
+ response.getImportFailed().addAll(importPortletsFailed);
+ response.setResourceList(resourceList);
+
+ return response;
+ }
+
+ public static ImportPortletsFailed createImportPortletsFailed(List<String>
importIds, ErrorCodes.Codes errorCode, String reason)
+ {
+ //TODO: reason should be a LocalizedString
+ ParameterValidation.throwIllegalArgExceptionIfNull(errorCode,
"ErrorCode");
+ if (ParameterValidation.existsAndIsNotEmpty(importIds))
+ {
+ ImportPortletsFailed failedPortlets = new ImportPortletsFailed();
+ failedPortlets.getImportID().addAll(importIds);
+ if (reason != null)
+ {
+ failedPortlets.setReason(createLocalizedString(reason));
+ }
+ failedPortlets.setErrorCode(ErrorCodes.getQname(errorCode));
+
+ return failedPortlets;
+ }
+
+ throw new IllegalArgumentException("Must provide non-null, non-empty portlet
handle list.");
+ }
+
+ public static ImportedPortlet createImportedPortlet(String portletID, PortletContext
portletContext)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletID,
"PortletID");
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletContext,
"PortletContext");
+
+ ImportedPortlet importedPortlet = new ImportedPortlet();
+ importedPortlet.setImportID(portletID);
+ importedPortlet.setNewPortletContext(portletContext);
+
+ return importedPortlet;
+ }
+
+ public static ReleaseExport createReleaseExport(RegistrationContext
registrationContext, byte[] exportContext, UserContext userContext)
+ {
+ if (exportContext == null || exportContext.length == 0)
+ {
+ throw new IllegalArgumentException("Must provide a non null or empty
exportContext to ReleaseExport.");
+ }
+
+ ReleaseExport releaseExport = new ReleaseExport();
+ releaseExport.setRegistrationContext(registrationContext);
+ releaseExport.setExportContext(exportContext);
+ releaseExport.setUserContext(userContext);
+
+ return releaseExport;
+ }
+
+ public static SetExportLifetime createSetExportLifetime(RegistrationContext
registrationContext, byte[] exportContext, UserContext userContext, Lifetime lifetime)
+ {
+ if (exportContext == null || exportContext.length == 0)
+ {
+ throw new IllegalArgumentException("Must provide a non null or empty
exportContext to SetExportLifetime.");
+ }
+
+ SetExportLifetime setExportLifetime = new SetExportLifetime();
+ setExportLifetime.setRegistrationContext(registrationContext);
+ setExportLifetime.setExportContext(exportContext);
+ setExportLifetime.setUserContext(userContext);
+ setExportLifetime.setLifetime(lifetime);
+
+ return setExportLifetime;
+ }
}
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java 2010-08-05
13:14:29 UTC (rev 3759)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V1ToV2Converter.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -31,6 +31,7 @@
import org.gatein.wsrp.WSRPExceptionFactory;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.spec.v2.ErrorCodes;
import org.oasis.wsrp.v1.V1CacheControl;
import org.oasis.wsrp.v1.V1ClientData;
import org.oasis.wsrp.v1.V1ClonePortlet;
@@ -710,7 +711,7 @@
List<FailedPortlets> result = new
ArrayList<FailedPortlets>(destroyFailed.size());
for (V1DestroyFailed failed : destroyFailed)
{
-
result.add(WSRPTypeFactory.createFailedPortlets(Collections.singletonList(failed.getPortletHandle()),
failed.getReason()));
+
result.add(WSRPTypeFactory.createFailedPortlets(Collections.singletonList(failed.getPortletHandle()),
ErrorCodes.Codes.OPERATIONFAILED, failed.getReason()));
}
return result;
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v2/ErrorCodes.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v2/ErrorCodes.java 2010-08-05
13:14:29 UTC (rev 3759)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v2/ErrorCodes.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -47,4 +47,35 @@
public static final QName ResourceSuspended = new QName(WSRP2_TYPES_NS,
"ResourceSuspended");
public static final QName TooBusy = new QName(WSRP2_TYPES_NS, "TooBusy");
public static final QName TooManyRequests = new QName(WSRP2_TYPES_NS,
"TooManyRequests");
+
+ public static enum Codes
+ {
+ ACCESSDENIED, EXPORTNOLONGERVALID, INCONSISTENTPARAMETERS, INVALIDREGISTRATION,
INVALIDCOOKIE, INVALIDHANDLE, INVALIDSESSION,
+ INVALIDUSERCATEGORY, MODIFYREGISTRATIONREQUIRED, MISSINGPARAMETERS,
OPERATIONFAILED, OPERATIONNOTSUPPORTED, RESOURCESUSPENDED,
+ TOOBUSY, TOOMANYREQUESTS
+ }
+
+ public static QName getQname(Codes code)
+ {
+ switch(code)
+ {
+ case ACCESSDENIED: return AccessDenied;
+ case EXPORTNOLONGERVALID: return ExportNoLongerValid;
+ case INCONSISTENTPARAMETERS: return InconsistentParameters;
+ case INVALIDREGISTRATION: return InvalidRegistration;
+ case INVALIDCOOKIE: return InvalidCookie;
+ case INVALIDHANDLE: return InvalidHandle;
+ case INVALIDSESSION: return InvalidSession;
+ case INVALIDUSERCATEGORY: return InvalidUserCategory;
+ case MODIFYREGISTRATIONREQUIRED: return ModifyRegistrationRequired;
+ case MISSINGPARAMETERS: return MissingParameters;
+ case OPERATIONFAILED: return OperationFailed;
+ case OPERATIONNOTSUPPORTED: return OperationNotSupported;
+ case RESOURCESUSPENDED: return ResourceSuspended;
+ case TOOBUSY: return TooBusy;
+ case TOOMANYREQUESTS: return TooManyRequests;
+
+ default: return OperationFailed;
+ }
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java 2010-08-05
13:14:29 UTC (rev 3759)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -25,6 +25,7 @@
import org.gatein.common.NotYetImplemented;
import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.spec.v2.ErrorCodes;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.gatein.wsrp.test.protocol.v2.BehaviorRegistry;
import org.gatein.wsrp.test.protocol.v2.MarkupBehavior;
@@ -148,7 +149,7 @@
{
ArrayList<String> failed = new ArrayList<String>();
failed.add(handle);
- failedPortlets.value.add(WSRPTypeFactory.createFailedPortlets(failed,
"Handle '" + handle + "' doesn't exist"));
+ failedPortlets.value.add(WSRPTypeFactory.createFailedPortlets(failed,
ErrorCodes.Codes.OPERATIONFAILED, "Handle '" + handle + "'
doesn't exist"));
}
}
}
Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * 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.exports;
+
+import java.io.UnsupportedEncodingException;
+
+import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportPortletData;
+import org.oasis.wsrp.v2.Lifetime;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationNotSupported;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public interface ExportManager
+{
+ void setPersistanceManager (ExportPersistenceManager exportPersistenceManager);
+
+ ExportPersistenceManager getPersistenceManager();
+
+ boolean supportExportByValue();
+
+ ExportContext createExportContext(boolean exportByValueRequired, Lifetime lifetime)
throws UnsupportedEncodingException;
+
+ ExportContext createExportContext(byte[] bytes);
+
+ ExportPortletData createExportPortletData(ExportContext exportContextData, String
portletHandle, byte[] portletState) throws UnsupportedEncodingException;
+
+ ExportPortletData createExportPortletData(ExportContext exportContext, Lifetime
lifetime, byte[] bytes);
+
+ byte[] encodeExportPortletData(ExportContext exportContextData, ExportPortletData
exportPortletData) throws UnsupportedEncodingException;
+
+ byte[] encodeExportContextData (ExportContext exportContextData) throws
UnsupportedEncodingException;
+
+ Lifetime setExportLifetime(ExportContext exportContext, Lifetime lifetime) throws
OperationFailed, OperationNotSupported;
+
+ void releaseExport(ExportContext exportContext);
+}
+
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * 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.exports;
+
+import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportPortletData;
+import org.oasis.wsrp.v2.Lifetime;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public interface ExportPersistenceManager
+{
+
+ String storeExportContextData(ExportContext exportContextData);
+
+ String storeExportPortletData(ExportPortletData exportPortletData);
+
+ ExportContext retrieveExportContextData(String refid);
+
+ ExportPortletData retrieveExportPortletData(String refid);
+
+ Lifetime updateExportLifetime(ExportContext exportContext, Lifetime lifetime);
+
+ void releaseExport(ExportContext exportContext);
+}
+
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-05
13:14:29 UTC (rev 3759)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -25,8 +25,11 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
+
import org.gatein.common.NotYetImplemented;
import org.gatein.common.i18n.LocalizedString;
+import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportPortletData;
import org.gatein.pc.api.InvalidPortletIdException;
import org.gatein.pc.api.NoSuchPortletException;
import org.gatein.pc.api.Portlet;
@@ -41,8 +44,10 @@
import org.gatein.registration.Registration;
import org.gatein.registration.RegistrationLocal;
import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPExceptionFactory;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.spec.v2.ErrorCodes;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.oasis.wsrp.v2.AccessDenied;
import org.oasis.wsrp.v2.ClonePortlet;
@@ -51,18 +56,22 @@
import org.oasis.wsrp.v2.DestroyPortlets;
import org.oasis.wsrp.v2.DestroyPortletsResponse;
import org.oasis.wsrp.v2.ExportByValueNotSupported;
-import org.oasis.wsrp.v2.ExportNoLongerValid;
import org.oasis.wsrp.v2.ExportPortlets;
import org.oasis.wsrp.v2.ExportPortletsResponse;
+import org.oasis.wsrp.v2.ExportedPortlet;
+import org.oasis.wsrp.v2.ExportNoLongerValid;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.FailedPortlets;
import org.oasis.wsrp.v2.GetPortletDescription;
import org.oasis.wsrp.v2.GetPortletProperties;
import org.oasis.wsrp.v2.GetPortletPropertyDescription;
+import org.oasis.wsrp.v2.ImportPortlet;
+import org.oasis.wsrp.v2.ImportPortlets;
+import org.oasis.wsrp.v2.ImportPortletsFailed;
+import org.oasis.wsrp.v2.ImportPortletsResponse;
+import org.oasis.wsrp.v2.ImportedPortlet;
import org.oasis.wsrp.v2.GetPortletsLifetime;
import org.oasis.wsrp.v2.GetPortletsLifetimeResponse;
-import org.oasis.wsrp.v2.ImportPortlets;
-import org.oasis.wsrp.v2.ImportPortletsResponse;
import org.oasis.wsrp.v2.InconsistentParameters;
import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.InvalidRegistration;
@@ -71,6 +80,7 @@
import org.oasis.wsrp.v2.MissingParameters;
import org.oasis.wsrp.v2.ModifyRegistrationRequired;
import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationFailedFault;
import org.oasis.wsrp.v2.OperationNotSupported;
import org.oasis.wsrp.v2.PortletContext;
import org.oasis.wsrp.v2.PortletDescription;
@@ -81,15 +91,19 @@
import org.oasis.wsrp.v2.PropertyList;
import org.oasis.wsrp.v2.ReleaseExport;
import org.oasis.wsrp.v2.ResetProperty;
+import org.oasis.wsrp.v2.ResourceList;
import org.oasis.wsrp.v2.ResourceSuspended;
+import org.oasis.wsrp.v2.ReturnAny;
import org.oasis.wsrp.v2.SetExportLifetime;
import org.oasis.wsrp.v2.SetPortletProperties;
import org.oasis.wsrp.v2.SetPortletsLifetime;
import org.oasis.wsrp.v2.SetPortletsLifetimeResponse;
import org.oasis.wsrp.v2.UserContext;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -251,7 +265,7 @@
failedPortlets = new
ArrayList<FailedPortlets>(reasonToHandles.size());
for (String reason : reasonToHandles.keys())
{
-
failedPortlets.add(WSRPTypeFactory.createFailedPortlets(reasonToHandles.get(reason),
reason));
+
failedPortlets.add(WSRPTypeFactory.createFailedPortlets(reasonToHandles.get(reason),ErrorCodes.Codes.OPERATIONFAILED,
reason));
}
}
else
@@ -292,33 +306,6 @@
throw new NotYetImplemented();
}
- public ExportPortletsResponse exportPortlets(ExportPortlets exportPortlets)
- throws AccessDenied, ExportByValueNotSupported, InconsistentParameters,
InvalidHandle, InvalidRegistration,
- InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, OperationNotSupported,
- ResourceSuspended
- {
- throw new NotYetImplemented();
- }
-
- public ImportPortletsResponse importPortlets(ImportPortlets importPortlets)
- throws AccessDenied, ExportNoLongerValid, InconsistentParameters,
InvalidRegistration, InvalidUserCategory,
- MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
- {
- throw new NotYetImplemented();
- }
-
- public List<Extension> releaseExport(ReleaseExport releaseExport)
- {
- throw new NotYetImplemented();
- }
-
- public Lifetime setExportLifetime(SetExportLifetime setExportLifetime)
- throws AccessDenied, InvalidHandle, InvalidRegistration,
ModifyRegistrationRequired, OperationFailed,
- OperationNotSupported, ResourceSuspended
- {
- throw new NotYetImplemented();
- }
-
public PortletContext setPortletProperties(SetPortletProperties setPortletProperties)
throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
@@ -478,6 +465,296 @@
}
}
+ public ExportPortletsResponse exportPortlets(ExportPortlets exportPortlets) throws
AccessDenied,
+ ExportByValueNotSupported, InconsistentParameters, InvalidHandle,
InvalidRegistration, InvalidUserCategory,
+ MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(exportPortlets,
"ExportPortlets");
+
+ List<PortletContext> portletContexts = exportPortlets.getPortletContext();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContexts,
"PortletContext", "ExportPortlets");
+
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(exportPortlets.getRegistrationContext());
+
+ UserContext userContext = exportPortlets.getUserContext();
+ checkUserAuthorization(userContext);
+
+ boolean exportByValueRequired = exportPortlets.isExportByValueRequired();
+
+ //check that the export manager can handle export by value
+ if (exportByValueRequired &&
!producer.getExportManager().supportExportByValue())
+ {
+ //TODO: instead of passing a string here, we should pass a resource so that its
localized
+ WSRP2ExceptionFactory.throwWSException(ExportByValueNotSupported.class,
"The consumer is requesting portlets to be exported by value, but this consumer only
supports export by reference.", null);
+ }
+
+
+ List<ExportedPortlet> exportedPortlets = new
ArrayList<ExportedPortlet>();
+ Map<String, FailedPortlets> failedPortletsMap = new HashMap<String,
FailedPortlets>();
+
+ try
+ {
+ RegistrationLocal.setRegistration(registration);
+
+ //TODO: try catch here?
+ ExportContext exportContext =
producer.getExportManager().createExportContext(exportPortlets.isExportByValueRequired(),
exportPortlets.getLifetime());
+
+ for (PortletContext portletContext : exportPortlets.getPortletContext())
+ {
+ try
+ {
+ byte[] exportData;
+
+ String portletHandle = portletContext.getPortletHandle();
+ byte[] portletState = portletContext.getPortletState();
+
+ if (portletHandle != null)
+ {
+ org.gatein.pc.api.PortletContext portalPC =
WSRPUtils.convertToPortalPortletContext(portletContext);
+ if (producer.getPortletInvoker().getPortlet(portalPC) == null)
+ {
+ WSRP2ExceptionFactory.throwWSException(InvalidHandle.class,
"Could not find a portlet with handle " + portletHandle + " in the
producer", null);
+ }
+ }
+ else
+ {
+ WSRP2ExceptionFactory.throwWSException(InvalidHandle.class, "A
portlet handle cannot be null.", null);
+ }
+
+ //get the exportPortletData
+ ExportPortletData exportPortletData =
producer.getExportManager().createExportPortletData(exportContext, portletHandle,
portletState);
+
+ //Create the exportedPortlet
+ ExportedPortlet exportedPortlet =
WSRPTypeFactory.createExportedPortlet(portletHandle, exportPortletData.encodeAsBytes());
+ exportedPortlets.add(exportedPortlet);
+ }
+
+ //TODO: this is very messy, make this better
+ catch (UnsupportedEncodingException e)
+ {
+ if(!failedPortletsMap.containsKey(e.getClass().toString()))
+ {
+ List<String> portletHandles = new ArrayList<String>();
+ portletHandles.add(portletContext.getPortletHandle());
+
+ FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, ErrorCodes.Codes.OPERATIONFAILED,
"Error encoding the portlet for export.");
+ failedPortletsMap.put(e.getClass().toString(), failedPortlets);
+ }
+ else
+ {
+ FailedPortlets failedPortlets =
failedPortletsMap.get(e.getClass().toString());
+
failedPortlets.getPortletHandles().add(portletContext.getPortletHandle());
+ }
+ }
+ catch (NoSuchPortletException e)
+ {
+ if(!failedPortletsMap.containsKey(e.getClass().toString()))
+ {
+ List<String> portletHandles = new ArrayList<String>();
+ portletHandles.add(portletContext.getPortletHandle());
+
+ FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, ErrorCodes.Codes.INVALIDHANDLE,
"The specified porlet handle is invalid.");
+ failedPortletsMap.put(e.getClass().toString(), failedPortlets);
+ }
+ else
+ {
+ FailedPortlets failedPortlets =
failedPortletsMap.get(e.getClass().toString());
+
failedPortlets.getPortletHandles().add(portletContext.getPortletHandle());
+ }
+ }
+ catch (InvalidHandle e)
+ {
+ if(!failedPortletsMap.containsKey(e.getClass().toString()))
+ {
+ List<String> portletHandles = new ArrayList<String>();
+ portletHandles.add(portletContext.getPortletHandle());
+
+ FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, ErrorCodes.Codes.INVALIDHANDLE,
"The specified portlet handle is invalid.");
+ failedPortletsMap.put(e.getClass().toString(), failedPortlets);
+ }
+ else
+ {
+ FailedPortlets failedPortlets =
failedPortletsMap.get(e.getClass().toString());
+
failedPortlets.getPortletHandles().add(portletContext.getPortletHandle());
+ }
+ }
+ catch (Exception e)
+ {
+ if(!failedPortletsMap.containsKey(e.getClass().toString()))
+ {
+ List<String> portletHandles = new ArrayList<String>();
+ portletHandles.add(portletContext.getPortletHandle());
+
+ FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, ErrorCodes.Codes.OPERATIONFAILED,
"An exception occured when trying to export this portlet for export.");
+ e.printStackTrace();
+ failedPortletsMap.put(e.getClass().toString(), failedPortlets);
+ }
+ else
+ {
+ FailedPortlets failedPortlets =
failedPortletsMap.get(e.getClass().toString());
+
failedPortlets.getPortletHandles().add(portletContext.getPortletHandle());
+ }
+ }
+ }
+
+
+
+ //TODO: handle resourceLists better (should be using for things like errors)
+ ResourceList resourceList = null;
+
+ return
WSRPTypeFactory.createExportPortletsResponse(exportContext.encodeAsBytes(),
exportedPortlets, new ArrayList<FailedPortlets>(failedPortletsMap.values()),
exportContext.getLifeTime(), resourceList);
+ }
+ catch (Exception e)//TODO ADD PROPER EXCEPTION HANDLING
+ {
+ e.printStackTrace();
+ throw new OperationFailed("TODO: add proper error handling", new
OperationFailedFault());
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+
+ public ImportPortletsResponse importPortlets(ImportPortlets importPortlets) throws
OperationFailed, InvalidRegistration, MissingParameters
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(importPortlets,
"ImportPortlets");
+
+ List<ImportPortlet> importPortletList = importPortlets.getImportPortlet();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(importPortletList,
"ImportPortlet", "ImportPortlets");
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(importPortlets.getRegistrationContext());
+
+ // check if we have a valid userContext or not
+ UserContext userContext = importPortlets.getUserContext();
+ checkUserAuthorization(userContext);
+
+ try
+ {
+ RegistrationLocal.setRegistration(registration);
+
+ byte[] importContext = importPortlets.getImportContext();
+
+ Lifetime lifeTime = importPortlets.getLifetime();
+
+ List<ImportedPortlet> importedPortlets = new
ArrayList<ImportedPortlet>();
+ Map<String, ImportPortletsFailed> failedPortletsMap = new
HashMap<String, ImportPortletsFailed>();
+
+ ExportContext exportContext =
producer.getExportManager().createExportContext(importContext);
+
+ for (ImportPortlet importPortlet : importPortletList)
+ {
+ try
+ {
+ byte[] portletData = importPortlet.getExportData();
+
+ ExportPortletData exportPortletData =
producer.getExportManager().createExportPortletData(exportContext, lifeTime,
portletData);
+
+ String portletHandle = exportPortletData.getPortletHandle();
+ byte[] portletState = exportPortletData.getPortletState();
+
+ 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);
+ PortletContext wpc = WSRPUtils.convertToWSRPPortletContext(cpc);
+
+ ImportedPortlet importedPortlet =
WSRPTypeFactory.createImportedPortlet(importPortlet.getImportID(), wpc);
+
+ importedPortlets.add(importedPortlet);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ if(!failedPortletsMap.containsKey(e.getClass().toString()))
+ {
+ List<String> importIds = new ArrayList<String>();
+ importIds.add(importPortlet.getImportID());
+
+ ImportPortletsFailed failedPortlets =
WSRPTypeFactory.createImportPortletsFailed(importIds, ErrorCodes.Codes.OPERATIONFAILED,
"The import portlet operation failed");
+
+ failedPortletsMap.put(e.getClass().toString(), failedPortlets);
+ }
+ else
+ {
+ ImportPortletsFailed failedPortlets =
failedPortletsMap.get(e.getClass().toString());
+ failedPortlets.getImportID().add(importPortlet.getImportID());
+ }
+ }
+ }
+
+ ResourceList resourceList = null; //TODO: figure out what exactly should be
stored in the resource list here
+
+ return WSRPTypeFactory.createImportPortletsResponse(importedPortlets, new
ArrayList<ImportPortletsFailed>(failedPortletsMap.values()), resourceList);
+ }
+ catch (Exception e)
+ {
+ //TODO: put proper error messages here
+ e.printStackTrace();
+ throw new NotYetImplemented();
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+
+ public List<Extension> releaseExport(ReleaseExport releaseExport)
+ {
+ try
+ {
+ if (releaseExport != null)
+ {
+ ExportContext exportContext =
producer.getExportManager().createExportContext(releaseExport.getExportContext());
+ producer.getExportManager().releaseExport(exportContext);
+ }
+ }
+ catch (Exception e)
+ {
+ //TODO: this method doesn't return anything, should we do more than just
output the stacktrace?
+ e.printStackTrace();
+ }
+
+ //this method shouldn't return anything
+ return new ReturnAny().getExtensions();
+ }
+
+ public Lifetime setExportLifetime(SetExportLifetime setExportLifetime) throws
OperationFailed, InvalidRegistration
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(setExportLifetime,
"setExportLifetimePortlets");
+
+ byte[] exportContextBytes = setExportLifetime.getExportContext();
+ //NOTE: we can't throw a MissingParameterException since its not allowed as
part of the spec
+ if (exportContextBytes == null)
+ {
+ WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot call
setExportLifetime with an empty ExportContext.", null);
+ }
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(setExportLifetime.getRegistrationContext());
+
+ // check if we have a valid userContext or not
+ UserContext userContext = setExportLifetime.getUserContext();
+ checkUserAuthorization(userContext);
+
+ try
+ {
+ RegistrationLocal.setRegistration(registration);
+
+ ExportContext exportContext =
producer.getExportManager().createExportContext(exportContextBytes);
+
+ return
producer.getExportManager().setExportLifetime(exportContext,setExportLifetime.getLifetime());
+
+ }
+ catch (Exception e)
+ {
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class,
"Operation Failed while trying to setExportLifetime.", e);
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+
private void checkUserAuthorization(UserContext userContext)
{
//todo: implement
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementInterface.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementInterface.java 2010-08-05
13:14:29 UTC (rev 3759)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementInterface.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -56,6 +56,7 @@
import org.oasis.wsrp.v2.PropertyList;
import org.oasis.wsrp.v2.ReleaseExport;
import org.oasis.wsrp.v2.ResourceSuspended;
+import org.oasis.wsrp.v2.ReturnAny;
import org.oasis.wsrp.v2.SetExportLifetime;
import org.oasis.wsrp.v2.SetPortletProperties;
import org.oasis.wsrp.v2.SetPortletsLifetime;
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-08-05
13:14:29 UTC (rev 3759)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -23,6 +23,7 @@
package org.gatein.wsrp.producer;
+import org.gatein.exports.ExportManager;
import org.gatein.pc.api.NoSuchPortletException;
import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.PortletInvoker;
@@ -46,6 +47,9 @@
import org.oasis.wsrp.v2.DestroyPortlets;
import org.oasis.wsrp.v2.DestroyPortletsResponse;
import org.oasis.wsrp.v2.ExportByValueNotSupported;
+import org.oasis.wsrp.v2.ExportPortlets;
+import org.oasis.wsrp.v2.ExportPortletsResponse;
+import org.oasis.wsrp.v2.ExportByValueNotSupported;
import org.oasis.wsrp.v2.ExportNoLongerValid;
import org.oasis.wsrp.v2.ExportPortlets;
import org.oasis.wsrp.v2.ExportPortletsResponse;
@@ -141,6 +145,9 @@
/** configuration service */
private ProducerConfigurationService configurationService; //todo: make sure it's
multi-thread safe
+ /** export manager */
+ private ExportManager exportManager;
+
private boolean started = false;
// On-demand class holder Singleton pattern (multi-thread safe)
@@ -346,6 +353,16 @@
return configurationService;
}
+ public void setExportManager(ExportManager exportManger)
+ {
+ this.exportManager = exportManger;
+ }
+
+ public ExportManager getExportManager()
+ {
+ return exportManager;
+ }
+
public synchronized void start()
{
if (!started)
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/export/ExportTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/export/ExportTestCase.java
(rev 0)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/export/ExportTestCase.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -0,0 +1,95 @@
+/******************************************************************************
+ * 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.export;
+
+import java.io.UnsupportedEncodingException;
+
+import org.gatein.exports.data.ExportData;
+import org.gatein.exports.data.ExportPortletData;
+import org.gatein.wsrp.test.ExtendedAssert;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class ExportTestCase extends TestCase
+{
+ public void testTransformationByValueStateless() throws UnsupportedEncodingException
+ {
+ String portletId = "TestPortletID_123";
+ double version = 1.0;
+
+ ExportPortletData exportPortletData = new ExportPortletData(portletId, null);
+ assertEquals(version, exportPortletData.getVersion());
+ assertEquals(portletId, exportPortletData.getPortletHandle());
+ assertNull(exportPortletData.getPortletState());
+
+ 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());
+ assertNull(portletDataFromBytes.getPortletState());
+ }
+
+ public void testTransformationByValueStatefull() throws UnsupportedEncodingException
+ {
+ String portletId = "TestPortletID_123";
+ double version = 1.0;
+ byte[] state = new byte[]{0, 1, 2, 3, 'a', 'b', 'c'};
+
+ ExportPortletData exportPortletData = new ExportPortletData(portletId, state);
+ assertEquals(version, exportPortletData.getVersion());
+ assertEquals(portletId, exportPortletData.getPortletHandle());
+ assertNotNull(exportPortletData.getPortletState());
+ ExtendedAssert.assertEquals(state, exportPortletData.getPortletState());
+
+ 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());
+ ExtendedAssert.assertEquals(state, portletDataFromBytes.getPortletState());
+ }
+
+
+ /**
+ * ADD MORE TESTS
+ * - decode from a stored byte array
+ * - test that encode returns an expected array
+ * - test that you get back the right version (the implementation doesn't do this
correctly yet...)
+ */
+}
+
Modified: components/wsrp/trunk/wsrp-producer-war/pom.xml
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/pom.xml 2010-08-05 13:14:29 UTC (rev 3759)
+++ components/wsrp/trunk/wsrp-producer-war/pom.xml 2010-08-05 14:53:28 UTC (rev 3760)
@@ -417,13 +417,14 @@
<configuration>
<skip>${maven.test.skip}</skip>
<includes>
-
<include>org/gatein/wsrp/protocol/v1/MarkupTestCase.class</include>
+
<include>org/gatein/wsrp/protocol/v1/MarkupTestCase.class</include>
<include>org/gatein/wsrp/protocol/v1/PortletManagementTestCase.class</include>
<include>org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.class</include>
<include>org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.class</include>
<include>org/gatein/wsrp/protocol/v1/RegistrationTestCase.class</include>
-
<!--<include>org/gatein/wsrp/protocol/v2/ResourceTestCase.class</include>-->
+ <!--
<include>org/gatein/wsrp/protocol/v2/ResourceTestCase.class</include> -->
<include>org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.class</include>
+
<include>org/gatein/wsrp/protocol/v2/PortletManagementTestCase.class</include>
</includes>
<excludes>
<exclude>org/gatein/wsrp/producer/**</exclude>
Modified:
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v2/PortletManagementEndpoint.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v2/PortletManagementEndpoint.java 2010-08-05
13:14:29 UTC (rev 3759)
+++
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v2/PortletManagementEndpoint.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -23,6 +23,7 @@
package org.gatein.wsrp.endpoints.v2;
+import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.endpoints.WSRPBaseEndpoint;
import org.oasis.wsrp.v2.AccessDenied;
import org.oasis.wsrp.v2.ClonePortlet;
@@ -31,6 +32,8 @@
import org.oasis.wsrp.v2.DestroyPortletsResponse;
import org.oasis.wsrp.v2.ExportByValueNotSupported;
import org.oasis.wsrp.v2.ExportNoLongerValid;
+import org.oasis.wsrp.v2.ExportPortlets;
+import org.oasis.wsrp.v2.ExportPortletsResponse;
import org.oasis.wsrp.v2.ExportedPortlet;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.FailedPortlets;
@@ -38,7 +41,9 @@
import org.oasis.wsrp.v2.GetPortletProperties;
import org.oasis.wsrp.v2.GetPortletPropertyDescription;
import org.oasis.wsrp.v2.ImportPortlet;
+import org.oasis.wsrp.v2.ImportPortlets;
import org.oasis.wsrp.v2.ImportPortletsFailed;
+import org.oasis.wsrp.v2.ImportPortletsResponse;
import org.oasis.wsrp.v2.ImportedPortlet;
import org.oasis.wsrp.v2.InconsistentParameters;
import org.oasis.wsrp.v2.InvalidHandle;
@@ -58,6 +63,7 @@
import org.oasis.wsrp.v2.Property;
import org.oasis.wsrp.v2.PropertyList;
import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.ReleaseExport;
import org.oasis.wsrp.v2.ResetProperty;
import org.oasis.wsrp.v2.ResourceList;
import org.oasis.wsrp.v2.ResourceSuspended;
@@ -69,6 +75,8 @@
import javax.jws.HandlerChain;
import javax.jws.WebParam;
import javax.xml.ws.Holder;
+
+import java.util.ArrayList;
import java.util.List;
/**
@@ -233,7 +241,16 @@
@WebParam(name = "extensions", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types", mode = WebParam.Mode.OUT)
Holder<List<Extension>> extensions)
throws AccessDenied, ExportByValueNotSupported, InconsistentParameters,
InvalidHandle, InvalidRegistration, InvalidUserCategory, MissingParameters,
ModifyRegistrationRequired, OperationFailed, OperationNotSupported, ResourceSuspended
{
- //To change body of implemented methods use File | Settings | File Templates.
+ ExportPortlets exportPortlets =
WSRPTypeFactory.createExportPortlets(registrationContext, portletContext, userContext,
lifetime.value, exportByValueRequired);
+
+ ExportPortletsResponse exportPortletsResponse =
producer.exportPortlets(exportPortlets);
+
+ lifetime.value = exportPortletsResponse.getLifetime();
+ exportContext.value = exportPortletsResponse.getExportContext();
+ exportedPortlet.value = exportPortletsResponse.getExportedPortlet();
+ failedPortlets.value = exportPortletsResponse.getFailedPortlets();
+ resourceList.value = exportPortletsResponse.getResourceList();
+ extensions.value = exportPortletsResponse.getExtensions();
}
public void importPortlets(
@@ -248,7 +265,14 @@
@WebParam(name = "extensions", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types", mode = WebParam.Mode.OUT)
Holder<List<Extension>> extensions)
throws AccessDenied, ExportNoLongerValid, InconsistentParameters,
InvalidRegistration, InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, OperationNotSupported, ResourceSuspended
{
- //To change body of implemented methods use File | Settings | File Templates.
+ ImportPortlets importPortlets =
WSRPTypeFactory.createImportPortlets(registrationContext, importContext, importPortlet,
userContext, lifetime);
+
+ ImportPortletsResponse importPortletsResponse =
producer.importPortlets(importPortlets);
+
+ importedPortlets.value = importPortletsResponse.getImportedPortlets();
+ importFailed.value = importPortletsResponse.getImportFailed();
+ resourceList.value = importPortletsResponse.getResourceList();
+ extensions.value = importPortletsResponse.getExtensions();
}
public List<Extension> releaseExport(
@@ -256,14 +280,20 @@
@WebParam(name = "exportContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") byte[] exportContext,
@WebParam(name = "userContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") UserContext userContext)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ ReleaseExport releaseExport =
WSRPTypeFactory.createReleaseExport(registrationContext, exportContext, userContext);
+
+ producer.releaseExport(releaseExport);
+
+ //release export isn't suppose to return anything
+ return new ArrayList<Extension>();
}
public Lifetime setExportLifetime(
@WebParam(name = "setExportLifetime", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types", partName = "setExportLifetime")
SetExportLifetime setExportLifetime)
throws AccessDenied, InvalidHandle, InvalidRegistration,
ModifyRegistrationRequired, OperationFailed, OperationNotSupported, ResourceSuspended
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ //Note: we are getting a SetExportLifetime instead of the components for some
reason.
+ return producer.setExportLifetime(setExportLifetime);
}
public void setPortletProperties(
Added:
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
(rev 0)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/NeedPortletHandleTest.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -0,0 +1,245 @@
+/******************************************************************************
+ * 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.protocol.v2;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.oasis.wsrp.v2.GetMarkup;
+import org.oasis.wsrp.v2.GetServiceDescription;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.MarkupResponse;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PortletDescription;
+import org.oasis.wsrp.v2.ServiceDescription;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public abstract class NeedPortletHandleTest extends V2ProducerBaseTest
+{
+ private String mostUsedPortletWARFileName;
+ private String currentlyDeployedArchiveName;
+ private Map<String, List<String>> war2Handles = new HashMap<String,
List<String>>(7);
+
+
+ public NeedPortletHandleTest(String portletWARFileName)
+ throws Exception
+ {
+ this("NeedPortletHandleTest", portletWARFileName);
+ this.mostUsedPortletWARFileName = portletWARFileName;
+ }
+
+ protected NeedPortletHandleTest(String name, String portletWARFileName)
+ throws Exception
+ {
+ super(name);
+ this.mostUsedPortletWARFileName = portletWARFileName;
+ }
+
+ protected String getDefaultHandle()
+ {
+ return getFirstHandleFor(mostUsedPortletWARFileName);
+ }
+
+ /**
+ * @param archiveName
+ * @return
+ * @since 2.6.3
+ */
+ private String getFirstHandleFor(String archiveName)
+ {
+ return war2Handles.get(archiveName).get(0);
+ }
+
+ protected String getHandleForCurrentlyDeployedArchive()
+ {
+ return getFirstHandleFor(currentlyDeployedArchiveName);
+ }
+
+ /**
+ * @return
+ * @since 2.6.3
+ */
+ protected List<String> getHandlesForCurrentlyDeployedArchive()
+ {
+ return war2Handles.get(currentlyDeployedArchiveName);
+ }
+
+ /**
+ * Each time we deploy a new archive, check to see if the service description has
changed and add any new portlet
+ * handles found.
+ *
+ * @param archiveName
+ * @throws Exception
+ */
+ public void deploy(String archiveName) throws Exception
+ {
+ super.deploy(archiveName);
+ currentlyDeployedArchiveName = archiveName;
+
+ if (!war2Handles.containsKey(archiveName))
+ {
+ GetServiceDescription getServiceDescription =
WSRPTypeFactory.createGetServiceDescription();
+ ServiceDescription serviceDescription =
producer.getServiceDescription(getServiceDescription);
+ List<PortletDescription> offered =
serviceDescription.getOfferedPortlets();
+ if (offered != null)
+ {
+ for (PortletDescription portletDescription : offered)
+ {
+ String handle = portletDescription.getPortletHandle();
+ String warName = handle.substring(1, handle.indexOf('.')) +
".war";
+ if (warName.equals(archiveName))
+ {
+ List<String> handles = war2Handles.get(warName);
+ if (handles == null)
+ {
+ handles = new ArrayList<String>(3);
+ war2Handles.put(warName, handles);
+ }
+
+ handles.add(handle);
+ }
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException(archiveName + " didn't contain
any portlets...");
+ }
+ }
+ }
+
+ public void undeploy(String archiveName) throws Exception
+ {
+ try
+ {
+ super.undeploy(archiveName);
+ }
+ catch (Exception e)
+ {
+ // if an exception occurred the portlet is still probably deployed, so just
exit
+ e.printStackTrace();
+ return;
+ }
+
+ currentlyDeployedArchiveName = null;
+
+ // only remove the mapping if we're not undeploying the most used portlet
(optimization, as it avoids parsing the SD)
+ if (!mostUsedPortletWARFileName.equals(archiveName))
+ {
+ war2Handles.remove(archiveName);
+ }
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.mostUsedPortletWARFileName = getMostUsedPortletWARFileName();
+ deploy(mostUsedPortletWARFileName);
+
+ // reset strict mode
+ producer.usingStrictModeChangedTo(true);
+ }
+
+ /**
+ * Sub-classes need to implement this method to return the local WAR file name of the
portlet being deployed most of
+ * the time in the context of the test case. This is required since we cannot rely on
the name to be properly set at
+ * all time via the constructor.
+ *
+ * @return
+ */
+ protected abstract String getMostUsedPortletWARFileName();
+
+ public void tearDown() throws Exception
+ {
+ undeploy(mostUsedPortletWARFileName);
+ super.tearDown();
+ }
+
+ /**
+ * Creates a valid Markup request.
+ *
+ * @return a basic, valid GetMarkup object representing the markup request
+ */
+ protected GetMarkup createMarkupRequestForCurrentlyDeployedPortlet() throws Exception
+ {
+ return createMarkupRequest(getHandleForCurrentlyDeployedArchive());
+ }
+
+ /**
+ * @param handle
+ * @return
+ * @throws RemoteException
+ * @throws V1InvalidRegistrationFault
+ * @throws V1OperationFailedFault
+ * @since 2.6.3
+ */
+ protected GetMarkup createMarkupRequest(String handle) throws RemoteException,
InvalidRegistration, OperationFailed
+ {
+ GetMarkup getMarkup = WSRPTypeFactory.createDefaultMarkupRequest(handle);
+
getMarkup.getMarkupParams().getMarkupCharacterSets().add(WSRPConstants.DEFAULT_CHARACTER_SET);
+
+ return getMarkup;
+ }
+
+ protected String getPortletHandleFrom(String partialHandle)
+ {
+ List<String> handles = getHandlesForCurrentlyDeployedArchive();
+ for (String handle : handles)
+ {
+ if (handle.contains(partialHandle))
+ {
+ return handle;
+ }
+ }
+
+ throw new IllegalArgumentException("Couldn't find a portlet handle
matching '" + partialHandle + "' in " +
currentlyDeployedArchiveName);
+ }
+
+ protected GetMarkup createMarkupRequest() throws Exception
+ {
+ return createMarkupRequestForCurrentlyDeployedPortlet();
+ }
+
+ protected void checkSessionForCurrentlyDeployedPortlet(MarkupResponse response)
+ throws RemoteException, InvalidRegistration, OperationFailed
+ {
+ // We don't send any portlet session information, just user cookies... The
producer takes care of the details
+ // What this means, though is that we don't have access to individual portlet
session ids... so we can only
+ // check that we get a cookie... Not very test-friendly...
+ /*ProducerSessionInformation sessionInfo =
RequestHeaderClientHandler.getCurrentProducerSessionInformation();
+ ExtendedAssert.assertNotNull(sessionInfo);
+
ExtendedAssert.assertTrue(sessionInfo.getUserCookie().lastIndexOf("JSESSIONID")
!= -1);
+
+ // Check that we are not sending sessionID's
+ SessionContext sessionContext = response.getSessionContext();
+ ExtendedAssert.assertNull(sessionContext);*/
+ }
+}
+
Added:
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
(rev 0)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-05
14:53:28 UTC (rev 3760)
@@ -0,0 +1,252 @@
+/******************************************************************************
+ * 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.protocol.v2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportPortletData;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.producer.WSRPProducerBaseTest;
+import org.gatein.wsrp.servlet.ServletAccess;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.gatein.wsrp.test.support.MockHttpServletRequest;
+import org.gatein.wsrp.test.support.MockHttpServletResponse;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.oasis.wsrp.v2.ExportPortlets;
+import org.oasis.wsrp.v2.ExportPortletsResponse;
+import org.oasis.wsrp.v2.ExportedPortlet;
+import org.oasis.wsrp.v2.FailedPortlets;
+import org.oasis.wsrp.v2.ImportPortlet;
+import org.oasis.wsrp.v2.ImportPortlets;
+import org.oasis.wsrp.v2.ImportPortletsResponse;
+import org.oasis.wsrp.v2.Lifetime;
+import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.UserContext;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+(a)RunWith(Arquillian.class)
+public class PortletManagementTestCase extends NeedPortletHandleTest
+{
+ private static final String TEST_BASIC_PORTLET_WAR =
"test-basic-portlet.war";
+
+
+ public PortletManagementTestCase() throws Exception
+ {
+ super("PortletManagementTestCase", TEST_BASIC_PORTLET_WAR);
+ }
+
+ @Deployment
+ public static JavaArchive createDeployment()
+ {
+ JavaArchive jar = ShrinkWrap.create("test.jar", JavaArchive.class);
+ jar.addClass(NeedPortletHandleTest.class);
+ jar.addClass(V2ProducerBaseTest.class);
+ jar.addClass(WSRPProducerBaseTest.class);
+ return jar;
+ }
+
+ @Before
+ public void setUp() throws Exception
+ {
+ if (System.getProperty("test.deployables.dir") != null)
+ {
+ super.setUp();
+ //hack to get around having to have a httpservletrequest when accessing the
producer services
+ //I don't know why its really needed, seems to be a dependency where wsrp
connects with the pc module
+
ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null),
MockHttpServletResponse.createMockResponse());
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception
+ {
+ if (System.getProperty("test.deployables.dir") != null)
+ {
+ super.tearDown();
+ }
+ }
+
+ /*TO TEST
+ * - export
+ * - import
+ * - releaseExport
+ * - test a valid setup that the producer is no longer holding any data
+ * - test an invalid setup that we get back the proper errors
+ * - test with invalid portlet handles
+ * - setExportLifeTime
+ * - test a valid setup that the export lifetime has been updated
+ * - test an invalid setup that we get an error back
+ * - use an invalid export context
+ * - use an export context that is set to export by value
+ * - invalid registration, usercontext, etc..
+ */
+
+ @Test
+ public void testExport() throws Exception
+ {
+ boolean exportByValue = true;
+ Lifetime lifetime = null;
+ UserContext userContext = null;
+ RegistrationContext registrationContext = null;
+
+ String handle = getDefaultHandle();
+ PortletContext defaultContext = WSRPTypeFactory.createPortletContext(handle);
+
+ List<PortletContext> portletContexts = new
ArrayList<PortletContext>();
+ portletContexts.add(defaultContext);
+
+ ExportPortlets exportPortlets =
WSRPTypeFactory.createExportPortlets(registrationContext, portletContexts, userContext,
lifetime, exportByValue);
+
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+
+ assertNotNull(response.getExportContext());
+ assertNull(response.getLifetime());
+ assertTrue(response.getFailedPortlets().isEmpty());
+
+ assertEquals(1, response.getExportedPortlet().size());
+
+ ExportedPortlet exportPortlet = response.getExportedPortlet().get(0);
+
+ assertEquals(handle, exportPortlet.getPortletHandle());
+ }
+
+
+ @Test
+ public void testExportNonExistantHandle() throws Exception
+ {
+ String nonExistantHandle = "123FakeHandle";
+ List<PortletContext> portletContexts =
createPortletContextList(nonExistantHandle);
+
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+
+ assertNotNull(response.getExportContext());
+ assertNull(response.getLifetime());
+ assertTrue(response.getExportedPortlet().isEmpty());
+
+ assertEquals(1, response.getFailedPortlets().size());
+
+ FailedPortlets failedPortlet = response.getFailedPortlets().get(0);
+
+ assertTrue(failedPortlet.getPortletHandles().contains(nonExistantHandle));
+
assertEquals("InvalidHandle",failedPortlet.getErrorCode().getLocalPart());
+ assertTrue(failedPortlet.getPortletHandles().contains(nonExistantHandle));
+ }
+
+ @Test
+ public void testExportNullHandle() throws Exception
+ {
+ String nonExistantHandle = null;
+ List<PortletContext> portletContexts =
createPortletContextList(nonExistantHandle);
+
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+
+ assertNotNull(response.getExportContext());
+ assertNull(response.getLifetime());
+ assertTrue(response.getExportedPortlet().isEmpty());
+
+ assertEquals(1, response.getFailedPortlets().size());
+
+ FailedPortlets failedPortlet = response.getFailedPortlets().get(0);
+ assertTrue(failedPortlet.getPortletHandles().contains(nonExistantHandle));
+
assertEquals("InvalidHandle",failedPortlet.getErrorCode().getLocalPart());
+ assertTrue(failedPortlet.getPortletHandles().contains(nonExistantHandle));
+ }
+
+ protected List<PortletContext> createPortletContextList(String...
portletHandles)
+ {
+ List<PortletContext> portletContexts = new
ArrayList<PortletContext>();
+
+ for (String portletHandle : portletHandles)
+ {
+ PortletContext portletContext = new PortletContext();
+ portletContext.setPortletHandle(portletHandle);
+ portletContexts.add(portletContext);
+ }
+ return portletContexts;
+ }
+
+ protected ExportPortlets createSimpleExportPortlets (List<PortletContext>
portletContexts)
+ {
+ boolean exportByValueRequired = true;
+ Lifetime lifetime = null;
+ UserContext userContext = null;
+ RegistrationContext registrationContext = null;
+
+ return WSRPTypeFactory.createExportPortlets(registrationContext, portletContexts,
userContext, lifetime, exportByValueRequired);
+ }
+
+
+ @Test
+ public void testImport() throws Exception
+ {
+ String importID = "foo";
+
+ ExportPortletData exportPortletData = new ExportPortletData(getDefaultHandle(),
null);
+ byte[] exportData = exportPortletData.encodeAsBytes();
+
+ Lifetime lifetime = null;
+ UserContext userContext = null;
+ RegistrationContext registrationContext = null;
+
+ List<String> portletList = new ArrayList<String>();
+ portletList.add(getDefaultHandle());
+ ExportContext exportContextData = new ExportContext();
+ byte[] importContext = exportContextData.encodeAsBytes();
+
+ ImportPortlet importPortlet = WSRPTypeFactory.createImportPorlet(importID,
exportData);
+
+ List<ImportPortlet> importPortletsList = new
ArrayList<ImportPortlet>();
+ importPortletsList.add(importPortlet);
+
+ ImportPortlets importPortlets =
WSRPTypeFactory.createImportPortlets(registrationContext, importContext,
importPortletsList, userContext, lifetime);
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+ }
+
+
+
+
+ @Override
+ protected String getMostUsedPortletWARFileName()
+ {
+ return TEST_BASIC_PORTLET_WAR;
+ }
+
+}
+
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/producer-sar/META-INF/jboss-beans.xml
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/producer-sar/META-INF/jboss-beans.xml 2010-08-05
13:14:29 UTC (rev 3759)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/producer-sar/META-INF/jboss-beans.xml 2010-08-05
14:53:28 UTC (rev 3760)
@@ -47,6 +47,9 @@
<property name="configurationService">
<inject bean="ConfigurationService"/>
</property>
+ <property name="exportManager">
+ <inject bean="ExportManager"/>
+ </property>
</bean>
<bean name="PortletInvoker"
class="org.gatein.pc.portlet.state.producer.ProducerPortletInvoker">
@@ -92,39 +95,6 @@
<bean name="ServletAccess"
class="org.gatein.wsrp.servlet.ServletAccess"/>
-</deployment>
+ <bean name="ExportManager"
class="org.gatein.exports.impl.ExportManagerImpl"/>
- <!-- Dummy test WSRP Producer implementation -->
- <!-- <bean name="DummyWSRPProducer"
class="org.gatein.wsrp.test.TestWSRPProducerImpl"/> -->
-
- <!-- Hack to get access to req/resp -->
- <!-- <bean name="ServletAccess"
class="org.gatein.wsrp.servlet.ServletAccessFilter"/> -->
-
- <!-- <bean name="ServiceFactory"
class="org.gatein.wsrp.services.PerEndpointSOAPInvokerServiceFactory">
- <property
name="ServiceDescriptionURL">http://localhost:8080/test-wsrp-consumer/ServiceDescriptionService</property>
- <property
name="MarkupURL">http://localhost:8080/test-wsrp-consumer/MarkupService</property>
- <property
name="RegistrationURL">http://localhost:8080/test-wsrp-consumer/RegistrationService</property>
- <property
name="PortletManagementURL">http://localhost:8080/test-wsrp-consumer/PortletManagementService</property>
- <property name="Env">
- java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
- java.naming.provider.url=jnp://localhost:1099
- java.naming.factory.url.pkgs=org.jboss.naming.client
- j2ee.clientName=wsrp-client
- </property>
- <property name="PortJNDIMapping">
-
org.gatein.wsrp.core.WSRP_v1_ServiceDescription_PortType=java:comp/env/service/ServiceDescriptionService
-
org.gatein.wsrp.core.WSRP_v1_Markup_PortType=java:comp/env/service/MarkupService
-
org.gatein.wsrp.core.WSRP_v1_Registration_PortType=java:comp/env/service/RegistrationService
-
org.gatein.wsrp.core.WSRP_v1_PortletManagement_PortType=java:comp/env/service/PortletManagementService
- </property>
- </bean>
-
- <bean name="CachingServiceFactory"
class="CachingServiceFactory">
- <property name="Delegate"><inject
bean="ServiceFactory"/></property>
- </bean>
-
- <bean name="WSRPConsumer"
class="org.gatein.wsrp.consumer.WSRPConsumerImpl">
- <property name="ServiceFactory"><inject
bean="CachingServiceFactory"/></property>
- </bean>
- -->
- <!--</deployment> -->
+</deployment>