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;