gatein SVN: r3767 - in components/wsrp/trunk: common/src/main/java/org/gatein/wsrp/spec/v2 and 2 other directories.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2010-08-06 15:39:29 -0400 (Fri, 06 Aug 2010)
New Revision: 3767
Added:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/MimeResponseHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MimeResponseProcessor.java
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v2/WSRP2Constants.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ResourceHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RenderRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ResourceRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPPortletInvocationContext.java
Log:
- GTNWSRP-54:
+ Added fake resource id for cases where portlets want to retrieve a resource without specifying an id (allowed by JSR 286).
+ Added support for resource cacheability as it is needed to properly generate portlet URLs in resources.
+ Added MimeResponseHandler and MimeResponseProcessor to gather common code between render and resource operations.
+ Fixed incorrect behavior of ResourceHandler.prepareRequest.
+ Right now, force rewriting all the time, need to handle this better.
- GTNWSRP-58: Started adding generics for better type safety and more elegant code.
- Cleaned up code a little.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java 2010-08-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -234,10 +234,6 @@
}
else if (encodedURL.startsWith(WSRPRewritingConstants.URL_TYPE_RESOURCE))
{
- if (log.isDebugEnabled())
- {
- log.debug("Using experimental resource URL support...");
- }
urlType = WSRPRewritingConstants.URL_TYPE_RESOURCE;
url = new WSRPResourceURL();
}
@@ -258,11 +254,6 @@
// extract the other parameters
params = extractParams(encodedURL, originalURL, customModes, customWindowStates);
}
- else if (WSRPRewritingConstants.URL_TYPE_RESOURCE.equals(urlType))
- {
- throw new IllegalArgumentException("Both the 'wsrp-url' and 'wsrp-requiresRewrite' parameters MUST also be specified for resource URL '"
- + originalURL + "'");
- }
url.setParams(params, originalURL);
url.setExtraParamsAfterEndToken(extraAfterEnd);
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java 2010-08-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -25,9 +25,7 @@
import org.gatein.common.net.URLTools;
import org.gatein.common.net.media.MediaType;
-import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.api.Mode;
-import org.gatein.pc.api.PortletContext;
import org.gatein.pc.api.ResourceURL;
import org.gatein.pc.api.StateString;
import org.gatein.pc.api.WindowState;
@@ -35,7 +33,6 @@
import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
import org.jboss.logging.Logger;
-import javax.servlet.http.HttpServletRequest;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
@@ -49,6 +46,7 @@
public class WSRPResourceURL extends WSRPPortletURL implements ResourceURL
{
private final static Logger log = Logger.getLogger(WSRPResourceURL.class);
+ public final static String DEFAULT_RESOURCE_ID = "_gtn_resid_";
private String resourceId;
private StateString resourceState;
@@ -83,6 +81,11 @@
{
super(mode, windowState, secure, navigationalState);
+ if (resourceId == null)
+ {
+ // if the container didn't provide us with a resource id, fake one so that we can still build a correct WSRP URL.
+ resourceId = DEFAULT_RESOURCE_ID;
+ }
this.resourceId = resourceId;
this.resourceState = resourceState;
this.cacheability = cacheability;
@@ -101,16 +104,16 @@
}
createURLParameter(sb, WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE, requiresRewrite ? "true" : "false");
-
+
if (resourceId != null)
{
createURLParameter(sb, WSRP2RewritingConstants.RESOURCE_ID, resourceId);
}
-
+
// false is the default value, so we don't actually need to add it to the string
if (preferOperation != false)
{
- createURLParameter(sb, WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION, Boolean.toString(preferOperation));
+ createURLParameter(sb, WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION, Boolean.toString(preferOperation));
}
}
@@ -119,10 +122,10 @@
{
super.dealWithSpecificParams(params, originalURL);
- String paramValue = getRawParameterValueFor(params, WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE);
- if (paramValue != null)
+ String requireRewrite = getRawParameterValueFor(params, WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE);
+ if (requireRewrite != null)
{
- requiresRewrite = Boolean.valueOf(paramValue);
+ requiresRewrite = Boolean.valueOf(requireRewrite);
params.remove(WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE);
}
else
@@ -131,48 +134,52 @@
+ WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE + " parameter in " + originalURL);
}
- paramValue = getRawParameterValueFor(params, WSRPRewritingConstants.RESOURCE_URL);
- if (paramValue != null)
+ String url = getRawParameterValueFor(params, WSRPRewritingConstants.RESOURCE_URL);
+ if (url != null)
{
try
{
- paramValue = URLTools.decodeXWWWFormURL(paramValue);
- this.resourceURL = new URL(paramValue);
+ url = URLTools.decodeXWWWFormURL(url);
+ this.resourceURL = new URL(url);
String extension = URLTools.getFileExtensionOrNullFrom(resourceURL);
MediaType mediaType = SUPPORTED_RESOURCE_TYPES.get(extension);
if (mediaType == null)
{
log.debug("Couldn't determine (based on extension) MIME type of file: " + resourceURL.getPath()
- + "\nRetrieving the associated resource will probably fail.");
+ + "\nRetrieving the associated resource will probably fail.");
}
params.remove(WSRPRewritingConstants.RESOURCE_URL);
-
+
}
catch (MalformedURLException e)
{
- throw new IllegalArgumentException("Malformed URL: " + paramValue, e);
+ throw new IllegalArgumentException("Malformed URL: " + url, e);
}
}
-
+
String resourceIDParam = getRawParameterValueFor(params, WSRP2RewritingConstants.RESOURCE_ID);
if (resourceIDParam != null)
{
resourceId = resourceIDParam;
}
-
+
String preferOperationParam = getRawParameterValueFor(params, WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
+ if (preferOperationParam != null)
{
- if (preferOperationParam != null)
- {
- preferOperation = Boolean.valueOf(preferOperationParam);
- }
+ preferOperation = Boolean.valueOf(preferOperationParam);
}
-
- if (resourceIDParam == null && paramValue == null)
+
+ String cacheabilityParam = getRawParameterValueFor(params, WSRP2RewritingConstants.RESOURCE_CACHEABILITY);
+ if (cacheabilityParam != null)
{
+ cacheability = WSRPUtils.getCacheLevelFromResourceCacheability(cacheabilityParam);
+ }
+
+ if (resourceIDParam == null && url == null)
+ {
throw new IllegalArgumentException("The parsed parameters don't contain a value for "
- + WSRPRewritingConstants.RESOURCE_URL + " or for " + WSRP2RewritingConstants.RESOURCE_ID + " parameter in " + originalURL);
+ + WSRPRewritingConstants.RESOURCE_URL + " or for " + WSRP2RewritingConstants.RESOURCE_ID + " parameter in " + originalURL);
}
}
@@ -185,15 +192,6 @@
return resourceURL;
}
- /**
- * @param resourceURL
- * @deprecated
- */
- public void setResourceURL(URL resourceURL)
- {
- this.resourceURL = resourceURL;
- }
-
public String getResourceId()
{
// we need to return a representation of the wsrp resource identification, this is not necessarily just
@@ -202,15 +200,6 @@
return encodeResource(resourceId, resourceURL, preferOperation);
}
- /**
- * @param resourceId
- * @deprecated
- */
- public void setResourceId(String resourceId)
- {
- this.resourceId = resourceId;
- }
-
public StateString getResourceState()
{
return resourceState;
@@ -221,31 +210,6 @@
return cacheability;
}
- public static String createAbsoluteURLFrom(String initial, String serverAddress, String portletApplicationName)
- {
- String url = serverAddress;
-
- if (portletApplicationName != null)
- {
- url += URLTools.SLASH + portletApplicationName;
- }
-
- if (!ParameterValidation.isNullOrEmpty(initial))
- {
- if (initial.startsWith(URLTools.SLASH))
- {
- url += initial;
- }
- else
- {
- url += URLTools.SLASH + initial;
- }
- }
-
- return url;
-
- }
-
/**
* @return
* @deprecated
@@ -254,54 +218,56 @@
{
return requiresRewrite;
}
-
+
//TODO: figure out a more clean way to encode and decode the pc resource id (note: different from the wsrp resource id)
//we should either use a Map<String, String> directly or pass an object back
-
+
/**
* Encodes the wsrp resource information into a single string.
- *
- * @param resourceId The original resource ID
- * @param resourceURL The originial resource url
+ *
+ * @param resourceId The original resource ID
+ * @param resourceURL The originial resource url
* @param preferedOperation The preferedOperation value
* @return
*/
public static String encodeResource(String resourceId, URL resourceURL, boolean preferedOperation)
{
Map<String, String[]> parameters = new HashMap<String, String[]>();
-
+
if (resourceId != null)
{
parameters.put(WSRP2RewritingConstants.RESOURCE_ID, new String[]{resourceId});
}
-
+
if (resourceURL != null)
{
parameters.put(WSRPRewritingConstants.RESOURCE_URL, new String[]{resourceURL.toString()});
}
-
+
parameters.put(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION, new String[]{Boolean.toString(preferedOperation)});
-
+
return StateString.encodeAsOpaqueValue(parameters);
}
-
+
/**
* Decodes the resource information specified by the encodeResource back into proper resource values
- *
+ *
* @param resourceInfo
*/
public static Map<String, String> decodeResource(String resourceInfo)
{
- Map<String, String[]> resourceParameters = StateString.decodeOpaqueValue(resourceInfo);
-
+ Map<String, String[]> resourceParameters = StateString.decodeOpaqueValue(resourceInfo);
+
Map<String, String> resource = new HashMap<String, String>();
-
+
for (Map.Entry<String, String[]> entry : resourceParameters.entrySet())
{
if (entry.getValue() != null && entry.getValue().length > 0)
- resource.put(entry.getKey(), entry.getValue()[0]);
+ {
+ resource.put(entry.getKey(), entry.getValue()[0]);
+ }
}
-
+
return resource;
}
}
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-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -75,6 +75,7 @@
import org.oasis.wsrp.v2.MarkupParams;
import org.oasis.wsrp.v2.MarkupResponse;
import org.oasis.wsrp.v2.MarkupType;
+import org.oasis.wsrp.v2.MimeResponse;
import org.oasis.wsrp.v2.ModelDescription;
import org.oasis.wsrp.v2.ModifyRegistration;
import org.oasis.wsrp.v2.NamedString;
@@ -185,20 +186,20 @@
{
return createResourceRequest(createPortletContext(handle), createDefaultRuntimeContext(), createDefaultResourceParams(resourceID));
}
-
+
public static GetResource createResourceRequest(PortletContext portletContext, RuntimeContext runtimeContext, ResourceParams resourceParams)
{
ParameterValidation.throwIllegalArgExceptionIfNull(runtimeContext, "RuntimeContext");
ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "PortletContext");
ParameterValidation.throwIllegalArgExceptionIfNull(resourceParams, "ResourceParams");
-
+
GetResource getResource = new GetResource();
getResource.setPortletContext(portletContext);
getResource.setRuntimeContext(runtimeContext);
getResource.setResourceParams(resourceParams);
return getResource;
}
-
+
/**
* Same as createPerformBlockingInteraction(portletHandle, {@link #createDefaultRuntimeContext}(), {@link
* #createDefaultMarkupParams}(), {@link #createDefaultInteractionParams}());
@@ -404,9 +405,9 @@
public static ResourceParams createDefaultResourceParams(String resourceID)
{
return createResourceParams(false, WSRPConstants.getDefaultLocales(), WSRPConstants.getDefaultMimeTypes(),
- WSRPConstants.VIEW_MODE, WSRPConstants.NORMAL_WINDOW_STATE, resourceID, StateChange.READ_ONLY);
+ WSRPConstants.VIEW_MODE, WSRPConstants.NORMAL_WINDOW_STATE, resourceID, StateChange.READ_ONLY);
}
-
+
public static ResourceParams createResourceParams(boolean secureClientCommunication, List<String> locales, List<String> mimeTypes, String mode, String windowState, String resourceID, StateChange stateChange)
{
ParameterValidation.throwIllegalArgExceptionIfNull(locales, "locales");
@@ -419,7 +420,7 @@
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mode, "mode", "ResourceParams");
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(windowState, "window state", "ResourceParams");
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(resourceID, "Resource ID", "ResourceParams");
-
+
ResourceParams resourceParams = new ResourceParams();
resourceParams.setSecureClientCommunication(secureClientCommunication);
resourceParams.setMode(mode);
@@ -428,18 +429,18 @@
{
resourceParams.getLocales().addAll(locales);
}
-
+
if (ParameterValidation.existsAndIsNotEmpty(mimeTypes))
{
resourceParams.getMimeTypes().addAll(mimeTypes);
}
-
+
resourceParams.setResourceID(resourceID);
resourceParams.setPortletStateChange(stateChange);
-
+
return resourceParams;
}
-
+
/**
* Same as createRuntimeContext({@link WSRPConstants#NONE_USER_AUTHENTICATION})
*
@@ -518,7 +519,7 @@
markupResponse.setMarkupContext(markupContext);
return markupResponse;
}
-
+
public static ResourceResponse createResourceResponse(ResourceContext resourceContext)
{
ParameterValidation.throwIllegalArgExceptionIfNull(resourceContext, "ResourceContext");
@@ -567,53 +568,50 @@
markupContext.setItemBinary(markupBinary);
return markupContext;
}
-
- /**
- * mimeType: The mime type of the returned resource. The mimeType field MUST be specified whenever resource is returned,
- * and if the resourceBinary field is used to return the resource, the mime type MUST include the character set for
- * textual mime types using the syntax specified in RFC1522[14] (e.g. "text/html; charset=UTF-8"). In this particular
- * case this character set MAY be different than the response message.
- * <p/>
- */
- public static ResourceContext createResourceContext(String mediaType, String resourceString)
- {
- return createResourceContext(mediaType, resourceString, null);
- }
/**
* @param mediaType The mime type of the returned resource. The mimeType field MUST be specified whenever resource is
- * returned, and if the resourceBinary field is used to return the resource, the mime type MUST include
- * the character set for textual mime types using the syntax specified in RFC1522[14] (e.g.
+ * returned, and if the resourceBinary field is used to return the resource, the mime type MUST
+ * include the character set for textual mime types using the syntax specified in RFC1522[14] (e.g.
* "text/html; charset=UTF-8"). In this particular case this character set MAY be different than the
* response message.
* @return a new ResourceContext
*/
- public static ResourceContext createResourceContext(String mediaType, byte[] resourceBinary)
+ public static ResourceContext createResourceContext(String mediaType, String resourceString, byte[] resourceBinary)
{
- return createResourceContext(mediaType, null, resourceBinary);
+ return createMimeResponse(mediaType, resourceString, resourceBinary, ResourceContext.class);
}
-
- public static ResourceContext createResourceContext(String mediaType, String resourceString, byte[] resourceBinary)
+
+ public static <T extends MimeResponse> T createMimeResponse(String mimeType, String itemString, byte[] itemBinary, Class<T> clazz)
{
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mediaType, "MIME type", "ResourceContext");
- if ((resourceString == null) && (resourceBinary == null || resourceBinary.length == 0))
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mimeType, "MIME type", "MimeResponse");
+ if ((itemString == null) && (itemBinary == null || itemBinary.length == 0))
{
- throw new IllegalArgumentException("MarkupContext requires either a non-null markup string or binary markup.");
+ throw new IllegalArgumentException("MimeResponse requires either a non-null markup string or binary markup.");
}
-
- ResourceContext resourceContext = new ResourceContext();
- resourceContext.setMimeType(mediaType);
-
- if (resourceString != null)
+
+ T mimeResponse;
+ try
{
- resourceContext.setItemString(resourceString);
+ mimeResponse = clazz.newInstance();
}
+ catch (Exception e)
+ {
+ throw new RuntimeException("Couldn't instantiate " + clazz.getSimpleName(), e);
+ }
+
+ mimeResponse.setMimeType(mimeType);
+
+ if (itemString != null)
+ {
+ mimeResponse.setItemString(itemString);
+ }
else
{
- resourceContext.setItemBinary(resourceBinary);
+ mimeResponse.setItemBinary(itemBinary);
}
-
- return resourceContext;
+
+ return mimeResponse;
}
/**
@@ -1376,24 +1374,24 @@
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
@@ -1403,60 +1401,60 @@
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)
+
+ 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
@@ -1474,49 +1472,49 @@
return failedPortlets;
}
- throw new IllegalArgumentException("Must provide non-null, non-empty portlet handle list.");
+ 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/WSRPUtils.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java 2010-08-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -29,17 +29,16 @@
import org.gatein.common.net.URLTools;
import org.gatein.common.util.ConversionException;
import org.gatein.common.util.ParameterValidation;
-import org.gatein.pc.api.ActionURL;
import org.gatein.pc.api.Mode;
import org.gatein.pc.api.PortletContext;
import org.gatein.pc.api.PortletStateType;
-import org.gatein.pc.api.PortletURL;
-import org.gatein.pc.api.RenderURL;
import org.gatein.pc.api.StatefulPortletContext;
import org.gatein.pc.api.WindowState;
+import org.gatein.pc.api.cache.CacheLevel;
import org.gatein.pc.api.state.AccessMode;
import org.gatein.wsrp.registration.LocalizedString;
import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.gatein.wsrp.spec.v2.WSRP2Constants;
import org.oasis.wsrp.v2.InteractionParams;
import org.oasis.wsrp.v2.MarkupParams;
import org.oasis.wsrp.v2.NamedString;
@@ -69,6 +68,7 @@
private final static Map<String, WindowState> WSRP_JSR168_WINDOW_STATES = new HashMap<String, WindowState>(7);
private final static Map<String, String> JSR168_WSRP_MODES = new HashMap<String, String>(7);
private final static Map<String, Mode> WSRP_JSR168_MODES = new HashMap<String, Mode>(7);
+ private final static Map<CacheLevel, String> JSR286_WSRP_CACHE = new HashMap<CacheLevel, String>(7);
private static final String SET_OF_LOCALES = "set of Locales";
private static final String MODE = "Mode";
private static final String WSRP_MODE_NAME = "wsrp portlet name";
@@ -107,6 +107,10 @@
DEFAULT_JSR168_MODES = new HashSet<Mode>(WSRP_JSR168_MODES.values());
DEFAULT_JSR168_WINDOWSTATES = new HashSet<WindowState>(WSRP_JSR168_WINDOW_STATES.values());
+
+ JSR286_WSRP_CACHE.put(CacheLevel.FULL, WSRP2Constants.RESOURCE_CACHEABILITY_FULL);
+ JSR286_WSRP_CACHE.put(CacheLevel.PAGE, WSRP2Constants.RESOURCE_CACHEABILITY_PAGE);
+ JSR286_WSRP_CACHE.put(CacheLevel.PORTLET, WSRP2Constants.RESOURCE_CACHEABILITY_PORTLET);
}
private WSRPUtils()
@@ -210,26 +214,6 @@
}
- public static String getWSRPURLTypeFrom(PortletURL url)
- {
- if (url instanceof WSRPPortletURL)
- {
- return ((WSRPPortletURL)url).getURLType();
- }
-
- if (url instanceof RenderURL)
- {
- return WSRPRewritingConstants.URL_TYPE_RENDER;
- }
-
- if (url instanceof ActionURL)
- {
- return WSRPRewritingConstants.URL_TYPE_BLOCKING_ACTION;
- }
-
- throw new IllegalArgumentException("Unrecognized URL type.");
- }
-
public static String convertRequestAuthTypeToWSRPAuthType(String authType)
{
if (authType == null)
@@ -304,7 +288,22 @@
return result;
}
+ public static String getResourceCacheabilityFromCacheLevel(CacheLevel cacheLevel)
+ {
+ return cacheLevel == null ? null : cacheLevel.name().toLowerCase(Locale.ENGLISH);
+ }
+ public static CacheLevel getCacheLevelFromResourceCacheability(String resourceCacheability)
+ {
+ // if we don't pass a resource cacheability, assume Page for maximum compatibility
+ if (resourceCacheability == null)
+ {
+ return CacheLevel.PAGE;
+ }
+ return CacheLevel.valueOf(resourceCacheability.toUpperCase(Locale.ENGLISH));
+ }
+
+
public static Locale getLocale(String lang) throws IllegalArgumentException
{
if (lang != null)
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v2/WSRP2Constants.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v2/WSRP2Constants.java 2010-08-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v2/WSRP2Constants.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -38,4 +38,8 @@
public static final String OPTIONS_COPYPORTLETS = "wsrp:copyPortlets";
public static final String OPTIONS_IMPORT = "wsrp:import";
public static final String OPTIONS_EXPORT = "wsrp:export";
+
+ public static final String RESOURCE_CACHEABILITY_FULL = "full";
+ public static final String RESOURCE_CACHEABILITY_PORTLET = "portlet";
+ public static final String RESOURCE_CACHEABILITY_PAGE = "page";
}
Added: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/MimeResponseHandler.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/MimeResponseHandler.java (rev 0)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/MimeResponseHandler.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -0,0 +1,182 @@
+/*
+ * 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.consumer;
+
+import org.gatein.common.text.TextTools;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.URLFormat;
+import org.gatein.pc.api.cache.CacheScope;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.pc.api.invocation.response.ContentResponse;
+import org.gatein.pc.api.invocation.response.ErrorResponse;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.pc.api.invocation.response.ResponseProperties;
+import org.gatein.pc.api.spi.PortletInvocationContext;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPConsumer;
+import org.gatein.wsrp.WSRPRewritingConstants;
+import org.oasis.wsrp.v2.CacheControl;
+import org.oasis.wsrp.v2.MimeResponse;
+import org.oasis.wsrp.v2.SessionContext;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public abstract class MimeResponseHandler<Response, LocalMimeResponse extends MimeResponse> extends InvocationHandler
+{
+ private static final org.gatein.pc.api.cache.CacheControl DEFAULT_CACHE_CONTROL = new org.gatein.pc.api.cache.CacheControl(0, CacheScope.PRIVATE, null);
+
+ protected MimeResponseHandler(WSRPConsumerImpl consumer)
+ {
+ super(consumer);
+ }
+
+ protected abstract SessionContext getSessionContextFrom(Response response);
+
+ protected abstract LocalMimeResponse getMimeResponseFrom(Response response);
+
+ @Override
+ protected PortletInvocationResponse processResponse(Object response, PortletInvocation invocation, RequestPrecursor requestPrecursor) throws PortletInvokerException
+ {
+ Response localResponse = (Response)response;
+
+ consumer.getSessionHandler().updateSessionIfNeeded(getSessionContextFrom(localResponse), invocation,
+ requestPrecursor.getPortletHandle());
+
+ LocalMimeResponse mimeResponse = getMimeResponseFrom(localResponse);
+ String markup = mimeResponse.getItemString();
+ byte[] binary = mimeResponse.getItemBinary();
+ if (markup != null && binary != null)
+ {
+ return new ErrorResponse(new IllegalArgumentException("Markup response cannot contain both string and binary " +
+ "markup. Per Section 6.1.10 of the WSRP specification, this is a Producer error."));
+ }
+
+ if (markup == null && binary == null)
+ {
+ if (mimeResponse.isUseCachedItem())
+ {
+ //todo: deal with cache GTNWSRP-40
+ }
+ else
+ {
+ return new ErrorResponse(new IllegalArgumentException("Markup response must contain at least string or binary" +
+ " markup. Per Section 6.1.10 of the WSRP specification, this is a Producer error."));
+ }
+ }
+
+ if (markup != null && markup.length() > 0)
+ {
+ if (Boolean.TRUE.equals(mimeResponse.isRequiresRewriting()))
+ {
+ markup = processMarkup(
+ markup,
+ getNamespaceFrom(invocation.getWindowContext()),
+ invocation.getContext(),
+ invocation.getTarget(),
+ new URLFormat(invocation.getSecurityContext().isSecure(), invocation.getSecurityContext().isAuthenticated(), true, true),
+ consumer
+ );
+ }
+ }
+
+ String mimeType = mimeResponse.getMimeType();
+ if (mimeType == null || mimeType.length() == 0)
+ {
+ return new ErrorResponse(new IllegalArgumentException("No MIME type was provided for portlet content."));
+ }
+
+ return createContentResponse(mimeResponse, invocation, null, null, mimeType, binary, markup, createCacheControl(mimeResponse));
+ }
+
+ protected PortletInvocationResponse createContentResponse(LocalMimeResponse mimeResponse, PortletInvocation invocation,
+ ResponseProperties properties, Map<String, Object> attributes,
+ String mimeType, byte[] bytes, String markup,
+ org.gatein.pc.api.cache.CacheControl cacheControl)
+ {
+ return new ContentResponse(properties, attributes, mimeType, bytes, markup, cacheControl);
+ }
+
+ static String processMarkup(String markup, String namespace, PortletInvocationContext context, org.gatein.pc.api.PortletContext target, URLFormat format, WSRPConsumer consumer)
+ {
+ // fix-me: how to deal with fragment header? => interceptor?
+
+ // todo: remove, this is a work-around for GTNWSRP-12
+ markup = markup.replaceFirst("%3ftimeout%3d.*%2f", "%2f");
+
+ markup = TextTools.replaceBoundedString(
+ markup,
+ WSRPRewritingConstants.WSRP_REWRITE,
+ WSRPRewritingConstants.END_WSRP_REWRITE,
+ new MarkupProcessor(namespace, context, target, format, consumer.getProducerInfo()),
+ true,
+ false,
+ true
+ );
+
+ return markup;
+ }
+
+ protected org.gatein.pc.api.cache.CacheControl createCacheControl(LocalMimeResponse mimeResponse)
+ {
+ CacheControl cacheControl = mimeResponse.getCacheControl();
+ org.gatein.pc.api.cache.CacheControl result = DEFAULT_CACHE_CONTROL;
+
+ int expires;
+ if (cacheControl != null)
+ {
+ expires = cacheControl.getExpires();
+ String userScope = cacheControl.getUserScope();
+
+ // check that we support the user scope...
+ if (consumer.supportsUserScope(userScope))
+ {
+ if (debug)
+ {
+ log.debug("Trying to cache markup " + userScope + " for " + expires + " seconds.");
+ }
+ CacheScope scope;
+ if (WSRPConstants.CACHE_FOR_ALL.equals(userScope))
+ {
+ scope = CacheScope.PUBLIC;
+ }
+ else if (WSRPConstants.CACHE_PER_USER.equals(userScope))
+ {
+ scope = CacheScope.PRIVATE;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown CacheControl user scope: " + userScope); // should not happen
+ }
+
+ result = new org.gatein.pc.api.cache.CacheControl(expires, scope, cacheControl.getValidateTag());
+ }
+ }
+
+ return result;
+ }
+}
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java 2010-08-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -23,21 +23,13 @@
package org.gatein.wsrp.consumer;
-import org.gatein.common.text.TextTools;
import org.gatein.pc.api.PortletInvokerException;
-import org.gatein.pc.api.URLFormat;
-import org.gatein.pc.api.cache.CacheScope;
import org.gatein.pc.api.invocation.PortletInvocation;
import org.gatein.pc.api.invocation.RenderInvocation;
-import org.gatein.pc.api.invocation.response.ErrorResponse;
import org.gatein.pc.api.invocation.response.FragmentResponse;
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
-import org.gatein.pc.api.spi.PortletInvocationContext;
-import org.gatein.wsrp.WSRPConstants;
-import org.gatein.wsrp.WSRPConsumer;
-import org.gatein.wsrp.WSRPRewritingConstants;
+import org.gatein.pc.api.invocation.response.ResponseProperties;
import org.gatein.wsrp.WSRPTypeFactory;
-import org.oasis.wsrp.v2.CacheControl;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.GetMarkup;
import org.oasis.wsrp.v2.MarkupContext;
@@ -49,22 +41,43 @@
import javax.xml.ws.Holder;
import java.util.List;
+import java.util.Map;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
* @version $Revision: 12082 $
* @since 2.4 (May 31, 2006)
*/
-public class RenderHandler extends InvocationHandler
+public class RenderHandler extends MimeResponseHandler<MarkupResponse, MarkupContext>
{
- private static final org.gatein.pc.api.cache.CacheControl DEFAULT_CACHE_CONTROL = new org.gatein.pc.api.cache.CacheControl(0, CacheScope.PRIVATE, null);
-
protected RenderHandler(WSRPConsumerImpl consumer)
{
super(consumer);
}
+ @Override
+ protected SessionContext getSessionContextFrom(MarkupResponse response)
+ {
+ return response.getSessionContext();
+ }
+
+ @Override
+ protected MarkupContext getMimeResponseFrom(MarkupResponse markupResponse)
+ {
+ return markupResponse.getMarkupContext();
+ }
+
+ @Override
+ protected PortletInvocationResponse createContentResponse(MarkupContext markupContext, PortletInvocation invocation,
+ ResponseProperties properties, Map<String, Object> attributes,
+ String mimeType, byte[] bytes, String markup,
+ org.gatein.pc.api.cache.CacheControl cacheControl)
+ {
+ return new FragmentResponse(properties, attributes, mimeType, bytes, markup, markupContext.getPreferredTitle(),
+ cacheControl, invocation.getPortalContext().getModes());
+ }
+
protected Object prepareRequest(RequestPrecursor requestPrecursor, PortletInvocation invocation)
{
if (!(invocation instanceof RenderInvocation))
@@ -81,68 +94,6 @@
return WSRPTypeFactory.createMarkupRequest(portletContext, requestPrecursor.runtimeContext, requestPrecursor.markupParams);
}
- protected PortletInvocationResponse processResponse(Object response, PortletInvocation invocation, RequestPrecursor requestPrecursor)
- {
- MarkupResponse markupResponse = (MarkupResponse)response;
-
- // process the response
- consumer.getSessionHandler().updateSessionIfNeeded(markupResponse.getSessionContext(), invocation,
- requestPrecursor.getPortletHandle());
-
- MarkupContext markupContext = markupResponse.getMarkupContext();
- String markup = markupContext.getItemString();
- byte[] binary = markupContext.getItemBinary();
- if (markup != null && binary != null)
- {
- return new ErrorResponse(new IllegalArgumentException("Markup response cannot contain both string and binary " +
- "markup. Per Section 6.1.10 of the WSRP specification, this is a Producer error."));
- }
-
- if (markup == null && binary == null)
- {
- if (markupContext.isUseCachedItem())
- {
- //todo: deal with cache GTNWSRP-40
- }
- else
- {
- return new ErrorResponse(new IllegalArgumentException("Markup response must contain at least string or binary" +
- " markup. Per Section 6.1.10 of the WSRP specification, this is a Producer error."));
- }
- }
-
- if (markup != null && markup.length() > 0)
- {
- if (Boolean.TRUE.equals(markupContext.isRequiresRewriting()))
- {
- markup = processMarkup(
- markup,
- getNamespaceFrom(invocation.getWindowContext()),
- invocation.getContext(),
- invocation.getTarget(),
- new URLFormat(invocation.getSecurityContext().isSecure(), invocation.getSecurityContext().isAuthenticated(), true, true),
- consumer
- );
- }
- }
- else
- {
- // todo: need to deal with binary
- }
-
- String mimeType = markupContext.getMimeType();
- if (mimeType == null || mimeType.length() == 0)
- {
- return new ErrorResponse(new IllegalArgumentException("No MIME type was provided for portlet content."));
- }
-
- // generate appropriate CacheControl
- org.gatein.pc.api.cache.CacheControl cacheControl = createCacheControl(markupContext);
-
- return new FragmentResponse(null, null, mimeType, null, markup,
- markupContext.getPreferredTitle(), cacheControl, invocation.getPortalContext().getModes());
- }
-
protected void updateUserContext(Object request, UserContext userContext)
{
getRenderRequest(request).setUserContext(userContext);
@@ -188,62 +139,4 @@
throw new IllegalArgumentException("RenderHandler: Request is not a GetMarkup request!");
}
- static String processMarkup(String markup, String namespace, PortletInvocationContext context, org.gatein.pc.api.PortletContext target, URLFormat format, WSRPConsumer consumer)
- {
- // fix-me: how to deal with fragment header? => interceptor?
-
- // todo: remove, this is a work-around for GTNWSRP-12
- markup = markup.replaceFirst("%3ftimeout%3d.*%2f", "%2f");
-
- markup = TextTools.replaceBoundedString(
- markup,
- WSRPRewritingConstants.WSRP_REWRITE,
- WSRPRewritingConstants.END_WSRP_REWRITE,
- new MarkupProcessor(namespace, context, target, format, consumer.getProducerInfo()),
- true,
- false,
- true
- );
-
- return markup;
- }
-
- private org.gatein.pc.api.cache.CacheControl createCacheControl(MarkupContext markupContext)
- {
- CacheControl cacheControl = markupContext.getCacheControl();
- org.gatein.pc.api.cache.CacheControl result = DEFAULT_CACHE_CONTROL;
-
- int expires;
- if (cacheControl != null)
- {
- expires = cacheControl.getExpires();
- String userScope = cacheControl.getUserScope();
-
- // check that we support the user scope...
- if (consumer.supportsUserScope(userScope))
- {
- if (debug)
- {
- log.debug("RenderHandler.processRenderRequest: trying to cache markup " + userScope + " for " + expires + " seconds.");
- }
- CacheScope scope;
- if (WSRPConstants.CACHE_FOR_ALL.equals(userScope))
- {
- scope = CacheScope.PUBLIC;
- }
- else if (WSRPConstants.CACHE_PER_USER.equals(userScope))
- {
- scope = CacheScope.PRIVATE;
- }
- else
- {
- throw new IllegalArgumentException("Unknown CacheControl user scope: " + userScope); // should not happen
- }
-
- result = new org.gatein.pc.api.cache.CacheControl(expires, scope, cacheControl.getValidateTag());
- }
- }
-
- return result;
- }
}
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ResourceHandler.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ResourceHandler.java 2010-08-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ResourceHandler.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -23,37 +23,31 @@
package org.gatein.wsrp.consumer;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.ws.Holder;
-
import org.apache.commons.httpclient.Cookie;
import org.gatein.common.io.IOTools;
import org.gatein.common.net.media.MediaType;
import org.gatein.common.net.media.TypeDef;
import org.gatein.common.util.MultiValuedPropertyMap;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.common.util.Tools;
import org.gatein.pc.api.PortletInvokerException;
-import org.gatein.pc.api.cache.CacheScope;
+import org.gatein.pc.api.StateString;
import org.gatein.pc.api.invocation.PortletInvocation;
import org.gatein.pc.api.invocation.ResourceInvocation;
import org.gatein.pc.api.invocation.response.ContentResponse;
-import org.gatein.pc.api.invocation.response.ErrorResponse;
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
import org.gatein.pc.api.invocation.response.ResponseProperties;
-import org.gatein.wsrp.WSRPConstants;
+import org.gatein.pc.api.spi.InstanceContext;
+import org.gatein.pc.api.state.AccessMode;
import org.gatein.wsrp.WSRPResourceURL;
import org.gatein.wsrp.WSRPRewritingConstants;
import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.handler.CookieUtil;
import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
-import org.oasis.wsrp.v2.CacheControl;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.GetResource;
+import org.oasis.wsrp.v2.MarkupParams;
import org.oasis.wsrp.v2.PortletContext;
import org.oasis.wsrp.v2.ResourceContext;
import org.oasis.wsrp.v2.ResourceParams;
@@ -62,20 +56,38 @@
import org.oasis.wsrp.v2.SessionContext;
import org.oasis.wsrp.v2.UserContext;
+import javax.xml.ws.Holder;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
* @version $Revision$
*/
-public class ResourceHandler extends InvocationHandler
+public class ResourceHandler extends MimeResponseHandler<ResourceResponse, ResourceContext>
{
- private static final org.gatein.pc.api.cache.CacheControl DEFAULT_CACHE_CONTROL = new org.gatein.pc.api.cache.CacheControl(0, CacheScope.PRIVATE, null);
-
+
protected ResourceHandler(WSRPConsumerImpl consumer)
{
super(consumer);
}
@Override
+ protected SessionContext getSessionContextFrom(ResourceResponse resourceResponse)
+ {
+ return resourceResponse.getSessionContext();
+ }
+
+ @Override
+ protected ResourceContext getMimeResponseFrom(ResourceResponse resourceResponse)
+ {
+ return resourceResponse.getResourceContext();
+ }
+
+ @Override
protected void updateUserContext(Object request, UserContext userContext)
{
if (request instanceof GetResource)
@@ -97,9 +109,13 @@
protected RuntimeContext getRuntimeContextFrom(Object request)
{
if (request instanceof GetResource)
+ {
return getResourceRequest(request).getRuntimeContext();
+ }
else
+ {
return null;
+ }
}
@Override
@@ -109,17 +125,18 @@
{
throw new IllegalArgumentException("ResourceHandler can only handle ResourceInvocations!");
}
-
- ResourceInvocation resourceInvocation = (ResourceInvocation) invocation;
-
+
+ ResourceInvocation resourceInvocation = (ResourceInvocation)invocation;
+
String resourceInvocationId = resourceInvocation.getResourceId();
-
+
Map<String, String> resourceMap = WSRPResourceURL.decodeResource(resourceInvocationId);
-
+
String resourceId = resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID);
String resourceURL = resourceMap.get(WSRPRewritingConstants.RESOURCE_URL);
- String preferOperation = resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
-
+ String preferOperationAsString = resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
+ boolean preferOperation = (preferOperationAsString != null && Boolean.parseBoolean(preferOperationAsString));
+
int version = 1;
try
{
@@ -129,8 +146,8 @@
{
log.warn("Encountered an exception when trying to get the consumer's markup service's version, assuming WSRP 1.0 compliant.", portletInvokerException);
}
-
- if (version == 2 && resourceId != null && resourceId.length() > 0 && (preferOperation.equalsIgnoreCase("true") || resourceURL != null || resourceURL.isEmpty()))
+
+ if (version == 2 && (preferOperation || resourceURL == null || (resourceId != null && resourceId.length() > 0)))
{
return prepareGetResourceRequest(requestPrecursor, resourceInvocation, resourceId);
}
@@ -144,34 +161,48 @@
private GetResource prepareGetResourceRequest(RequestPrecursor requestPrecursor, ResourceInvocation invocation, String resourceId)
{
PortletContext portletContext = requestPrecursor.getPortletContext();
-
- ResourceParams resourceParams = new ResourceParams();
-
- resourceParams.setResourceID(resourceId);
-
- resourceParams.setClientData(requestPrecursor.markupParams.getClientData());
- resourceParams.setMode(requestPrecursor.markupParams.getMode());
- resourceParams.setNavigationalContext(requestPrecursor.markupParams.getNavigationalContext());
- resourceParams.setSecureClientCommunication(requestPrecursor.markupParams.isSecureClientCommunication());
- resourceParams.setValidateTag(requestPrecursor.markupParams.getValidateTag());
- resourceParams.setWindowState(requestPrecursor.markupParams.getWindowState());
-
- resourceParams.getMimeTypes().addAll(requestPrecursor.markupParams.getMimeTypes());
-
- //TODO
- //resourceParams.setPortletStateChange(...);
- //resourceParams.setResourceCacheability(...);
-
- if (invocation.getResourceState() != null)
+
+ // since we actually extracted the data into MarkupParams in the RequestPrecursor, use that! :)
+ MarkupParams params = requestPrecursor.markupParams;
+
+ // access mode
+ InstanceContext instanceContext = invocation.getInstanceContext();
+ ParameterValidation.throwIllegalArgExceptionIfNull(instanceContext, "instance context");
+ AccessMode accessMode = instanceContext.getAccessMode();
+ ParameterValidation.throwIllegalArgExceptionIfNull(accessMode, "access mode");
+ if (debug)
{
- resourceParams.setResourceState(invocation.getResourceState().getStringValue());
+ log.debug("Portlet is requesting " + accessMode + " access mode");
}
-
- GetResource getResource = WSRPTypeFactory.createResourceRequest(portletContext, requestPrecursor.runtimeContext, resourceParams);
-
- return getResource;
+
+ // if the portlet didn't request a resource id, use the fake one:
+ if (resourceId == null || resourceId.length() == 0)
+ {
+ resourceId = WSRPResourceURL.DEFAULT_RESOURCE_ID;
+ }
+
+ // Create ResourceParams
+ ResourceParams resourceParams = WSRPTypeFactory.createResourceParams(params.isSecureClientCommunication(),
+ params.getLocales(), params.getMimeTypes(), params.getMode(), params.getWindowState(), resourceId,
+ WSRPUtils.getStateChangeFromAccessMode(accessMode));
+
+ resourceParams.setNavigationalContext(params.getNavigationalContext());
+ resourceParams.setClientData(params.getClientData());
+ resourceParams.setResourceCacheability(WSRPUtils.getResourceCacheabilityFromCacheLevel(invocation.getCacheLevel()));
+
+ StateString resourceState = invocation.getResourceState();
+ if (resourceState != null)
+ {
+ String state = resourceState.getStringValue();
+ if (!StateString.JBPNS_PREFIX.equals(state)) // fix-me: see JBPORTAL-900
+ {
+ resourceParams.setResourceState(state);
+ }
+ }
+
+ return WSRPTypeFactory.createResourceRequest(portletContext, requestPrecursor.runtimeContext, resourceParams);
}
-
+
@Override
protected Object performRequest(Object request) throws Exception
{
@@ -191,20 +222,20 @@
}
private ResourceResponse performGetResourceRequest(GetResource getResource) throws Exception
- {
+ {
Holder<SessionContext> sessionContextHolder = new Holder<SessionContext>();
Holder<ResourceContext> resourceContextHolder = new Holder<ResourceContext>();
Holder<PortletContext> portletContextHolder = new Holder<PortletContext>(getResource.getPortletContext());
-
- consumer.getMarkupService().getResource(getResource.getRegistrationContext(), portletContextHolder, getResource.getRuntimeContext(),
- getResource.getUserContext(), getResource.getResourceParams(), resourceContextHolder, sessionContextHolder, new Holder<List<Extension>>());
-
+
+ consumer.getMarkupService().getResource(getResource.getRegistrationContext(), portletContextHolder, getResource.getRuntimeContext(),
+ getResource.getUserContext(), getResource.getResourceParams(), resourceContextHolder, sessionContextHolder, new Holder<List<Extension>>());
+
ResourceResponse resourceResponse = WSRPTypeFactory.createResourceResponse(resourceContextHolder.value);
resourceResponse.setPortletContext(portletContextHolder.value);
resourceResponse.setSessionContext(sessionContextHolder.value);
return resourceResponse;
}
-
+
private ContentResponse performURLRequest(String resourceURL) throws Exception
{
URL url = new URL(resourceURL);
@@ -276,85 +307,24 @@
return result;
}
-
+
@Override
protected PortletInvocationResponse processResponse(Object response, PortletInvocation invocation, RequestPrecursor requestPrecursor) throws PortletInvokerException
{
if (response instanceof ResourceResponse)
{
- return processGetResourceResponse((ResourceResponse)response, invocation, requestPrecursor);
+ return super.processResponse(response, invocation, requestPrecursor);
}
else if (response instanceof ContentResponse)
{
- return (ContentResponse) response;
+ return (ContentResponse)response;
}
else
{
throw new PortletInvokerException("Invalid response object: " + response + ". Expected either a " + ContentResponse.class + " or a " + ResourceResponse.class);
}
}
-
- private PortletInvocationResponse processGetResourceResponse(ResourceResponse resourceResponse, PortletInvocation invocation, RequestPrecursor requestPrecursor) throws PortletInvokerException
- {
- ResourceContext resourceContext = resourceResponse.getResourceContext();
-
- String chars = resourceContext.getItemString();
- byte[] binary = resourceContext.getItemBinary();
-
- ResponseProperties properties = null;
- Map<String, Object> attributes = null;
-
- String mimeType = resourceContext.getMimeType();
- if (mimeType == null || mimeType.length() == 0)
- {
- return new ErrorResponse(new IllegalArgumentException("No MIME type was provided for portlet content."));
- }
-
- // generate appropriate CacheControl
- org.gatein.pc.api.cache.CacheControl cacheControl = createCacheControl(resourceContext);
-
- return new ContentResponse(properties, attributes, mimeType, binary, chars, cacheControl);
- }
-
- private org.gatein.pc.api.cache.CacheControl createCacheControl(ResourceContext resourceContext)
- {
- CacheControl cacheControl = resourceContext.getCacheControl();
- org.gatein.pc.api.cache.CacheControl result = DEFAULT_CACHE_CONTROL;
- int expires;
- if (cacheControl != null)
- {
- expires = cacheControl.getExpires();
- String userScope = cacheControl.getUserScope();
-
- // check that we support the user scope...
- if (consumer.supportsUserScope(userScope))
- {
- if (debug)
- {
- log.debug("RenderHandler.processRenderRequest: trying to cache markup " + userScope + " for " + expires + " seconds.");
- }
- CacheScope scope;
- if (WSRPConstants.CACHE_FOR_ALL.equals(userScope))
- {
- scope = CacheScope.PUBLIC;
- }
- else if (WSRPConstants.CACHE_PER_USER.equals(userScope))
- {
- scope = CacheScope.PRIVATE;
- }
- else
- {
- throw new IllegalArgumentException("Unknown CacheControl user scope: " + userScope); // should not happen
- }
-
- result = new org.gatein.pc.api.cache.CacheControl(expires, scope, cacheControl.getValidateTag());
- }
- }
-
- return result;
- }
-
private GetResource getResourceRequest(Object request)
{
if (request instanceof GetResource)
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupHandler.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupHandler.java 2010-08-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupHandler.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -138,7 +138,7 @@
checkForError(response);
- return requestProcessor.processResponse(response);
+ return (ResourceResponse)requestProcessor.processResponse(response);
}
public BlockingInteractionResponse performBlockingInteraction(PerformBlockingInteraction performBlockingInteraction)
Added: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MimeResponseProcessor.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MimeResponseProcessor.java (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MimeResponseProcessor.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.gatein.wsrp.producer;
+
+import org.gatein.common.net.URLTools;
+import org.gatein.pc.api.invocation.response.ContentResponse;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPRewritingConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.servlet.ServletAccess;
+import org.oasis.wsrp.v2.MimeResponse;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public abstract class MimeResponseProcessor<LocalMimeResponse extends MimeResponse> extends RequestProcessor
+{
+ protected String namespace;
+ private static final String EMPTY = "";
+
+ protected MimeResponseProcessor(WSRPProducerImpl producer)
+ {
+ super(producer);
+ }
+
+ /**
+ * Process String returned from RenderResult to add rewriting token if necessary, replacing namespaces by the WSRP
+ * rewrite token. fix-me: need to check for producer rewriting
+ *
+ * @param renderString the String to be processed for rewriting marking
+ * @return a String processed to add rewriting tokens as necessary
+ */
+ protected String processFragmentString(String renderString)
+ {
+ String result = renderString.replaceAll(namespace, WSRPRewritingConstants.WSRP_REWRITE_TOKEN);
+
+ result = URLTools.replaceURLsBy(result, new WSRPUtils.AbsoluteURLReplacementGenerator(ServletAccess.getRequest()));
+ return result;
+ }
+
+ Object processResponse(PortletInvocationResponse response)
+ {
+ ContentResponse content = (ContentResponse)response;
+ String itemString = null;
+ byte[] itemBinary = null;
+ String contentType = content.getContentType();
+ switch (content.getType())
+ {
+ case ContentResponse.TYPE_CHARS:
+ itemString = processFragmentString(content.getChars());
+ break;
+ case ContentResponse.TYPE_BYTES:
+ itemBinary = content.getBytes(); // fix-me: might need to convert to Base64?
+ break;
+ case ContentResponse.TYPE_EMPTY:
+ itemString = EMPTY;
+ contentType = markupRequest.getMediaType(); // assume we got what we asked for :)
+ break;
+ }
+
+ LocalMimeResponse mimeResponse = WSRPTypeFactory.createMimeResponse(contentType, itemString, itemBinary, getReifiedClass());
+
+ mimeResponse.setLocale(markupRequest.getLocale());
+
+ //TODO: figure out requiresRewriting and useCachedItem
+ Boolean requiresRewriting = true;
+ Boolean useCachedItem = false;
+ mimeResponse.setRequiresRewriting(requiresRewriting);
+ mimeResponse.setUseCachedItem(useCachedItem);
+
+ //TODO: check if anything actually uses the ccpp profile warning
+ String ccppProfileWarning = null;
+ mimeResponse.setCcppProfileWarning(ccppProfileWarning);
+
+ // cache information
+ int expires = content.getCacheControl().getExpirationSecs();
+ // only create a CacheControl if expiration time is not 0
+ if (expires != 0)
+ {
+ // if expires is negative, replace by -1 to make sure
+ if (expires < 0)
+ {
+ expires = -1;
+ }
+
+ mimeResponse.setCacheControl(WSRPTypeFactory.createCacheControl(expires, WSRPConstants.CACHE_PER_USER));
+ }
+
+ additionallyProcessIfNeeded(mimeResponse, response);
+
+ return createResponse(mimeResponse);
+ }
+
+ protected abstract Object createResponse(LocalMimeResponse mimeResponse);
+
+ protected abstract Class<LocalMimeResponse> getReifiedClass();
+
+ protected void additionallyProcessIfNeeded(LocalMimeResponse mimeResponse, PortletInvocationResponse response)
+ {
+ // default implementation does nothing
+ }
+}
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RenderRequestProcessor.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RenderRequestProcessor.java 2010-08-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RenderRequestProcessor.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -23,23 +23,16 @@
package org.gatein.wsrp.producer;
-import org.gatein.common.net.URLTools;
import org.gatein.pc.api.invocation.PortletInvocation;
import org.gatein.pc.api.invocation.RenderInvocation;
-import org.gatein.pc.api.invocation.response.FragmentResponse;
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
import org.gatein.pc.api.state.AccessMode;
import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
-import org.gatein.wsrp.WSRPConstants;
-import org.gatein.wsrp.WSRPRewritingConstants;
import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.servlet.ServletAccess;
import org.oasis.wsrp.v2.GetMarkup;
import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.InvalidRegistration;
import org.oasis.wsrp.v2.MarkupContext;
-import org.oasis.wsrp.v2.MarkupParams;
import org.oasis.wsrp.v2.MimeRequest;
import org.oasis.wsrp.v2.MissingParameters;
import org.oasis.wsrp.v2.OperationFailed;
@@ -55,11 +48,9 @@
* @version $Revision: 13121 $
* @since 2.6
*/
-public class RenderRequestProcessor extends RequestProcessor
+public class RenderRequestProcessor extends MimeResponseProcessor<MarkupContext>
{
- private static final String EMPTY = "";
private final GetMarkup getMarkup;
- private String namespace;
public RenderRequestProcessor(WSRPProducerImpl producer, GetMarkup getMarkup) throws UnsupportedMimeType,
UnsupportedWindowState, InvalidHandle, UnsupportedMode, MissingParameters, InvalidRegistration, OperationFailed
@@ -104,6 +95,7 @@
return AccessMode.READ_ONLY;
}
+ @Override
PortletInvocation initInvocation(WSRPPortletInvocationContext context)
{
// MUST match namespace generation used in PortletResponseImpl.getNamespace in portlet module...
@@ -112,67 +104,21 @@
return new RenderInvocation(context);
}
- Object processResponse(PortletInvocationResponse response)
+ @Override
+ protected Object createResponse(MarkupContext mimeResponse)
{
- FragmentResponse fragment = (FragmentResponse)response;
- String markupString = null;
- byte[] markupBinary = null;
- switch (fragment.getType())
- {
- case FragmentResponse.TYPE_CHARS:
- markupString = processFragmentString(fragment.getChars());
- break;
- case FragmentResponse.TYPE_BYTES:
- markupBinary = fragment.getBytes(); // fix-me: might need to convert to Base64?
- break;
- case FragmentResponse.TYPE_EMPTY:
- markupString = EMPTY;
- break;
- }
-
-
- MarkupContext markupContext;
- if (markupString != null)
- {
- markupContext = WSRPTypeFactory.createMarkupContext(markupRequest.getMediaType(), markupString);
- }
- else
- {
- markupContext = WSRPTypeFactory.createMarkupContext(markupRequest.getMediaTypeWithCharset(), markupBinary);
- }
- markupContext.setLocale(markupRequest.getLocale());
- markupContext.setRequiresRewriting(Boolean.TRUE);
- markupContext.setPreferredTitle(portletDescription.getTitle().getValue());
-
- // cache information
- int expires = fragment.getCacheControl().getExpirationSecs();
- // only create a CacheControl if expiration time is not 0
- if (expires != 0)
- {
- // if expires is negative, replace by -1 to make sure
- if (expires < 0)
- {
- expires = -1;
- }
-
- markupContext.setCacheControl(WSRPTypeFactory.createCacheControl(expires, WSRPConstants.CACHE_PER_USER));
- }
-
- return WSRPTypeFactory.createMarkupResponse(markupContext);
+ return WSRPTypeFactory.createMarkupResponse(mimeResponse);
}
- /**
- * Process String returned from RenderResult to add rewriting token if necessary, replacing namespaces by the WSRP
- * rewrite token. fix-me: need to check for producer rewriting
- *
- * @param renderString the String to be processed for rewriting marking
- * @return a String processed to add rewriting tokens as necessary
- */
- private String processFragmentString(String renderString)
+ @Override
+ protected Class<MarkupContext> getReifiedClass()
{
- String result = renderString.replaceAll(namespace, WSRPRewritingConstants.WSRP_REWRITE_TOKEN);
+ return MarkupContext.class;
+ }
- result = URLTools.replaceURLsBy(result, new WSRPUtils.AbsoluteURLReplacementGenerator(ServletAccess.getRequest()));
- return result;
+ @Override
+ protected void additionallyProcessIfNeeded(MarkupContext markupContext, PortletInvocationResponse response)
+ {
+ markupContext.setPreferredTitle(portletDescription.getTitle().getValue());
}
}
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ResourceRequestProcessor.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ResourceRequestProcessor.java 2010-08-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ResourceRequestProcessor.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -1,57 +1,44 @@
-/******************************************************************************
- * 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.gatein.wsrp.producer;
-import org.gatein.common.NotYetImplemented;
-import org.gatein.common.net.URLTools;
-import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.cache.CacheLevel;
import org.gatein.pc.api.invocation.PortletInvocation;
import org.gatein.pc.api.invocation.ResourceInvocation;
-import org.gatein.pc.api.invocation.response.ContentResponse;
-import org.gatein.pc.api.invocation.response.FragmentResponse;
-import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
import org.gatein.pc.api.state.AccessMode;
import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
-import org.gatein.wsrp.WSRPConstants;
-import org.gatein.wsrp.WSRPRewritingConstants;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.servlet.ServletAccess;
-import org.oasis.wsrp.v2.CacheControl;
import org.oasis.wsrp.v2.GetResource;
import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.MarkupParams;
import org.oasis.wsrp.v2.MimeRequest;
import org.oasis.wsrp.v2.MissingParameters;
import org.oasis.wsrp.v2.OperationFailed;
import org.oasis.wsrp.v2.PortletContext;
-import org.oasis.wsrp.v2.PortletDescription;
import org.oasis.wsrp.v2.RegistrationContext;
import org.oasis.wsrp.v2.ResourceContext;
import org.oasis.wsrp.v2.ResourceParams;
-import org.oasis.wsrp.v2.ResourceResponse;
import org.oasis.wsrp.v2.RuntimeContext;
import org.oasis.wsrp.v2.UnsupportedMimeType;
import org.oasis.wsrp.v2.UnsupportedMode;
@@ -59,18 +46,13 @@
import org.oasis.wsrp.v2.UserContext;
/**
- *
* @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
* @version $Revision$
*/
-public class ResourceRequestProcessor extends RequestProcessor
+public class ResourceRequestProcessor extends MimeResponseProcessor<ResourceContext>
{
-
- private static final String EMPTY = "";
-
private final GetResource getResource;
- private String namespace;
-
+
public ResourceRequestProcessor(WSRPProducerImpl producer, GetResource getResource) throws InvalidRegistration, OperationFailed, MissingParameters, InvalidHandle, UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode
{
super(producer);
@@ -78,88 +60,11 @@
prepareInvocation();
}
- public PortletInvocation getInvocation()
- {
- return invocation;
- }
-
public PortletContext getPortletContext()
{
return getResource.getPortletContext();
}
- public ResourceResponse processResponse(PortletInvocationResponse response)
- {
- ContentResponse content = (ContentResponse)response;
- String resourceString = null;
- byte[] resourceBinary = null;
- switch (content.getType())
- {
- case ContentResponse.TYPE_CHARS:
- resourceString = processFragmentString(content.getChars());
- break;
- case ContentResponse.TYPE_BYTES:
- resourceBinary = content.getBytes(); // fix-me: might need to convert to Base64?
- break;
- case ContentResponse.TYPE_EMPTY:
- resourceString = EMPTY;
- break;
- }
-
- ResourceContext resourceContext;
- if (resourceString != null)
- {
- resourceContext = WSRPTypeFactory.createResourceContext(content.getContentType(), resourceString);
- }
- else
- {
- resourceContext = WSRPTypeFactory.createResourceContext(content.getContentType(), resourceBinary);
- }
-
- resourceContext.setLocale(markupRequest.getLocale());
-
- //TODO: figure out requiresRewriting and useCachedItem
- Boolean requiresRewriting = false;
- Boolean useCachedItem = false;
- resourceContext.setRequiresRewriting(requiresRewriting);
- resourceContext.setUseCachedItem(useCachedItem);
-
- //TODO: check if anything actually uses the ccpp profile warning
- String ccppProfileWarning = null;
- resourceContext.setCcppProfileWarning(ccppProfileWarning);
-
- // cache information
- int expires = content.getCacheControl().getExpirationSecs();
- // only create a CacheControl if expiration time is not 0
- if (expires != 0)
- {
- // if expires is negative, replace by -1 to make sure
- if (expires < 0)
- {
- expires = -1;
- }
-
- resourceContext.setCacheControl(WSRPTypeFactory.createCacheControl(expires, WSRPConstants.CACHE_PER_USER));
- }
-
- return WSRPTypeFactory.createResourceResponse(resourceContext);
- }
-
- /**
- * Process String returned from RenderResult to add rewriting token if necessary, replacing namespaces by the WSRP
- * rewrite token. fix-me: need to check for producer rewriting
- *
- * @param renderString the String to be processed for rewriting marking
- * @return a String processed to add rewriting tokens as necessary
- */
- private String processFragmentString(String renderString)
- {
- String result = renderString.replaceAll(namespace, WSRPRewritingConstants.WSRP_REWRITE_TOKEN);
-
- result = URLTools.replaceURLsBy(result, new WSRPUtils.AbsoluteURLReplacementGenerator(ServletAccess.getRequest()));
- return result;
- }
-
@Override
AccessMode getAccessMode() throws MissingParameters
{
@@ -177,7 +82,7 @@
{
return getResource.getResourceParams();
}
-
+
@Override
RegistrationContext getRegistrationContext()
{
@@ -202,28 +107,46 @@
// MUST match namespace generation used in PortletResponseImpl.getNamespace in portlet module...
namespace = PortletUtils.generateNamespaceFrom(context.getWindowContext().getId());
ResourceInvocation resourceInvocation = new ResourceInvocation(context);
-
+
ResourceParams resourceParams = this.getResource.getResourceParams();
-
+
resourceInvocation.setResourceId(this.getResource.getResourceParams().getResourceID());
-
+
WSRPRequestContext requestContext = WSRPRequestContext.createRequestContext(markupRequest, resourceParams);
resourceInvocation.setRequestContext(requestContext);
resourceInvocation.setForm(requestContext.getForm());
-
+
//TODO: property set validation token for caching (ie ETAG)
String validationToken = null;
resourceInvocation.setValidationToken(validationToken);
-
- resourceInvocation.setResourceState(createNavigationalState(resourceParams.getResourceState()));
-
- if (resourceParams.getResourceCacheability() != null)
+
+ resourceInvocation.setResourceState(createNavigationalState(resourceParams.getResourceState()));
+
+ String resourceCacheability = resourceParams.getResourceCacheability();
+ if (resourceCacheability != null)
{
- CacheLevel cacheLevel = CacheLevel.valueOf(resourceParams.getResourceCacheability());
+ CacheLevel cacheLevel = WSRPUtils.getCacheLevelFromResourceCacheability(resourceParams.getResourceCacheability());
resourceInvocation.setCacheLevel(cacheLevel);
}
-
+ else
+ {
+ // according to JSR 286, cache level must default to ResourceURL.PAGE
+ resourceInvocation.setCacheLevel(CacheLevel.PAGE);
+ }
+
return resourceInvocation;
}
+
+ @Override
+ protected Object createResponse(ResourceContext resourceContext)
+ {
+ return WSRPTypeFactory.createResourceResponse(resourceContext);
+ }
+
+ @Override
+ protected Class<ResourceContext> getReifiedClass()
+ {
+ return ResourceContext.class;
+ }
}
Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPPortletInvocationContext.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPPortletInvocationContext.java 2010-08-06 15:14:27 UTC (rev 3766)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPPortletInvocationContext.java 2010-08-06 19:39:29 UTC (rev 3767)
@@ -37,7 +37,6 @@
import org.gatein.pc.portlet.impl.spi.AbstractPortletInvocationContext;
import org.gatein.pc.portlet.impl.spi.AbstractServerContext;
import org.gatein.wsrp.WSRPPortletURL;
-import org.gatein.wsrp.WSRPResourceURL;
import org.gatein.wsrp.WSRPRewritingConstants;
import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.servlet.ServletAccess;
@@ -133,10 +132,6 @@
Boolean wantSecureBool = urlFormat.getWantSecure();
boolean wantSecure = (wantSecureBool != null ? wantSecureBool : false);
WSRPPortletURL url = WSRPPortletURL.create(containerURL, wantSecure);
- if (url instanceof WSRPResourceURL)
- {
- WSRPResourceURL resourceURL = (WSRPResourceURL)url;
- }
return url.toString();
}
return null;
13 years, 11 months
gatein SVN: r3766 - components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2.
by do-not-reply@jboss.org
Author: mwringe
Date: 2010-08-06 11:14:27 -0400 (Fri, 06 Aug 2010)
New Revision: 3766
Added:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/V2ProducerBaseTest.java
Log:
GTNWSRP-46: Create MarkupTestCase for WSRP 2.
Added: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java (rev 0)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java 2010-08-06 15:14:27 UTC (rev 3766)
@@ -0,0 +1,870 @@
+/******************************************************************************
+ * 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.Collections;
+import java.util.List;
+import java.util.Locale;
+
+import org.gatein.pc.api.ParametersStateString;
+import org.gatein.pc.api.StateString;
+import org.gatein.wsrp.WSRPActionURL;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPPortletURL;
+import org.gatein.wsrp.WSRPRenderURL;
+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.BlockingInteractionResponse;
+import org.oasis.wsrp.v2.CacheControl;
+import org.oasis.wsrp.v2.GetMarkup;
+import org.oasis.wsrp.v2.InitCookie;
+import org.oasis.wsrp.v2.InteractionParams;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.MarkupContext;
+import org.oasis.wsrp.v2.MarkupResponse;
+import org.oasis.wsrp.v2.NamedString;
+import org.oasis.wsrp.v2.NavigationalContext;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PerformBlockingInteraction;
+import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.RuntimeContext;
+import org.oasis.wsrp.v2.SessionContext;
+import org.oasis.wsrp.v2.SessionParams;
+import org.oasis.wsrp.v2.StateChange;
+import org.oasis.wsrp.v2.UnsupportedMode;
+import org.oasis.wsrp.v2.UpdateResponse;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+(a)RunWith(Arquillian.class)
+public class MarkupTestCase extends org.gatein.wsrp.protocol.v2.NeedPortletHandleTest
+{
+ private static final String DEFAULT_VIEW_MARKUP = "<p>symbol unset stock value: value unset</p>";
+ private static final String DEFAULT_MARKUP_PORTLET_WAR = "test-markup-portlet.war";
+
+ public MarkupTestCase()
+ throws Exception
+ {
+ super("MarkupTestCase", DEFAULT_MARKUP_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();
+ }
+ }
+
+ @Test
+ public void testGetMarkupViewNoSession() throws Exception
+ {
+ GetMarkup getMarkup = createMarkupRequest();
+
+ MarkupResponse response = producer.getMarkup(getMarkup);
+
+ checkMarkupResponse(response, DEFAULT_VIEW_MARKUP);
+ }
+
+ @Test
+ public void testInvalidGetMarkup() throws Exception
+ {
+ GetMarkup getMarkup = createMarkupRequest();
+ getMarkup.getMarkupParams().setMode("invalid mode");
+
+ try
+ {
+ producer.getMarkup(getMarkup);
+ ExtendedAssert.fail();
+ }
+ catch (UnsupportedMode unsupportedMode)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetMarkupWithSessionID() throws Exception
+ {
+ // The consumer should never have access to or be able to set a sessionID. Sessions are handled by the Producer using cookies.
+ GetMarkup getMarkup = createMarkupRequest();
+ SessionParams sessionParams = new SessionParams();
+ sessionParams.setSessionID("Hello World");
+ getMarkup.getRuntimeContext().setSessionParams(sessionParams);
+
+ try
+ {
+ producer.getMarkup(getMarkup);
+ ExtendedAssert.fail("A sessionID should not be allowed to be passed in GetMarkup()");
+ }
+ catch (OperationFailed operationFailed)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetMarkupEditNoSession() throws Exception
+ {
+ GetMarkup getMarkup = createMarkupRequest();
+ getMarkup.getMarkupParams().setMode(WSRPConstants.EDIT_MODE);
+
+ MarkupResponse response = producer.getMarkup(getMarkup);
+
+ checkMarkupResponse(response, "<form method='post' action='wsrp_rewrite?wsrp-urlType=blockingAction&wsrp" +
+ "-interactionState=JBPNS_/wsrp_rewrite' id='wsrp_rewrite_portfolioManager'><table><tr><td>Stock symbol</t" +
+ "d><td><input name='symbol'/></td></tr><tr><td><input type='submit' value='Submit'></td></tr></table></form>");
+ }
+
+ @Test
+ public void testGetMarkupRenderParameters() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String archiveName = "test-renderparam-portlet.war";
+ deploy(archiveName);
+
+ try
+ {
+ GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+ MarkupResponse res = producer.getMarkup(gm);
+
+ String markupString = res.getMarkupContext().getItemString();
+
+ String julienLink = extractLink(markupString, 0);
+ WSRPPortletURL julienURL = WSRPPortletURL.create(julienLink);
+
+ ExtendedAssert.assertString1ContainsString2(markupString, "Hello, Anonymous!");
+ ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 0");
+
+ ExtendedAssert.assertTrue(julienURL instanceof WSRPRenderURL);
+ WSRPRenderURL julienRender = (WSRPRenderURL)julienURL;
+
+ // We're now trying to get a hello for Julien ;)
+ NavigationalContext navigationalContext = new NavigationalContext();
+ navigationalContext.setOpaqueValue(julienRender.getNavigationalState().getStringValue());
+ gm.getMarkupParams().setNavigationalContext(navigationalContext);
+ res = producer.getMarkup(gm);
+ markupString = res.getMarkupContext().getItemString();
+ ExtendedAssert.assertString1ContainsString2(markupString, "Hello, Julien!");
+
+ // julien.length() * 2 to bypass second link
+ WSRPPortletURL incrementURL = WSRPPortletURL.create(extractLink(markupString, julienLink.length() * 2));
+ ExtendedAssert.assertTrue(incrementURL instanceof WSRPActionURL);
+ WSRPActionURL incrementAction = (WSRPActionURL)incrementURL;
+
+ // let's see now if we can increment the counter
+ PerformBlockingInteraction performBlockingInteraction =
+ WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+ InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
+ interactionParams.setInteractionState(incrementAction.getInteractionState().getStringValue());
+ producer.performBlockingInteraction(performBlockingInteraction);
+ res = producer.getMarkup(gm);
+ markupString = res.getMarkupContext().getItemString();
+ ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 1");
+ }
+ finally
+ {
+ undeploy(archiveName);
+ }
+ }
+
+ private String extractLink(String markupString, int fromIndex)
+ {
+ int urlStartIndex = markupString.indexOf("='", fromIndex);
+ int urlEndIndex = markupString.indexOf("'>", urlStartIndex);
+ return markupString.substring(urlStartIndex + 2, urlEndIndex);
+ }
+
+ // fix-me: add more tests
+ @Test
+ public void testGetMarkupSession() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ // deploy session-manipulating portlet
+ String sessionPortletArchive = "test-session-portlet.war";
+ deploy(sessionPortletArchive);
+
+
+ try
+ {
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+
+ MarkupResponse response = producer.getMarkup(getMarkup);
+
+ checkMarkupResponseWithSession(response, 0);
+
+ response = producer.getMarkup(getMarkup);
+ checkMarkupResponseWithSession(response, 1);
+
+ // fix-me: try to reuse the old session id: what should happen?
+ // runtimeContext.setSessionID(sessionID);
+ // getMarkup.setRuntimeContext(runtimeContext);
+ // try
+ // {
+ // producer.getMarkup(getMarkup);
+ // fail("The session should be invalid...");
+ // }
+ // catch (InvalidSessionFault expected)
+ // {
+ // }
+ }
+ finally
+ {
+ // reset state
+ undeploy(sessionPortletArchive);
+ }
+ }
+
+ @Test
+ public void testPerformBlockingInteractionNoRedirect() throws Exception
+ {
+ checkPBIAndGetNavigationalState("RHAT");
+ }
+
+ @Test
+ public void testPerformBlockingInteractionRedirect() throws Exception
+ {
+ PerformBlockingInteraction performBlockingInteraction =
+ WSRPTypeFactory.createDefaultPerformBlockingInteraction(getDefaultHandle());
+ InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
+
+ // crappy way but this is a test! ;)
+ NamedString namedString = new NamedString();
+ namedString.setName("symbol");
+ namedString.setValue("HELP");
+ interactionParams.getFormParameters().add(namedString);
+
+ BlockingInteractionResponse response = producer.performBlockingInteraction(performBlockingInteraction);
+ ExtendedAssert.assertNotNull(response);
+
+ // this is a redirect...
+ String redirectURL = response.getRedirectURL();
+ ExtendedAssert.assertNotNull(redirectURL);
+ ExtendedAssert.assertEquals("/WEB-INF/jsp/help.jsp", redirectURL); // fix-me: handle URL re-writing
+
+ // no update response
+ UpdateResponse updateResponse = response.getUpdateResponse();
+ ExtendedAssert.assertNull(updateResponse);
+ }
+
+ @Test
+ public void testGMAndPBIInteraction() throws Exception
+ {
+ testGetMarkupViewNoSession();
+ String symbol = "AAPL";
+ String navigationalState = checkPBIAndGetNavigationalState(symbol);
+
+ GetMarkup getMarkup = createMarkupRequest();
+ NavigationalContext navigationalContext = WSRPTypeFactory.createNavigationalContextOrNull(StateString.create(navigationalState), null);
+ getMarkup.getMarkupParams().setNavigationalContext(navigationalContext);
+ MarkupResponse response = producer.getMarkup(getMarkup);
+ checkMarkupResponse(response, "<p>" + symbol + " stock value: 123.45</p>");
+ }
+
+ @Test
+ public void testPBIWithSessionID() throws Exception
+ {
+ String portletHandle = getDefaultHandle();
+ PerformBlockingInteraction performBlockingInteraction = WSRPTypeFactory.createDefaultPerformBlockingInteraction(portletHandle);
+
+ RuntimeContext runtimeContext = performBlockingInteraction.getRuntimeContext();
+ //the sessionID should never be set by the consumer. Sessions are handled by cookies instead
+ SessionParams sessionParams = new SessionParams();
+ sessionParams.setSessionID("Hello World");
+ runtimeContext.setSessionParams(sessionParams);
+
+ try
+ {
+ producer.performBlockingInteraction(performBlockingInteraction);
+ ExtendedAssert.fail("Should not be able to pass a sessionID in a PerformBlockingInteraction()");
+ }
+ catch (OperationFailed expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testMarkupCaching() throws Exception
+ {
+ GetMarkup getMarkup = createMarkupRequest();
+
+ MarkupResponse response = producer.getMarkup(getMarkup);
+
+ CacheControl cacheControl = response.getMarkupContext().getCacheControl();
+ ExtendedAssert.assertNotNull(cacheControl);
+ ExtendedAssert.assertEquals(WSRPConstants.CACHE_PER_USER, cacheControl.getUserScope());
+ ExtendedAssert.assertEquals(15, cacheControl.getExpires());
+
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String sessionPortletArchive = "test-session-portlet.war";
+ deploy(sessionPortletArchive);
+
+ response = producer.getMarkup(createMarkupRequestForCurrentlyDeployedPortlet());
+
+ cacheControl = response.getMarkupContext().getCacheControl();
+ ExtendedAssert.assertNull(cacheControl);
+
+ undeploy(sessionPortletArchive);
+ }
+
+ @Test
+ public void testGetMarkupWithDispatcherPortlet() throws Exception
+ {
+
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String dispatcherPortletArchive = "test-dispatcher-portlet.war";
+ deploy(dispatcherPortletArchive);
+
+ try
+ {
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+
+ MarkupResponse response = producer.getMarkup(getMarkup);
+ checkMarkupResponse(response, "test");
+ }
+ finally
+ {
+ undeploy(dispatcherPortletArchive);
+ }
+ }
+
+ @Test
+ public void testGetMarkupWithNoContent() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String basicPortletArchive = "test-basic-portlet.war";
+ deploy(basicPortletArchive);
+
+ try
+ {
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+
+ MarkupResponse response = producer.getMarkup(getMarkup);
+ checkMarkupResponse(response, "");
+ }
+ finally
+ {
+ undeploy(basicPortletArchive);
+ }
+ }
+
+ @Test
+ public void testGetMarkupWithNonStandardLocalesStrictMode() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String getLocalesPortletArchive = "test-getlocales-portlet.war";
+ deploy(getLocalesPortletArchive);
+
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+ // we need to clear the value first for this test since the getLocales will be populated
+ // with default values for the system, and since en_US is not marked as a supported-locale in portlet.xml
+ // the default values will be used.
+ getMarkup.getMarkupParams().getLocales().clear();
+ getMarkup.getMarkupParams().getLocales().add("en_US");
+
+ try
+ {
+ producer.getMarkup(getMarkup);
+ //fail("Should have thrown an UnsupportetLocaleFault"); // ideally cf http://jira.jboss.com/jira/browse/JBPORTAL-857
+ ExtendedAssert.fail("Should have thrown an exception"); // right now
+ }
+ catch (Exception expected)
+ {
+ // expected
+ }
+ finally
+ {
+ // checkMarkupResponse(response, "GetLocalesPortlet"); // should we return try to generate markup regardless?
+ undeploy(getLocalesPortletArchive);
+ }
+ }
+
+ @Test
+ public void testGetMarkupWithNonStandardLocalesLenientMode() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String getLocalesPortletArchive = "test-getlocales-portlet.war";
+ deploy(getLocalesPortletArchive);
+
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+ // we need to clear the value first for this test since the getLocales will be populated
+ // with default values for the system, and since en_US is not marked as a supported-locale in portlet.xml
+ // the default values will be used.
+ getMarkup.getMarkupParams().getLocales().clear();
+ getMarkup.getMarkupParams().getLocales().add("en_US");
+
+ // Use the lenient mode
+ producer.usingStrictModeChangedTo(false);
+
+ // markup should be properly generated
+ checkMarkupResponse(producer.getMarkup(getMarkup), "English (United States)");
+ undeploy(getLocalesPortletArchive);
+ }
+
+ @Test
+ public void testGetMarkupWithoutDeclaredLocale() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String getLocalesPortletArchive = "test-getlocales-portlet.war";
+ deploy(getLocalesPortletArchive);
+
+ GetMarkup getMarkup = createMarkupRequest(getPortletHandleFrom("No Declared"));
+
+ try
+ {
+ checkMarkupResponse(producer.getMarkup(getMarkup), Locale.getDefault().getDisplayName());
+ }
+ finally
+ {
+ undeploy(getLocalesPortletArchive);
+ }
+ }
+
+ @Test
+ public void testGetMarkupLocales() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String getLocalesPortletArchive = "test-getlocales-portlet.war";
+ deploy(getLocalesPortletArchive);
+
+ GetMarkup getMarkup = createMarkupRequest(getPortletHandleFrom("Simple"));
+
+ try
+ {
+ List<String> locales = getMarkup.getMarkupParams().getLocales();
+ locales.add("en");
+ locales.add("fr");
+ MarkupResponse response = producer.getMarkup(getMarkup);
+ checkMarkupResponse(response, Locale.ENGLISH.getDisplayName());
+
+ locales.clear();
+ locales.add("fr");
+ locales.add("en");
+ response = producer.getMarkup(getMarkup);
+ checkMarkupResponse(response, Locale.FRENCH.getDisplayName());
+
+ locales.clear();
+ locales.add("de");
+ locales.add("en");
+ response = producer.getMarkup(getMarkup);
+ checkMarkupResponse(response, Locale.ENGLISH.getDisplayName());
+ }
+ finally
+ {
+ undeploy(getLocalesPortletArchive);
+ }
+ }
+
+ @Test
+ public void testGetMarkupWithEncodedURLs() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String encodeURLPortletArchive = "test-encodeurl-portlet.war";
+ deploy(encodeURLPortletArchive);
+
+ try
+ {
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+
+ MarkupResponse response = producer.getMarkup(getMarkup);
+ checkMarkupResponse(response, "wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite\n" +
+ "wsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewrite");
+ }
+ finally
+ {
+ undeploy(encodeURLPortletArchive);
+ }
+ }
+
+ @Test
+ public void testGetMarkupWithUserContext() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String userContextPortletArchive = "test-usercontext-portlet.war";
+ deploy(userContextPortletArchive);
+
+ try
+ {
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+ getMarkup.setUserContext(WSRPTypeFactory.createUserContext("johndoe"));
+
+ MarkupResponse response = producer.getMarkup(getMarkup);
+ checkMarkupResponse(response, "user: johndoe");
+ }
+ finally
+ {
+ undeploy(userContextPortletArchive);
+ }
+ }
+
+ @Test
+ public void testGetMarkupMultiValuedFormParams() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String multiValuedPortletArchive = "test-multivalued-portlet.war";
+ deploy(multiValuedPortletArchive);
+
+ NamedString namedString = createNamedString("multi", "value1");
+ try
+ {
+ PerformBlockingInteraction action =
+ WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+ List<NamedString> formParameters = action.getInteractionParams().getFormParameters();
+ formParameters.add(namedString);
+ BlockingInteractionResponse actionResponse = producer.performBlockingInteraction(action);
+ GetMarkup markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
+ markupRequest.getMarkupParams().setNavigationalContext(actionResponse.getUpdateResponse().getNavigationalContext());
+ MarkupResponse response = producer.getMarkup(markupRequest);
+ checkMarkupResponse(response, "multi: value1");
+
+ formParameters.clear();
+ formParameters.add(namedString);
+ formParameters.add(createNamedString("multi", "value2"));
+ actionResponse = producer.performBlockingInteraction(action);
+ markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
+ markupRequest.getMarkupParams().setNavigationalContext(actionResponse.getUpdateResponse().getNavigationalContext());
+ response = producer.getMarkup(markupRequest);
+ checkMarkupResponse(response, "multi: value1, value2");
+
+ formParameters.clear();
+ formParameters.add(new NamedString());
+ actionResponse = producer.performBlockingInteraction(action);
+ markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
+ markupRequest.getMarkupParams().setNavigationalContext(actionResponse.getUpdateResponse().getNavigationalContext());
+ response = producer.getMarkup(markupRequest);
+ checkMarkupResponse(response, "multi: ");
+ }
+ finally
+ {
+ undeploy(multiValuedPortletArchive);
+ }
+ }
+
+ @Test
+ public void testImplicitCloning() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String archiveName = "test-implicitcloning-portlet.war";
+ deploy(archiveName);
+
+ try
+ {
+ // check the initial value
+ GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+ MarkupResponse res = producer.getMarkup(gm);
+ String markupString = res.getMarkupContext().getItemString();
+ ExtendedAssert.assertEquals("initial", markupString);
+
+ // modify the preference value
+ PerformBlockingInteraction pbi = WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+ pbi.getInteractionParams().setPortletStateChange(StateChange.CLONE_BEFORE_WRITE); // request cloning if needed
+ String value = "new value";
+ pbi.getInteractionParams().getFormParameters().add(createNamedString("value", value));
+ BlockingInteractionResponse response = producer.performBlockingInteraction(pbi);
+ ExtendedAssert.assertNotNull(response);
+
+ // check that we got a new portlet context
+ PortletContext pc = response.getUpdateResponse().getPortletContext();
+ ExtendedAssert.assertNotNull(pc);
+
+ // get the markup again and check that we still get the initial value with the initial portlet context
+ res = producer.getMarkup(gm);
+ markupString = res.getMarkupContext().getItemString();
+ ExtendedAssert.assertEquals("initial", markupString);
+
+ // retrieving the markup with the new portlet context should return the new value
+ gm.setPortletContext(pc);
+ res = producer.getMarkup(gm);
+ markupString = res.getMarkupContext().getItemString();
+ ExtendedAssert.assertEquals(value, markupString);
+ }
+ finally
+ {
+ undeploy(archiveName);
+ }
+ }
+
+ private NamedString createNamedString(String name, String value)
+ {
+ NamedString namedString = new NamedString();
+ namedString.setName(name);
+ namedString.setValue(value);
+ return namedString;
+ }
+
+ @Test
+ public void testGetMarkupWithResource() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String archive = "test-resource-portlet.war";
+ deploy(archive);
+
+ try
+ {
+ GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+ MarkupResponse res = producer.getMarkup(gm);
+ String markupString = res.getMarkupContext().getItemString();
+
+ // accept either localhost or 127.0.0.1 for the host part of the generated markup
+ // note that we are using a MockHttpServletRequest, so the host and port come from there.
+ String markupStart = "<img src='wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2F";
+ String markupEnd = "%3A8080%2Ftest-resource-portlet%2Fgif%2Flogo.gif&wsrp-requiresRewrite=true/wsrp_rewrite'/>";
+ String localhostMarkup = markupStart + "localhost" + markupEnd;
+ String homeIPMarkup = markupStart + "127.0.0.1" + markupEnd;
+ boolean result = localhostMarkup.equals(markupString) || homeIPMarkup.equals(markupString);
+ ExtendedAssert.assertTrue("Expectd '" + localhostMarkup + "' or '" + homeIPMarkup + "' but received '" + markupString + "'." , result);
+ }
+ finally
+ {
+ undeploy(archive);
+ }
+ }
+
+ @Test
+ public void testGetMarkupWithNonURLEncodedResource() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String archive = "test-resourcenoencodeurl-portlet.war";
+ deploy(archive);
+
+ try
+ {
+ GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+ MarkupResponse res = producer.getMarkup(gm);
+ String markupString = res.getMarkupContext().getItemString();
+
+ // accept either localhost or 127.0.0.1 for the host part of the generated markup
+ // note that we are using a MockHttpServletRequest, so the host and port come from there.
+ String markupStart = "<img src='http://";
+ String markupEnd = ":8080/test-resourcenoencodeurl-portlet/gif/logo.gif'/>";
+ String localhostMarkup = markupStart + "localhost" + markupEnd;
+ String homeIPMarkup = markupStart + "127.0.0.1" + markupEnd;
+ boolean result = localhostMarkup.equals(markupString) || homeIPMarkup.equals(markupString);
+ ExtendedAssert.assertTrue("Expectd '" + localhostMarkup + "' or '" + homeIPMarkup + "' but received '" + markupString + "'.", result);
+ }
+ finally
+ {
+ undeploy(archive);
+ }
+ }
+
+ @Test
+ public void testApplicationScopeVariableHandling() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String archive = "test-applicationscope-portlet.war";
+ deploy(archive);
+
+ try
+ {
+ // set appVar to value in the application scope by the first portlet
+ PerformBlockingInteraction pbi = WSRPTypeFactory.createDefaultPerformBlockingInteraction(getPortletHandleFrom("Set"));
+ pbi.getInteractionParams().getFormParameters().add(createNamedString("appVar", "value"));
+ producer.performBlockingInteraction(pbi);
+
+ // the second portlet reads the appVar value and outputs it
+ GetMarkup gm = createMarkupRequest(getPortletHandleFrom("Get"));
+ MarkupResponse res = producer.getMarkup(gm);
+ checkMarkupResponse(res, "appVar=value");
+ }
+ finally
+ {
+ undeploy(archive);
+ }
+ }
+
+ @Test
+ public void testGetMarkupNoRegistrationWhenRegistrationRequired() throws Exception
+ {
+ configureRegistrationSettings(true, false);
+
+ GetMarkup gm = createMarkupRequest();
+ try
+ {
+ producer.getMarkup(gm);
+ ExtendedAssert.fail("Should have thrown InvalidRegistration!");
+ }
+ catch (InvalidRegistration invalidRegistration)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testPerformBlockingInteractionNoRegistrationWhenRegistrationRequired() throws Exception
+ {
+ configureRegistrationSettings(true, false);
+
+ PerformBlockingInteraction pbi = WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+ try
+ {
+ producer.performBlockingInteraction(pbi);
+ ExtendedAssert.fail("Should have thrown InvalidRegistration!");
+ }
+ catch (InvalidRegistration invalidRegistration)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInitCookieNoRegistrationWhenRegistrationRequired() throws Exception
+ {
+ configureRegistrationSettings(true, false);
+
+ InitCookie initCookie = WSRPTypeFactory.createInitCookie(null);
+ try
+ {
+ producer.initCookie(initCookie);
+ ExtendedAssert.fail("Should have thrown InvalidRegistration!");
+ }
+ catch (InvalidRegistration invalidRegistration)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ private String checkPBIAndGetNavigationalState(String symbol) throws Exception
+ {
+ PerformBlockingInteraction performBlockingInteraction =
+ WSRPTypeFactory.createDefaultPerformBlockingInteraction(getDefaultHandle());
+ InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
+ interactionParams.getFormParameters().add(createNamedString("symbol", symbol));
+
+ BlockingInteractionResponse response = producer.performBlockingInteraction(performBlockingInteraction);
+ ExtendedAssert.assertNotNull(response);
+
+ // this is not a redirect...
+ ExtendedAssert.assertNull(response.getRedirectURL());
+
+ // check update response
+ UpdateResponse updateResponse = response.getUpdateResponse();
+ ExtendedAssert.assertNotNull(updateResponse);
+ // request was readOnly so no updated portlet context
+ ExtendedAssert.assertNull(updateResponse.getPortletContext());
+ // check that no sessionId is getting passed.
+ ExtendedAssert.assertNull(updateResponse.getSessionContext());
+
+ String navigationalState = updateResponse.getNavigationalContext().getOpaqueValue();
+ ExtendedAssert.assertNotNull(navigationalState);
+ ExtendedAssert.assertEquals(updateResponse.getNewMode(), WSRPConstants.VIEW_MODE);
+ MarkupContext markupContext = updateResponse.getMarkupContext();
+ ExtendedAssert.assertNull(markupContext); // we don't return markup for now
+
+ return navigationalState;
+ }
+
+ private void checkMarkupResponseWithSession(MarkupResponse response, int count) throws RemoteException, InvalidRegistration, OperationFailed
+ {
+ ExtendedAssert.assertNotNull(response);
+
+ // Markup context
+ MarkupContext markupContext = response.getMarkupContext();
+ ExtendedAssert.assertNotNull(markupContext);
+ String markupString = markupContext.getItemString();
+ ExtendedAssert.assertString1ContainsString2(markupString, "count = " + count);
+ ExtendedAssert.assertString1ContainsString2(markupString, "<a href='wsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewrite'>render</a>");
+
+ // checking session
+ checkSessionForCurrentlyDeployedPortlet(response);
+ }
+
+ private MarkupContext checkMarkupResponse(MarkupResponse response, String markupString)
+ {
+ ExtendedAssert.assertNotNull(response);
+
+ // Markup context
+ MarkupContext markupContext = response.getMarkupContext();
+ ExtendedAssert.assertNotNull(markupContext);
+ ExtendedAssert.assertEquals("text/html", markupContext.getMimeType());
+ ExtendedAssert.assertEquals("title", markupContext.getPreferredTitle());
+ ExtendedAssert.assertTrue(markupContext.isRequiresRewriting());
+ ExtendedAssert.assertEquals(markupString, markupContext.getItemString());
+
+ // Session context
+ SessionContext sessionContext = response.getSessionContext();
+ // The session information is should never be sent to the consumer, Cookies are used instead.
+ ExtendedAssert.assertNull(sessionContext);
+
+ return markupContext;
+ }
+
+ protected String getMostUsedPortletWARFileName()
+ {
+ return DEFAULT_MARKUP_PORTLET_WAR;
+ }
+}
+
+
Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/V2ProducerBaseTest.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/V2ProducerBaseTest.java 2010-08-06 08:40:02 UTC (rev 3765)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/V2ProducerBaseTest.java 2010-08-06 15:14:27 UTC (rev 3766)
@@ -23,11 +23,20 @@
package org.gatein.wsrp.protocol.v2;
+import javax.xml.namespace.QName;
+
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.RegistrationManager;
+import org.gatein.registration.policies.DefaultRegistrationPolicy;
+import org.gatein.registration.policies.DefaultRegistrationPropertyValidator;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.producer.ProducerHolder;
import org.gatein.wsrp.producer.WSRPProducer;
import org.gatein.wsrp.producer.WSRPProducerBaseTest;
+import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
import org.gatein.wsrp.producer.v2.WSRP2Producer;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.gatein.wsrp.test.ExtendedAssert;
import org.oasis.wsrp.v2.GetServiceDescription;
/**
@@ -37,6 +46,8 @@
public class V2ProducerBaseTest extends WSRPProducerBaseTest
{
protected WSRP2Producer producer = ProducerHolder.getProducer(true);
+
+ private static final String CONSUMER = "test-consumer";
public V2ProducerBaseTest() throws Exception
{
@@ -61,4 +72,47 @@
gs.getDesiredLocales().add("en");
return gs;
}
+
+ protected RegistrationPropertyDescription configureRegistrationSettings(boolean requiresRegistration, boolean provideUnregisteredFullDescription)
+ {
+ // define expected registration infos
+ ProducerRegistrationRequirements registrationRequirements = producer.getConfigurationService().getConfiguration().getRegistrationRequirements();
+ registrationRequirements.setRegistrationRequired(requiresRegistration);
+ registrationRequirements.setRegistrationRequiredForFullDescription(!provideUnregisteredFullDescription);
+
+ if (requiresRegistration)
+ {
+ // fix-me: http://jira.jboss.com/jira/browse/JBPORTAL-821
+ RegistrationPropertyDescription regProp = new RegistrationPropertyDescription("regProp",
+ new QName("urn:oasis:names:tc:wsrp:v1:types", "LocalizedString", "ns1"));
+ regProp.setDefaultLabel("Registration Property");
+ registrationRequirements.addRegistrationProperty(regProp);
+
+ // Use default registration policy: this wiring is normally handled at the producer start, should maybe use a
+ // registration policy that is automatically configured when none is provided to avoid having a null one?
+ DefaultRegistrationPolicy defaultRegistrationPolicy = new DefaultRegistrationPolicy();
+ defaultRegistrationPolicy.setValidator(new DefaultRegistrationPropertyValidator());
+ registrationRequirements.setPolicy(defaultRegistrationPolicy);
+
+ RegistrationManager registrationManager = producer.getRegistrationManager();
+ registrationManager.setPolicy(defaultRegistrationPolicy);
+ registrationRequirements.addRegistrationPropertyChangeListener(registrationManager);
+
+ // create consumer for policy to be able to make decisions properly
+ try
+ {
+ registrationManager.createConsumer(CONSUMER);
+ }
+ catch (RegistrationException e)
+ {
+ ExtendedAssert.fail("Couldn't create consumer. Cause: " + e.getLocalizedMessage());
+ }
+
+ return regProp;
+ }
+ else
+ {
+ return null;
+ }
+ }
}
13 years, 11 months
gatein SVN: r3765 - portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest.
by do-not-reply@jboss.org
Author: hangnguyen
Date: 2010-08-06 04:40:02 -0400 (Fri, 06 Aug 2010)
New Revision: 3765
Modified:
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_03_ChangeDisplayLanguageInPublicMode.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_06_CreateNewAccount.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_13_ShowOrHideImportApplicationIcon.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_18_ManageManualGadget.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_20_ExpandAllCollapseAll.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_25_ChangeContainerInPortal.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_27_AddApplicationIntoContainerInLayoutOfPortal.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_28_EditPortalConfig.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_29_AddNewpageForPortal.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_33_EditNodePageProperties.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_51_ManageGadget.html
Log:
TestVN-356:Clean and Improve existing Selenium for GateIn
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_03_ChangeDisplayLanguageInPublicMode.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_03_ChangeDisplayLanguageInPublicMode.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_03_ChangeDisplayLanguageInPublicMode.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<link rel="selenium.base" href="" />
+<link rel="selenium.base" href="http://localhost:8080/" />
<title>Test_SNF_PRL_03_ChangeDisplayLanguageInPublicMode</title>
</head>
<body>
@@ -52,6 +52,11 @@
<td></td>
</tr>
<tr>
+ <td>waitForElementPresent</td>
+ <td>link=Apply</td>
+ <td></td>
+</tr>
+<tr>
<td>clickAndWait</td>
<td>link=Apply</td>
<td></td>
@@ -92,6 +97,11 @@
<td></td>
</tr>
<tr>
+ <td>waitForElementPresent</td>
+ <td>link=Appliquer</td>
+ <td></td>
+</tr>
+<tr>
<td>clickAndWait</td>
<td>link=Appliquer</td>
<td></td>
@@ -132,6 +142,11 @@
<td></td>
</tr>
<tr>
+ <td>waitForElementPresent</td>
+ <td>link=Áp dụng</td>
+ <td></td>
+</tr>
+<tr>
<td>clickAndWait</td>
<td>link=Áp dụng</td>
<td></td>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_06_CreateNewAccount.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_06_CreateNewAccount.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_06_CreateNewAccount.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -22,6 +22,11 @@
<td></td>
</tr>
<tr>
+ <td>windowMaximize</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
<td>click</td>
<td>link=Sign in</td>
<td></td>
@@ -52,6 +57,11 @@
<td></td>
</tr>
<tr>
+ <td>waitForElementPresent</td>
+ <td>link=New Staff</td>
+ <td></td>
+</tr>
+<tr>
<td>clickAndWait</td>
<td>link=New Staff</td>
<td></td>
@@ -59,7 +69,7 @@
<tr>
<td>waitForElementPresent</td>
<td>username</td>
- <td>Test_SNF_PRL_06</td>
+ <td></td>
</tr>
<tr>
<td>type</td>
@@ -128,12 +138,12 @@
</tr>
<tr>
<td>waitForTextPresent</td>
- <td>You have registered a new account. </td>
+ <td>You have registered a new account.</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
- <td>You have registered a new account. </td>
+ <td>You have registered a new account.</td>
<td></td>
</tr>
<tr>
@@ -288,12 +298,12 @@
</tr>
<tr>
<td>waitForTextPresent</td>
- <td>No result found. </td>
+ <td>No result found.</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
- <td>No result found. </td>
+ <td>No result found.</td>
<td></td>
</tr>
<tr>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_13_ShowOrHideImportApplicationIcon.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_13_ShowOrHideImportApplicationIcon.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_13_ShowOrHideImportApplicationIcon.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -167,6 +167,11 @@
<td></td>
</tr>
<tr>
+ <td>waitForElementPresent</td>
+ <td>//div[2]/div/div/div/div/div/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div/div/div[1]</td>
+ <td></td>
+</tr>
+<tr>
<td>mouseOver</td>
<td>//div[2]/div/div/div/div/div/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div/div/div[1]</td>
<td></td>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_18_ManageManualGadget.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_18_ManageManualGadget.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_18_ManageManualGadget.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -107,44 +107,34 @@
<td></td>
</tr>
<tr>
- <td>clickAt</td>
+ <td>click</td>
<td>link=Save</td>
<td></td>
</tr>
<tr>
- <td>waitForTextPresent</td>
- <td>hello world example</td>
- <td></td>
-</tr>
-<tr>
- <td>verifyTextPresent</td>
- <td>hello world example</td>
- <td></td>
-</tr>
-<tr>
<td>echo</td>
- <td>-- Edit gadget --</td>
+ <td>-- Add gadget into category--</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
- <td>//div[@id='UIGadgetInfo']/div[1]/div[2]</td>
+ <td>link=Click here to add into categories</td>
<td></td>
</tr>
<tr>
<td>click</td>
- <td>//div[@id='UIGadgetInfo']/div[1]/div[2]</td>
+ <td>link=Click here to add into categories</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
- <td>source</td>
+ <td>category_Gadgets</td>
<td></td>
</tr>
<tr>
- <td>type</td>
- <td>source</td>
- <td><?xml version="1.0" encoding="UTF-8"?><Module><ModulePrefs title="Test_SNF_PRL_18_edit" description="The hello world gadget."/><Content type="html"></Content></Module></td>
+ <td>click</td>
+ <td>category_Gadgets</td>
+ <td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
@@ -152,59 +142,54 @@
<td></td>
</tr>
<tr>
- <td>clickAt</td>
+ <td>click</td>
<td>link=Save</td>
<td></td>
</tr>
<tr>
<td>waitForTextPresent</td>
- <td>Test_SNF_PRL_18_edit</td>
+ <td>hello world example</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
- <td>Test_SNF_PRL_18_edit</td>
+ <td>hello world example</td>
<td></td>
</tr>
<tr>
<td>echo</td>
- <td>-- Click Refresh --</td>
+ <td>-- Edit gadget --</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
- <td>//div[@id='UIGadgetInfo']//div[@title='Refresh information']</td>
+ <td>link=hello world example</td>
<td></td>
</tr>
<tr>
<td>click</td>
- <td>//div[@id='UIGadgetInfo']//div[@title='Refresh information']</td>
+ <td>link=hello world example</td>
<td></td>
</tr>
<tr>
- <td>echo</td>
- <td>-- Add gadget into category--</td>
- <td></td>
-</tr>
-<tr>
<td>waitForElementPresent</td>
- <td>link=Click here to add into categories</td>
+ <td>//div[@id='UIGadgetInfo']/div[1]/div[2]</td>
<td></td>
</tr>
<tr>
<td>click</td>
- <td>link=Click here to add into categories</td>
+ <td>//div[@id='UIGadgetInfo']/div[1]/div[2]</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
- <td>category_Gadgets</td>
+ <td>source</td>
<td></td>
</tr>
<tr>
- <td>click</td>
- <td>category_Gadgets</td>
- <td></td>
+ <td>type</td>
+ <td>source</td>
+ <td><?xml version="1.0" encoding="UTF-8"?><Module><ModulePrefs title="Test_SNF_PRL_18_edit" description="The hello world gadget."/><Content type="html"></Content></Module></td>
</tr>
<tr>
<td>waitForElementPresent</td>
@@ -218,16 +203,31 @@
</tr>
<tr>
<td>waitForTextPresent</td>
- <td>Gadgets</td>
+ <td>Test_SNF_PRL_18_edit</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
- <td>Gadgets</td>
+ <td>Test_SNF_PRL_18_edit</td>
<td></td>
</tr>
<tr>
<td>echo</td>
+ <td>-- Click Refresh --</td>
+ <td></td>
+</tr>
+<tr>
+ <td>waitForElementPresent</td>
+ <td>//div[@id='UIGadgetInfo']//div[@title='Refresh information']</td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>//div[@id='UIGadgetInfo']//div[@title='Refresh information']</td>
+ <td></td>
+</tr>
+<tr>
+ <td>echo</td>
<td>-- Delete gadget--</td>
<td></td>
</tr>
@@ -242,6 +242,11 @@
<td></td>
</tr>
<tr>
+ <td>waitForConfirmationPresent</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
<td>assertConfirmation</td>
<td>Are you sure to delete this gadget?</td>
<td></td>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_20_ExpandAllCollapseAll.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_20_ExpandAllCollapseAll.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_20_ExpandAllCollapseAll.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -132,11 +132,6 @@
<td></td>
</tr>
<tr>
- <td>verifyTextNotPresent</td>
- <td>Application Registry</td>
- <td></td>
-</tr>
-<tr>
<td>verifyElementNotPresent</td>
<td>//div[@id='UISiteMap']/div[2]/div/div[3]/div[2]/div[1]/div/div/a</td>
<td></td>
@@ -147,8 +142,8 @@
<td></td>
</tr>
<tr>
- <td>verifyTextNotPresent</td>
- <td>Page Management</td>
+ <td>verifyElementNotPresent</td>
+ <td>//div[3]/div[2]/div[2]/div/div/a</td>
<td></td>
</tr>
<tr>
@@ -157,8 +152,8 @@
<td></td>
</tr>
<tr>
- <td>verifyTextNotPresent</td>
- <td>New Staff</td>
+ <td>verifyElementNotPresent</td>
+ <td>//div[4]/div[2]/div[1]/div/div/a</td>
<td></td>
</tr>
<tr>
@@ -167,8 +162,8 @@
<td></td>
</tr>
<tr>
- <td>verifyTextNotPresent</td>
- <td>Users and groups management</td>
+ <td>verifyElementNotPresent</td>
+ <td>//div[4]/div[2]/div[2]/div/div/a</td>
<td></td>
</tr>
<tr>
@@ -177,8 +172,8 @@
<td></td>
</tr>
<tr>
- <td>verifyTextNotPresent</td>
- <td>Blog</td>
+ <td>verifyElementNotPresent</td>
+ <td>//div[5]/div[2]/div[1]/div/div/a</td>
<td></td>
</tr>
<tr>
@@ -187,8 +182,8 @@
<td></td>
</tr>
<tr>
- <td>verifyTextNotPresent</td>
- <td>Google</td>
+ <td>verifyElementNotPresent</td>
+ <td>//div[5]/div[2]/div[2]/div/div/a</td>
<td></td>
</tr>
<tr>
@@ -197,8 +192,8 @@
<td></td>
</tr>
<tr>
- <td>verifyTextNotPresent</td>
- <td>Facebook</td>
+ <td>verifyElementNotPresent</td>
+ <td>//div[2]/div[3]/div/div/a</td>
<td></td>
</tr>
<tr>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_25_ChangeContainerInPortal.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_25_ChangeContainerInPortal.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_25_ChangeContainerInPortal.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -378,7 +378,7 @@
</tr>
<tr>
<td>dragAndDropToObject</td>
- <td>//div/div/div[2]/div/div/div[2]/div/div/div/div/div/div/div[1]</td>
+ <td>//div/div/div[2]/div/div/div[2]/div/div/div/div/div/div/div</td>
<td>UIPageBody</td>
</tr>
<tr>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_27_AddApplicationIntoContainerInLayoutOfPortal.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_27_AddApplicationIntoContainerInLayoutOfPortal.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_27_AddApplicationIntoContainerInLayoutOfPortal.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -22,6 +22,11 @@
<td></td>
</tr>
<tr>
+ <td>windowMaximize</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
<td>click</td>
<td>link=Sign in</td>
<td></td>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_28_EditPortalConfig.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_28_EditPortalConfig.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_28_EditPortalConfig.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -382,6 +382,16 @@
<td></td>
</tr>
<tr>
+ <td>clickAndWait</td>
+ <td>link=classic</td>
+ <td></td>
+</tr>
+<tr>
+ <td>clickAndWait</td>
+ <td>link=Site</td>
+ <td></td>
+</tr>
+<tr>
<td>waitForElementPresent</td>
<td>link=Delete</td>
<td></td>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_29_AddNewpageForPortal.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_29_AddNewpageForPortal.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_29_AddNewpageForPortal.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -223,6 +223,16 @@
</tr>
<tr>
<td>waitForElementPresent</td>
+ <td>searchOption</td>
+ <td></td>
+</tr>
+<tr>
+ <td>select</td>
+ <td>searchOption</td>
+ <td>label=Title</td>
+</tr>
+<tr>
+ <td>waitForElementPresent</td>
<td>//form[@id='UIPageSearch']/div[2]/a</td>
<td></td>
</tr>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_33_EditNodePageProperties.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_33_EditNodePageProperties.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_33_EditNodePageProperties.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -178,7 +178,7 @@
</tr>
<tr>
<td>echo</td>
- <td>--Edit node's page by chec show max windown--</td>
+ <td>--Edit node's page by check show max windown--</td>
<td></td>
</tr>
<tr>
@@ -457,11 +457,6 @@
<td>nodeLvl</td>
</tr>
<tr>
- <td>echo</td>
- <td>Node is at level ${nodeLvl}</td>
- <td></td>
-</tr>
-<tr>
<td>waitForElementPresent</td>
<td>link=Test_SNF_PRL_32</td>
<td></td>
@@ -483,21 +478,16 @@
</tr>
<tr>
<td>waitForElementNotPresent</td>
- <td>xpath=//div[@class='TreeContainer JSContainer']/div/div[${nodeLvl}]/div/a[@title='test_grp_label_26']</td>
+ <td>xpath=//div[@class='TreeContainer JSContainer']/div/div[${nodeLvl}]/div/a[@title='Test_SNF_PRL_32']</td>
<td></td>
</tr>
<tr>
<td>verifyElementNotPresent</td>
- <td>xpath=//div[@class='TreeContainer JSContainer']/div/div[${nodeLvl}]/div/a[@title='test_grp_label_26']</td>
+ <td>xpath=//div[@class='TreeContainer JSContainer']/div/div[${nodeLvl}]/div/a[@title='Test_SNF_PRL_32']</td>
<td></td>
</tr>
<tr>
<td>echo</td>
- <td>Node is at level ${nodeLvl}</td>
- <td></td>
-</tr>
-<tr>
- <td>echo</td>
<td>--Move node down</td>
<td></td>
</tr>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_51_ManageGadget.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_51_ManageGadget.html 2010-08-06 03:20:52 UTC (rev 3764)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_51_ManageGadget.html 2010-08-06 08:40:02 UTC (rev 3765)
@@ -117,7 +117,7 @@
<td></td>
</tr>
<tr>
- <td>clickAt</td>
+ <td>click</td>
<td>//input[@value='Save']</td>
<td></td>
</tr>
@@ -127,7 +127,7 @@
<td></td>
</tr>
<tr>
- <td>verifyElementPresent</td>
+ <td>waitForElementPresent</td>
<td>//div[contains(@id,'UIAddGadgetPopup')]/div/div[1]/div/div/div/div[2]</td>
<td></td>
</tr>
13 years, 11 months
gatein SVN: r3764 - portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest.
by do-not-reply@jboss.org
Author: hangnguyen
Date: 2010-08-05 23:20:52 -0400 (Thu, 05 Aug 2010)
New Revision: 3764
Modified:
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_28_EditPortalConfig.html
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_31_ManageNodePortal.html
Log:
TestVN-356:Clean and Improve existing Selenium for GateIn
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_28_EditPortalConfig.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_28_EditPortalConfig.html 2010-08-06 02:55:58 UTC (rev 3763)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_28_EditPortalConfig.html 2010-08-06 03:20:52 UTC (rev 3764)
@@ -22,6 +22,11 @@
<td></td>
</tr>
<tr>
+ <td>windowMaximize</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
<td>click</td>
<td>link=Sign in</td>
<td></td>
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_31_ManageNodePortal.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_31_ManageNodePortal.html 2010-08-06 02:55:58 UTC (rev 3763)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_31_ManageNodePortal.html 2010-08-06 03:20:52 UTC (rev 3764)
@@ -22,6 +22,11 @@
<td></td>
</tr>
<tr>
+ <td>windowMaximize</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
<td>click</td>
<td>link=Sign in</td>
<td></td>
13 years, 11 months
gatein SVN: r3763 - portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest.
by do-not-reply@jboss.org
Author: hangnguyen
Date: 2010-08-05 22:55:58 -0400 (Thu, 05 Aug 2010)
New Revision: 3763
Modified:
portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_65_ChangeSkin.html
Log:
TestVN-356:Clean and Improve existing Selenium for GateIn
Modified: portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_65_ChangeSkin.html
===================================================================
--- portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_65_ChangeSkin.html 2010-08-05 17:36:48 UTC (rev 3762)
+++ portal/trunk/testsuite/selenium-snifftests/src/suite/org/exoplatform/portal/selenium/NewSnifftest/Test_SNF_PRL_65_ChangeSkin.html 2010-08-06 02:55:58 UTC (rev 3763)
@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<link rel="selenium.base" href="" />
+<link rel="selenium.base" href="http://localhost:8080/" />
<title>Test_SNF_PRL_65_ChangeSkin</title>
</head>
<body>
@@ -87,31 +87,66 @@
<td></td>
</tr>
<tr>
+ <td>waitForTextPresent</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
<td>verifyTextPresent</td>
- <td>SimpleSkin</td>
+ <td>Home</td>
<td></td>
</tr>
<tr>
+ <td>echo</td>
+ <td>-- Change to Default skin--</td>
+ <td></td>
+</tr>
+<tr>
+ <td>waitForElementPresent</td>
+ <td>link=Change Skin</td>
+ <td></td>
+</tr>
+<tr>
<td>click</td>
<td>link=Change Skin</td>
<td></td>
</tr>
<tr>
+ <td>waitForElementPresent</td>
+ <td>//div[@id='UITabContent']/div/div/div[1]/div[2]/div[1]/div/div/div</td>
+ <td></td>
+</tr>
+<tr>
<td>click</td>
<td>//div[@id='UITabContent']/div/div/div[1]/div[2]/div[1]/div/div/div</td>
<td></td>
</tr>
<tr>
+ <td>waitForElementPresent</td>
+ <td>link=Apply</td>
+ <td></td>
+</tr>
+<tr>
<td>click</td>
<td>link=Apply</td>
<td></td>
</tr>
<tr>
+ <td>waitForTextPresent</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
<td>verifyTextPresent</td>
- <td>Default Style Skin</td>
+ <td>Home</td>
<td></td>
</tr>
<tr>
+ <td>waitForElementPresent</td>
+ <td>link=Sign out</td>
+ <td></td>
+</tr>
+<tr>
<td>clickAndWait</td>
<td>link=Sign out</td>
<td></td>
13 years, 11 months
gatein SVN: r3762 - components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2010-08-05 13:36:48 -0400 (Thu, 05 Aug 2010)
New Revision: 3762
Modified:
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/ResourceResponseImpl.java
Log:
- isEmpty is Java 6 only, use a Java 5 friendly method.
Modified: components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/ResourceResponseImpl.java
===================================================================
--- components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/ResourceResponseImpl.java 2010-08-05 15:05:31 UTC (rev 3761)
+++ components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/ResourceResponseImpl.java 2010-08-05 17:36:48 UTC (rev 3762)
@@ -65,7 +65,7 @@
{
throw new IllegalArgumentException("Locale cannot be null");
}
- if (locale.getCountry().isEmpty())
+ if (locale.getCountry().length() == 0)
{
addProperty("Content-Language", locale.getLanguage());
}
13 years, 11 months
gatein SVN: r3761 - in components/wsrp/trunk/producer/src/main/java/org/gatein/exports: impl and 1 other directory.
by do-not-reply@jboss.org
Author: mwringe
Date: 2010-08-05 11:05:31 -0400 (Thu, 05 Aug 2010)
New Revision: 3761
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.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/data/PersistedExportData.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
Log:
GTNWSRP-55: committing files which somehow didn't get added in the last commit.
Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java 2010-08-05 15:05:31 UTC (rev 3761)
@@ -0,0 +1,116 @@
+/******************************************************************************
+ * 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.data;
+
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.oasis.wsrp.v2.Lifetime;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class ExportContext extends ExportData
+{
+
+ protected static final String ENCODING = "UTF-8";
+ public static final String TYPE = "WSRP_EC";
+ public static final double VERSION = 1.0;
+
+
+ protected Lifetime lifeTime;
+ protected final boolean exportByValue;
+
+ protected List<String> portlets;
+
+ //for now, we don't store anything in the exported by value ExportContext
+ public ExportContext()
+ {
+ this.lifeTime = null;
+ this.exportByValue = true;
+ }
+
+ public ExportContext(boolean exportByValue, Lifetime lifetime)
+ {
+ //ignore the lifetime if we are exporting by value
+ if (exportByValue)
+ {
+ this.lifeTime = null;
+ }
+ else
+ {
+ this.lifeTime = lifetime;
+ }
+ this.exportByValue = exportByValue;
+ }
+
+ public boolean isExportByValue()
+ {
+ return this.exportByValue;
+ }
+
+ public Lifetime getLifeTime()
+ {
+ return lifeTime;
+ }
+
+ public void setLifeTime(Lifetime lifetime)
+ {
+ this.lifeTime = lifetime;
+ }
+
+ public void addPortlet(String portletName)
+ {
+ if (portlets == null)
+ {
+ this.portlets = new ArrayList<String>();
+ }
+ this.portlets.add(portletName);
+ }
+
+ public static ExportContext create(byte[] bytes)
+ {
+ //for now, we don't store anything in the stored by value ExportContext
+ ExportContext exportContext = new ExportContext();
+ return exportContext;
+ }
+
+ public String getType()
+ {
+ return TYPE;
+ }
+
+ public double getVersion()
+ {
+ return VERSION;
+ }
+
+ protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingException
+ {
+ return "EMPTY".getBytes(ENCODING);
+ }
+
+}
+
Added: 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 (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java 2010-08-05 15:05:31 UTC (rev 3761)
@@ -0,0 +1,104 @@
+/******************************************************************************
+ * 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.data;
+
+import java.io.UnsupportedEncodingException;
+
+import org.gatein.common.NotYetImplemented;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public abstract class ExportData
+{
+
+ public abstract double getVersion();
+ public abstract String getType();
+
+ protected abstract byte[] internalEncodeAsBytes() throws UnsupportedEncodingException;
+
+
+ //The encoding used to create the byte array
+ protected static final String ENCODING = "UTF-8";
+
+ protected static final String SEPARATOR = "_@_";
+
+ public byte[] encodeAsBytes() throws UnsupportedEncodingException
+ {
+ byte[] internalBytes = internalEncodeAsBytes();
+
+ String token = this.getType() + SEPARATOR + this.getVersion() + SEPARATOR;
+ String dataString = new String(internalBytes, ENCODING);
+
+ return (token + dataString).getBytes(ENCODING);
+ }
+
+ public static double getVersion(byte[] bytes) throws UnsupportedEncodingException
+ {
+ String dataString = new String(bytes, ENCODING);
+ String[] split = dataString.split(SEPARATOR, 3);
+
+ if (split.length >= 2)
+ {
+ double version = Double.parseDouble(split[1]);
+ return version;
+ }
+
+ //if a version could not be found, return -1
+ return -1;
+ }
+
+ public static String getType(byte[] bytes) throws UnsupportedEncodingException
+ {
+ String dataString = new String(bytes, ENCODING);
+ String[] split = dataString.split(SEPARATOR, 2);
+
+ if (split.length >= 2)
+ {
+ return split[0];
+ }
+
+ //if we could not find a type, then return null
+ return null;
+ }
+
+ public static byte[] getInternalBytes(byte[] bytes) throws UnsupportedEncodingException
+ {
+ String dataString = new String(bytes, ENCODING);
+ String[] split = dataString.split(SEPARATOR, 3);
+
+ if (split.length >= 3)
+ {
+ String internalString = split[2];
+ return internalString.getBytes(ENCODING);
+ }
+ else
+ {
+ //if we could not find the internal bytes, return null
+ return null;
+ }
+ }
+
+}
+
Added: 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 (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportPortletData.java 2010-08-05 15:05:31 UTC (rev 3761)
@@ -0,0 +1,122 @@
+/******************************************************************************
+ * 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.data;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+import org.gatein.pc.api.ParametersStateString;
+import org.gatein.pc.api.StateString;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class ExportPortletData extends ExportData
+{
+
+ protected static final String ENCODING = "UTF-8";
+ public static final String TYPE = "WSRP_EC";
+ public static final double VERSION = 1.0;
+
+ protected static final String PORTLETHANDLEKEY = "pID";
+ protected static final String PORTLETSTATEKEY = "pState";
+
+ protected String portletHandle;
+ protected byte[] portletState;
+
+ public ExportPortletData(String portletHandle, byte[] portletState)
+ {
+ this.portletHandle = portletHandle;
+ this.portletState = portletState;
+ }
+
+ public String getPortletHandle()
+ {
+ return this.portletHandle;
+ }
+
+ public byte[] getPortletState()
+ {
+ return this.portletState;
+ }
+
+ public String getType()
+ {
+ return TYPE;
+ }
+
+ public double getVersion()
+ {
+ return VERSION;
+ }
+
+ public static ExportPortletData create(byte[] bytes) throws UnsupportedEncodingException
+ {
+ //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));
+
+ String portletHandle;
+ byte[] portletState;
+
+ String[] portletHandles = map.get(PORTLETHANDLEKEY);
+ if (portletHandles != null && portletHandles.length > 0)
+ {
+ portletHandle = portletHandles[0];
+ }
+ 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;
+ }
+
+ return new ExportPortletData(portletHandle, portletState);
+ }
+
+ protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingException
+ {
+ ParametersStateString parameterStateString = ParametersStateString.create();
+ 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);
+ }
+
+ parameterStateString.setValue(PORTLETHANDLEKEY, portletHandle);
+
+ String stateString = parameterStateString.getStringValue();
+ return stateString.getBytes(ENCODING);
+ }
+
+}
+
Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java 2010-08-05 15:05:31 UTC (rev 3761)
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * 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.data;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+import org.gatein.pc.api.ParametersStateString;
+import org.gatein.pc.api.StateString;
+
+/**
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class PersistedExportData extends ExportData
+{
+ protected final String type;
+ protected final String refID;
+ protected static final double VERSION = 1.0;
+
+ protected static final String REFIDKEY = "rID";
+ protected static final String TYPEKEY = "type";
+
+ public PersistedExportData(String type, String refID)
+ {
+ this.type = type;
+ this.refID = refID;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public double getVersion()
+ {
+ return VERSION;
+ }
+
+ protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingException
+ {
+ ParametersStateString parameterStateString = ParametersStateString.create();
+
+ parameterStateString.setValue(REFIDKEY, REFIDKEY);
+ parameterStateString.setValue(TYPEKEY, type);
+
+ String stateString = parameterStateString.getStringValue();
+ return stateString.getBytes(ENCODING);
+ }
+
+ public static PersistedExportData create(byte[] bytes) throws UnsupportedEncodingException
+ {
+ Map<String, String[]> map = StateString.decodeOpaqueValue(new String(bytes, ENCODING));
+
+ String refId = null;
+ String type = null;
+
+ if (map.containsKey(REFIDKEY) && map.get(REFIDKEY).length > 0)
+ {
+ refId = map.get(REFIDKEY)[0];
+ }
+
+ if (map.containsKey(TYPEKEY) && map.get(TYPEKEY).length > 0 )
+ {
+ type = map.get(TYPEKEY)[0];
+ }
+
+ return new PersistedExportData(type, refId);
+ }
+
+
+}
+
Added: 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 (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java 2010-08-05 15:05:31 UTC (rev 3761)
@@ -0,0 +1,183 @@
+/******************************************************************************
+ * 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.impl;
+
+import java.io.UnsupportedEncodingException;
+
+import org.gatein.common.NotYetImplemented;
+import org.gatein.exports.ExportManager;
+import org.gatein.exports.ExportPersistenceManager;
+import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportData;
+import org.gatein.exports.data.ExportPortletData;
+import org.gatein.wsrp.WSRPExceptionFactory;
+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 class ExportManagerImpl implements ExportManager
+{
+
+ protected ExportPersistenceManager exportPersistenceManager;
+
+ //set to true if we prefer to export by value instead of by reference
+ protected boolean preferExportByValue = false;
+
+ protected boolean supportExportByValue = true;
+
+ public ExportPersistenceManager getPersistenceManager()
+ {
+ return exportPersistenceManager;
+ }
+
+ public void setPersistanceManager(ExportPersistenceManager exportPersistenceManager)
+ {
+ this.exportPersistenceManager = exportPersistenceManager;
+ }
+
+ public ExportContext createExportContext(boolean exportByValueRequired, Lifetime lifetime)
+ throws UnsupportedEncodingException
+ {
+ boolean useExportByValue = false;
+ if (exportByValueRequired || (exportPersistenceManager == null && preferExportByValue))
+ {
+ useExportByValue = true;
+ }
+
+ return new ExportContext(useExportByValue, lifetime);
+ }
+
+ public boolean supportExportByValue()
+ {
+ return supportExportByValue;
+ }
+
+ public ExportContext createExportContext(byte[] bytes)
+ {
+ try
+ {
+ String type = ExportData.getType(bytes);
+ double version = ExportData.getVersion(bytes);
+ if (ExportContext.TYPE.equals(type) && ExportContext.VERSION==version)
+ {
+ byte[] internalBytes = ExportData.getInternalBytes(bytes);
+ return ExportContext.create(internalBytes);
+ }
+ else
+ {
+ //TODO: throw an error here about not being a recognized type
+ throw new IllegalArgumentException("byte[] format unreconized.");
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new NotYetImplemented();
+ }
+ }
+
+ public ExportPortletData createExportPortletData(ExportContext exportContextData, String portletHandle,
+ byte[] portletState) throws UnsupportedEncodingException
+ {
+ return new ExportPortletData(portletHandle, portletState);
+ }
+
+ public ExportPortletData createExportPortletData(ExportContext exportContextData, Lifetime lifetime, byte[] bytes)
+ {
+ try
+ {
+ String type = ExportData.getType(bytes);
+ double version = ExportData.getVersion(bytes);
+ if (ExportPortletData.TYPE.equals(type) && ExportPortletData.VERSION==version)
+ {
+ byte[] internalBytes = ExportData.getInternalBytes(bytes);
+ return ExportPortletData.create(internalBytes);
+ }
+ else
+ {
+ //TODO: throw an error here about not being a recognized type
+ throw new IllegalArgumentException("byte[] format unreconized.");
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new NotYetImplemented();
+ }
+ }
+
+ public byte[] encodeExportPortletData(ExportContext exportContextData, ExportPortletData exportPortletData) throws UnsupportedEncodingException
+ {
+ if (exportContextData.isExportByValue())
+ {
+ return exportPortletData.encodeAsBytes();
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public byte[] encodeExportContextData(ExportContext exportContextData) throws UnsupportedEncodingException
+ {
+ if (exportContextData.isExportByValue())
+ {
+ return exportContextData.encodeAsBytes();
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public Lifetime setExportLifetime(ExportContext exportContext, Lifetime lifetime) throws OperationFailed, OperationNotSupported
+ {
+ if (exportContext.isExportByValue())
+ {
+ WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot set the lifetime for an export that was exported by value.", null);
+ }
+ if (getPersistenceManager() == null)
+ {
+ WSRPExceptionFactory.throwWSException(OperationNotSupported.class, "The producer only supports export by value. Cannot call setExportLifetime on this producer", null);
+ }
+
+ return getPersistenceManager().updateExportLifetime(exportContext, lifetime);
+ }
+
+ public void releaseExport(ExportContext exportContext)
+ {
+ //TODO: since we can't return any errors, we should at least log messages if this method is called and it can't be completed for some reason.
+ if (exportContext != null && !exportContext.isExportByValue() && exportPersistenceManager!= null)
+ {
+ exportPersistenceManager.releaseExport(exportContext);
+ }
+ }
+
+
+}
+
13 years, 11 months
gatein SVN: r3760 - in components/wsrp/trunk: common/src/main/java/org/gatein/wsrp/spec/v1 and 11 other directories.
by do-not-reply@jboss.org
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>
13 years, 11 months
gatein SVN: r3759 - components/pc/trunk/samples/src/main/java/org/gatein/pc/samples/remotecontroller.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2010-08-05 09:14:29 -0400 (Thu, 05 Aug 2010)
New Revision: 3759
Modified:
components/pc/trunk/samples/src/main/java/org/gatein/pc/samples/remotecontroller/RemoteControllerPortlet.java
Log:
- Properly set cache level to ResourceURL.PAGE as mandated by JSR 286 for resource-serving portlets which resources generate URLs.
Modified: components/pc/trunk/samples/src/main/java/org/gatein/pc/samples/remotecontroller/RemoteControllerPortlet.java
===================================================================
--- components/pc/trunk/samples/src/main/java/org/gatein/pc/samples/remotecontroller/RemoteControllerPortlet.java 2010-08-05 12:51:22 UTC (rev 3758)
+++ components/pc/trunk/samples/src/main/java/org/gatein/pc/samples/remotecontroller/RemoteControllerPortlet.java 2010-08-05 13:14:29 UTC (rev 3759)
@@ -1,5 +1,24 @@
/*
- * Copyright (c) 2008, Your Corporation. All Rights Reserved.
+ * 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.pc.samples.remotecontroller;
@@ -32,6 +51,8 @@
String namespace = "n_" + renderResponse.getNamespace();
printWriter.print("<p><a href='#' onclick=\"" + namespace + "_remote=" + namespace + "_openRemote('");
ResourceURL resource = renderResponse.createResourceURL();
+ // set the cache level to PAGE since the resource creates URLs and the spec mandates PAGE cache level in that case
+ resource.setCacheability(ResourceURL.PAGE);
printWriter.print(resource);
printWriter.print("')\">Open remote control!</a></p>");
}
13 years, 11 months
gatein SVN: r3758 - components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2010-08-05 08:51:22 -0400 (Thu, 05 Aug 2010)
New Revision: 3758
Modified:
components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/ResourceResponseImpl.java
Log:
- Improved error message.
Modified: components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/ResourceResponseImpl.java
===================================================================
--- components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/ResourceResponseImpl.java 2010-08-05 10:36:29 UTC (rev 3757)
+++ components/pc/trunk/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/ResourceResponseImpl.java 2010-08-05 12:51:22 UTC (rev 3758)
@@ -33,6 +33,7 @@
import javax.portlet.PortletURL;
import javax.portlet.ResourceResponse;
+import javax.portlet.ResourceURL;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -109,26 +110,23 @@
public PortletURL createActionURL()
{
- if (cacheability != CacheLevel.PAGE)
- {
- throw new IllegalStateException("Cannot create action URL because the current cache level " + cacheability +
- " is not " + CacheLevel.PAGE);
- }
-
- //
+ checkCacheLevel();
return super.createActionURL();
}
public PortletURL createRenderURL()
{
+ checkCacheLevel();
+ return super.createRenderURL();
+ }
+
+ private void checkCacheLevel()
+ {
if (cacheability != CacheLevel.PAGE)
{
- throw new IllegalStateException("Cannot create render URL because the current cache level " + cacheability +
- " is not " + CacheLevel.PAGE);
+ throw new IllegalStateException("A resource cannot create URLs if the cache level hasn't been set to "
+ + ResourceURL.PAGE + " as mandated by JSR-286 PLT.13.7. Cache level was: " + cacheability);
}
-
- //
- return super.createRenderURL();
}
protected ContentResponse createMarkupResponse(ResponseProperties properties, Map<String, Object> attributeMap, String contentType, byte[] bytes, String chars, CacheControl cacheControl)
13 years, 11 months