Author: mwringe
Date: 2010-07-20 15:47:00 -0400 (Tue, 20 Jul 2010)
New Revision: 3667
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ResourceRequestProcessor.java
Modified:
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/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ResourceHandler.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/MarkupService.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/v1/V1MarkupService.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/v2/V2MarkupService.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ActionRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/EventRequestProcessor.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/RequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPPortletInvocationContext.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPRequestContext.java
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v2/MarkupEndpoint.java
Log:
GTNWSRP-54: initial check in of GetResource support. Still needs a couple of fixes and
test cases to be added.
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-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPResourceURL.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -32,6 +32,7 @@
import org.gatein.pc.api.StateString;
import org.gatein.pc.api.WindowState;
import org.gatein.pc.api.cache.CacheLevel;
+import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
import org.jboss.logging.Logger;
import javax.servlet.http.HttpServletRequest;
@@ -55,6 +56,7 @@
private boolean requiresRewrite = false;
private URL resourceURL;
+ private boolean preferOperation = false;
private static final Map<String, MediaType> SUPPORTED_RESOURCE_TYPES = new
HashMap<String, MediaType>(11);
@@ -95,10 +97,21 @@
{
if (resourceURL != null)
{
- createURLParameter(sb, WSRPRewritingConstants.RESOURCE_URL, getResourceId());
+ createURLParameter(sb, WSRPRewritingConstants.RESOURCE_URL,
URLTools.encodeXWWWFormURL(resourceURL.toExternalForm()));
}
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));
+ }
}
@Override
@@ -123,34 +136,44 @@
{
try
{
- // todo: deal with resourceId properly, right now just use resourceURL if
any
- resourceId = paramValue; // keep the encoded value as it will be used in
URLs
-
paramValue = URLTools.decodeXWWWFormURL(paramValue);
-
- resourceURL = new URL(paramValue);
-
+ this.resourceURL = new URL(paramValue);
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);
}
}
- else
+
+ String resourceIDParam = getRawParameterValueFor(params,
WSRP2RewritingConstants.RESOURCE_ID);
+ if (resourceIDParam != null)
{
- throw new IllegalArgumentException("The parsed parameters don't contain
a value for the required "
- + WSRPRewritingConstants.RESOURCE_URL + " parameter in " +
originalURL);
+ resourceId = resourceIDParam;
}
+
+ String preferOperationParam = getRawParameterValueFor(params,
WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
+ {
+ if (preferOperationParam != null)
+ {
+ preferOperation = Boolean.valueOf(preferOperationParam);
+ }
+ }
+
+ if (resourceIDParam == null && paramValue == null)
+ {
+ throw new IllegalArgumentException("The parsed parameters don't contain
a value for "
+ + WSRPRewritingConstants.RESOURCE_URL + " or for " +
WSRP2RewritingConstants.RESOURCE_ID + " parameter in " + originalURL);
+ }
}
/**
@@ -173,11 +196,10 @@
public String getResourceId()
{
- if (resourceId == null && resourceURL != null)
- {
- resourceId = URLTools.encodeXWWWFormURL(resourceURL.toExternalForm());
- }
- return resourceId;
+ // we need to return a representation of the wsrp resource identification, this is
not necessarily just
+ // the wsrp-resourceID, we need to also consider the wsrp-url and other wsrp
resource values.
+ // This value returned by this method is used by the PC ResourceInvocation
+ return encodeResource(resourceId, resourceURL, preferOperation);
}
/**
@@ -199,37 +221,6 @@
return cacheability;
}
- /**
- * This method is a hack to provide a minimal resource support before WSRP 2 so that
bridged portlets work. We
- * basically build a resource URL based on the server address and the targeted portlet
context (which hopefully can
- * be mapped to the context path of the war file it's deployed in). JBoss Portlet
Bridge 2.0 uses a resource ID that
- * is the absolute path to resource inside web application context for static
resources.
- *
- * @param request
- * @param portletContext
- * @deprecated should be removed when WSRP 2 is implemented
- */
- public void buildURLWith(HttpServletRequest request, PortletContext portletContext)
- {
- String url = createAbsoluteURLFrom(resourceId,
URLTools.getServerAddressFrom(request), portletContext.getApplicationName());
- try
- {
- resourceURL = new URL(url);
- String extension = URLTools.getFileExtensionOrNullFrom(resourceURL);
- MediaType type = SUPPORTED_RESOURCE_TYPES.get(extension);
- if (MediaType.TEXT_CSS.equals(type) || MediaType.TEXT_JAVASCRIPT.equals(type) ||
MediaType.TEXT_HTML.equals(type))
- {
- requiresRewrite = true;
- }
- }
- catch (MalformedURLException e)
- {
- throw new IllegalArgumentException("Malformed URL: " + url, e);
- }
-
- log.info("Attempted to build resource URL that could be accessed directly from
consumer: " + resourceURL);
- }
-
public static String createAbsoluteURLFrom(String initial, String serverAddress,
String portletApplicationName)
{
String url = serverAddress;
@@ -263,4 +254,54 @@
{
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 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> 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]);
+ }
+
+ 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-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -55,6 +55,7 @@
import org.oasis.wsrp.v2.GetPortletDescription;
import org.oasis.wsrp.v2.GetPortletProperties;
import org.oasis.wsrp.v2.GetPortletPropertyDescription;
+import org.oasis.wsrp.v2.GetResource;
import org.oasis.wsrp.v2.GetServiceDescription;
import org.oasis.wsrp.v2.HandleEvents;
import org.oasis.wsrp.v2.HandleEventsResponse;
@@ -83,6 +84,9 @@
import org.oasis.wsrp.v2.RegistrationData;
import org.oasis.wsrp.v2.ReleaseSessions;
import org.oasis.wsrp.v2.ResetProperty;
+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.ServiceDescription;
import org.oasis.wsrp.v2.SessionContext;
@@ -165,6 +169,24 @@
return getMarkup;
}
+ public static GetResource createDefaultResourceRequest(String handle, String
resourceID)
+ {
+ 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}());
@@ -367,6 +389,45 @@
return markupParams;
}
+ public static ResourceParams createDefaultResourceParams(String resourceID)
+ {
+ return createResourceParams(false, WSRPConstants.getDefaultLocales(),
WSRPConstants.getDefaultMimeTypes(),
+ 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");
+ if (locales.isEmpty())
+ {
+ throw new IllegalArgumentException("Cannot create a ResourceParams with an
empty list of locales!");
+ }
+ ParameterValidation.throwIllegalArgExceptionIfNull(mimeTypes, "MIME
types");
+ ParameterValidation.throwIllegalArgExceptionIfNull(stateChange, "State
Change");
+ 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);
+ resourceParams.setWindowState(windowState);
+ if (ParameterValidation.existsAndIsNotEmpty(locales))
+ {
+ 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})
*
@@ -445,6 +506,14 @@
markupResponse.setMarkupContext(markupContext);
return markupResponse;
}
+
+ public static ResourceResponse createResourceResponse(ResourceContext
resourceContext)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(resourceContext,
"ResourceContext");
+ ResourceResponse resourceResponse = new ResourceResponse();
+ resourceResponse.setResourceContext(resourceContext);
+ return resourceResponse;
+ }
/**
* mimeType: The mime type of the returned markup. The mimeType field MUST be
specified whenever markup is returned,
@@ -486,8 +555,56 @@
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.
+ * "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)
+ {
+ return createResourceContext(mediaType, null, resourceBinary);
+ }
+
+ public static ResourceContext createResourceContext(String mediaType, String
resourceString, byte[] resourceBinary)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(mediaType, "MIME
type", "ResourceContext");
+ if ((resourceString == null) && (resourceBinary == null ||
resourceBinary.length == 0))
+ {
+ throw new IllegalArgumentException("MarkupContext requires either a
non-null markup string or binary markup.");
+ }
+
+ ResourceContext resourceContext = new ResourceContext();
+ resourceContext.setMimeType(mediaType);
+
+ if (resourceString != null)
+ {
+ resourceContext.setItemString(resourceString);
+ }
+ else
+ {
+ resourceContext.setItemBinary(resourceBinary);
+ }
+
+ return resourceContext;
+ }
+
+ /**
* @param sessionID An opaque string the Portlet defines for referencing state that is
stored locally on the
* Producer. The maximum length of a sessionID is 4096 characters,
* @param expires Maximum number of seconds between invocations referencing the
sessionID before the Producer will
Modified:
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java
===================================================================
---
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java 2010-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/other/WSRPPortletURLTestCase.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -31,8 +31,10 @@
import org.gatein.wsrp.WSRPRenderURL;
import org.gatein.wsrp.WSRPResourceURL;
import org.gatein.wsrp.WSRPRewritingConstants;
+import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
/**
@@ -49,7 +51,7 @@
WSRPPortletURL.setStrict(true);
}
- public void testResource()
+ public void testResourceURL()
{
String expected =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif"
+
"&wsrp-requiresRewrite=false/wsrp_rewrite";
@@ -59,9 +61,80 @@
WSRPResourceURL resource = (WSRPResourceURL)url;
assertFalse(resource.requiresRewrite());
assertEquals("http://test.com/images/test.gif",
resource.getResourceURL().toExternalForm());
- assertEquals("http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif",
resource.getResourceId());
+
+ //resource.getResourceId will not return the actual resource id, but an encoded
resource map used to determine how to access the resource
+ Map<String, String> resourceMap =
WSRPResourceURL.decodeResource(resource.getResourceId());
+ String resourceURL = resourceMap.get(WSRPRewritingConstants.RESOURCE_URL);
+
assertEquals("http://test.com/images/test.gif", resourceURL);
+
+ assertNull(resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID));
+
assertEquals("false",resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
}
+
+ public void testResourceID()
+ {
+ String expected =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-resourceID=resource_123" +
+ "&wsrp-requiresRewrite=false/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(expected);
+ assertTrue(url instanceof WSRPResourceURL);
+ WSRPResourceURL resource = (WSRPResourceURL)url;
+ assertFalse(resource.requiresRewrite());
+ assertNull(resource.getResourceURL());
+
+ //resource.getResourceId will not return the actual resource id, but an encoded
resource map used to determine how to access the resource
+ Map<String, String> resourceMap =
WSRPResourceURL.decodeResource(resource.getResourceId());
+ String resourceID = resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID);
+ assertEquals("resource_123", resourceID);
+
+ assertNull(resourceMap.get(WSRPRewritingConstants.RESOURCE_URL));
+ assertEquals("false",
resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
+ }
+
+ public void testResources()
+ {
+ String expected =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-resourceID=resource_123" +
+
"&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&wsrp-requiresRewrite=false/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(expected);
+
+ assertTrue(url instanceof WSRPResourceURL);
+ WSRPResourceURL resource = (WSRPResourceURL)url;
+ assertFalse(resource.requiresRewrite());
+
assertEquals("http://test.com/images/test.gif",
resource.getResourceURL().toExternalForm());
+
+ //resource.getResourceId will not return the actual resource id, but an encoded
resource map used to determine how to access the resource
+ Map<String, String> resourceMap =
WSRPResourceURL.decodeResource(resource.getResourceId());
+ String resourceID = resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID);
+ assertEquals("resource_123", resourceID);
+
+ String resourceURL = resourceMap.get(WSRPRewritingConstants.RESOURCE_URL);
+
assertEquals("http://test.com/images/test.gif", resourceURL);
+
assertEquals("false",resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION));
+ }
+
+ public void testPreferOperation()
+ {
+ String expected =
"wsrp_rewrite?wsrp-urlType=resource&wsrp-resourceID=resource_123" +
+
"&wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&wsrp-preferOperation=true&wsrp-requiresRewrite=false/wsrp_rewrite";
+ WSRPPortletURL url = WSRPPortletURL.create(expected);
+
+ assertTrue(url instanceof WSRPResourceURL);
+ WSRPResourceURL resource = (WSRPResourceURL)url;
+ assertFalse(resource.requiresRewrite());
+
assertEquals("http://test.com/images/test.gif",
resource.getResourceURL().toExternalForm());
+
+ //resource.getResourceId will not return the actual resource id, but an encoded
resource map used to determine how to access the resource
+ Map<String, String> resourceMap =
WSRPResourceURL.decodeResource(resource.getResourceId());
+ String resourceID = resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID);
+ assertEquals("resource_123", resourceID);
+
+ String resourceURL = resourceMap.get(WSRPRewritingConstants.RESOURCE_URL);
+
assertEquals("http://test.com/images/test.gif", resourceURL);
+
+ String preferOperation =
resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
+ assertEquals("true", preferOperation);
+ }
+
/** Declare a secure interaction back to the Portlet */
public void testSecureInteraction()
{
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-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ResourceHandler.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -23,6 +23,14 @@
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;
@@ -30,27 +38,38 @@
import org.gatein.common.util.MultiValuedPropertyMap;
import org.gatein.common.util.Tools;
import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.cache.CacheScope;
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.wsrp.WSRPResourceURL;
+import org.gatein.wsrp.WSRPRewritingConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
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.PortletContext;
+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.SessionContext;
import org.oasis.wsrp.v2.UserContext;
-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
{
+ 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);
@@ -59,28 +78,136 @@
@Override
protected void updateUserContext(Object request, UserContext userContext)
{
- //To change body of implemented methods use File | Settings | File Templates.
+ if (request instanceof GetResource)
+ {
+ getResourceRequest(request).setUserContext(userContext);
+ }
}
@Override
protected void updateRegistrationContext(Object request) throws
PortletInvokerException
{
- //To change body of implemented methods use File | Settings | File Templates.
+ if (request instanceof GetResource)
+ {
+
getResourceRequest(request).setRegistrationContext(consumer.getRegistrationContext());
+ }
}
@Override
protected RuntimeContext getRuntimeContextFrom(Object request)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ if (request instanceof GetResource)
+ return getResourceRequest(request).getRuntimeContext();
+ else
+ return null;
}
@Override
+ protected Object prepareRequest(RequestPrecursor requestPrecursor, PortletInvocation
invocation)
+ {
+ if (!(invocation instanceof ResourceInvocation))
+ {
+ throw new IllegalArgumentException("ResourceHandler can only handle
ResourceInvocations!");
+ }
+
+ 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);
+
+ int version = 1;
+ try
+ {
+ version = consumer.getMarkupService().getVersion();
+ }
+ catch (PortletInvokerException portletInvokerException)
+ {
+ 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()))
+ {
+ return prepareGetResourceRequest(requestPrecursor, resourceInvocation,
resourceId);
+ }
+ else
+ {
+ return resourceURL;
+ }
+
+ }
+
+ 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)
+ {
+
resourceParams.setResourceState(invocation.getResourceState().getStringValue());
+ }
+
+ GetResource getResource = WSRPTypeFactory.createResourceRequest(portletContext,
requestPrecursor.runtimeContext, resourceParams);
+
+ return getResource;
+ }
+
+ @Override
protected Object performRequest(Object request) throws Exception
{
- ResourceInvocation invocation = (ResourceInvocation)request;
- String resourceId = invocation.getResourceId();
+ if (request instanceof GetResource)
+ {
+ return performGetResourceRequest((GetResource)request);
+ }
+ else if (request instanceof String)
+ {
+ return performURLRequest((String)request);
+ }
+ else
+ {
+ throw new IllegalArgumentException("ResourceHandler performRequest can only
be called with a GetResource or String object. Received : " + request);
+ }
- URL url = new URL(resourceId);
+ }
+
+ 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>>());
+
+ 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);
URLConnection urlConnection = url.openConnection();
String contentType = urlConnection.getContentType();
@@ -149,28 +276,92 @@
return result;
}
-
+
@Override
- protected Object prepareRequest(RequestPrecursor requestPrecursor, PortletInvocation
invocation)
+ protected PortletInvocationResponse processResponse(Object response, PortletInvocation
invocation, RequestPrecursor requestPrecursor) throws PortletInvokerException
{
- if (!(invocation instanceof ResourceInvocation))
+ if (response instanceof ResourceResponse)
{
- throw new IllegalArgumentException("ResourceHandler can only handle
ResourceInvocations!");
+ return processGetResourceResponse((ResourceResponse)response, invocation,
requestPrecursor);
}
-
- return invocation;
+ else if (response instanceof ContentResponse)
+ {
+ return (ContentResponse) response;
+ }
+ else
+ {
+ throw new PortletInvokerException("Invalid response object: " +
response + ". Expected either a " + ContentResponse.class + " or a " +
ResourceResponse.class);
+ }
}
-
- @Override
- protected PortletInvocationResponse processResponse(Object response, PortletInvocation
invocation, RequestPrecursor requestPrecursor) throws PortletInvokerException
+
+ private PortletInvocationResponse processGetResourceResponse(ResourceResponse
resourceResponse, PortletInvocation invocation, RequestPrecursor requestPrecursor) throws
PortletInvokerException
{
- if (response instanceof ContentResponse)
+ 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 (ContentResponse)response;
+ return new ErrorResponse(new IllegalArgumentException("No MIME type was
provided for portlet content."));
}
- else
+
+ // 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)
{
- throw new PortletInvokerException("Invalid response object: " +
response);
+ 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)
+ {
+ return (GetResource)request;
+ }
+
+ throw new IllegalArgumentException("ResourceHandler: Request is not a
GetResource request!");
+ }
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/MarkupService.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/MarkupService.java 2010-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/MarkupService.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -136,5 +136,6 @@
UserContext userContext)
throws AccessDenied, InvalidRegistration, ModifyRegistrationRequired,
OperationFailed, OperationNotSupported,
ResourceSuspended;
-
+
+ public abstract int getVersion();
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/v1/V1MarkupService.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/v1/V1MarkupService.java 2010-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/v1/V1MarkupService.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -307,4 +307,10 @@
throw V1ToV2Converter.toV2Exception(OperationFailed.class, operationFailed);
}
}
+
+ @Override
+ public int getVersion()
+ {
+ return 1;
+ }
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/v2/V2MarkupService.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/v2/V2MarkupService.java 2010-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/v2/V2MarkupService.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -106,4 +106,10 @@
{
return service.initCookie(registrationContext, userContext);
}
+
+ @Override
+ public int getVersion()
+ {
+ return 2;
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -39,6 +39,7 @@
import org.gatein.pc.portlet.impl.spi.AbstractSecurityContext;
import org.gatein.pc.portlet.impl.spi.AbstractUserContext;
import org.gatein.pc.portlet.impl.spi.AbstractWindowContext;
+import org.gatein.wsrp.WSRPResourceURL;
import org.gatein.wsrp.consumer.ProducerSessionInformation;
import org.gatein.wsrp.test.ExtendedAssert;
import org.gatein.wsrp.test.protocol.v1.BehaviorRegistry;
@@ -66,6 +67,9 @@
import javax.servlet.http.HttpSession;
import javax.xml.ws.Holder;
+
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@@ -208,14 +212,16 @@
ExtendedAssert.assertEquals(3, behavior.getInitCookieCallCount());
}
- public void testResource() throws PortletInvokerException
+ public void testResource() throws PortletInvokerException, MalformedURLException
{
RenderInvocation render =
createRenderInvocation(ResourceMarkupBehavior.PORTLET_HANDLE);
PortletInvocationResponse response = consumer.invoke(render);
- //TODO: fix this test properly, we can't test it properly right now without
creating a new TestPortletInvocationContext as it will disrupt other tests
- checkRenderResult(response, "<img src='Resource
id=http%3A%2F%2Flocalhost%3A8080%2Ftest-resource-portlet%2Fgif%2Flogo.gif ns=null ws=null
m=null'/>");
- //checkRenderResult(response, "<img
src='http://localhost:8080/test-resource-portlet/gif/logo.gif'/>");
+ String resourceID = WSRPResourceURL.encodeResource(null, new
URL("http://localhost:8080/test-resource-portlet/gif/logo.gif"), false);
+ String expectedResult = "<img src='Resource id=" + resourceID +
" ns=null ws=null m=null'/>";
+
+ //NOTE: the value we get back is from the TestPortletInvocationContext, not what we
would normally receive
+ checkRenderResult(response, expectedResult);
}
private ProducerSessionInformation commonInitCookieTest(String handle,
InitCookieMarkupBehavior behavior, String cookieProtocol)
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ActionRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ActionRequestProcessor.java 2010-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ActionRequestProcessor.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -37,6 +37,7 @@
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.PerformBlockingInteraction;
@@ -77,7 +78,7 @@
return performBlockingInteraction.getRuntimeContext();
}
- MarkupParams getMarkupParams()
+ MimeRequest getParams()
{
return performBlockingInteraction.getMarkupParams();
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/EventRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/EventRequestProcessor.java 2010-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/EventRequestProcessor.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -42,6 +42,7 @@
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.OperationNotSupported;
@@ -102,7 +103,7 @@
}
@Override
- MarkupParams getMarkupParams()
+ MimeRequest getParams()
{
return handleEvents.getMarkupParams();
}
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-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupHandler.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -25,6 +25,7 @@
import org.gatein.common.NotYetImplemented;
import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.invocation.response.ContentResponse;
import org.gatein.pc.api.invocation.response.ErrorResponse;
import org.gatein.pc.api.invocation.response.FragmentResponse;
import org.gatein.pc.api.invocation.response.HTTPRedirectionResponse;
@@ -75,6 +76,7 @@
{
static final String PBI = "PerformBlockingInteraction";
static final String GET_MARKUP = "GetMarkup";
+ static final String GET_RESOURCE = "GetResource";
MarkupHandler(WSRPProducerImpl producer)
{
@@ -108,6 +110,33 @@
return (MarkupResponse)requestProcessor.processResponse(response);
}
+ public ResourceResponse getResource(GetResource getResource) throws AccessDenied,
InconsistentParameters,
+ InvalidCookie, InvalidHandle, InvalidRegistration, InvalidSession,
InvalidUserCategory, MissingParameters,
+ ModifyRegistrationRequired, OperationFailed, ResourceSuspended,
UnsupportedLocale, UnsupportedMimeType,
+ UnsupportedMode, UnsupportedWindowState
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getResource,
GET_RESOURCE);
+
+ ResourceRequestProcessor requestProcessor = new ResourceRequestProcessor(producer,
getResource);
+
+ String handle = requestProcessor.getPortletContext().getPortletHandle();
+ PortletInvocationResponse response;
+ try
+ {
+ log.debug("ResourceInvocation on portlet '" + handle +
"'");
+ response =
producer.getPortletInvoker().invoke(requestProcessor.getInvocation());
+ log.debug("ResourceInvocation done");
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not access portlet resource '" + handle + "'", e);
+ }
+
+ checkForError(response);
+
+ return (ResourceResponse)requestProcessor.processResponse(response);
+ }
+
public BlockingInteractionResponse
performBlockingInteraction(PerformBlockingInteraction performBlockingInteraction) throws
InvalidSession, UnsupportedMode, UnsupportedMimeType, OperationFailed,
UnsupportedWindowState, UnsupportedLocale, AccessDenied, PortletStateChangeRequired,
InvalidRegistration, MissingParameters, InvalidUserCategory, InconsistentParameters,
InvalidHandle, InvalidCookie
{
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(performBlockingInteraction,
PBI);
@@ -188,11 +217,6 @@
return (HandleEventsResponse)requestProcessor.processResponse(response);
}
- public ResourceResponse getResource(GetResource getResource) throws AccessDenied,
InconsistentParameters, InvalidCookie, InvalidHandle, InvalidRegistration, InvalidSession,
InvalidUserCategory, MissingParameters, ModifyRegistrationRequired, OperationFailed,
ResourceSuspended, UnsupportedLocale, UnsupportedMimeType, UnsupportedMode,
UnsupportedWindowState
- {
- throw new NotYetImplemented();
- }
-
static void throwOperationFaultOnSessionOperation() throws OperationFailed
{
throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "JBoss
Portal's Producer" +
@@ -221,7 +245,7 @@
throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
errorResult.getMessage(), cause);
}
- else if (!(response instanceof HTTPRedirectionResponse || response instanceof
FragmentResponse || response instanceof UpdateNavigationalStateResponse))
+ else if (!(response instanceof HTTPRedirectionResponse || response instanceof
FragmentResponse || response instanceof UpdateNavigationalStateResponse || response
instanceof ContentResponse))
{
throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Unsupported result type: " + response.getClass().getName(), null);
}
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-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RenderRequestProcessor.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -40,6 +40,7 @@
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;
import org.oasis.wsrp.v2.PortletContext;
@@ -78,7 +79,7 @@
return getMarkup.getRuntimeContext();
}
- MarkupParams getMarkupParams()
+ MimeRequest getParams()
{
return getMarkup.getMarkupParams();
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RequestProcessor.java 2010-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RequestProcessor.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -45,8 +45,8 @@
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.MarkupParams;
import org.oasis.wsrp.v2.MarkupType;
+import org.oasis.wsrp.v2.MimeRequest;
import org.oasis.wsrp.v2.MissingParameters;
import org.oasis.wsrp.v2.NamedString;
import org.oasis.wsrp.v2.NavigationalContext;
@@ -102,8 +102,8 @@
checkForSessionIDs(runtimeContext);
- // get markup parameters
- final MarkupParams params = getMarkupParams();
+ // get parameters
+ final MimeRequest params = getParams();
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(params,
"MarkupParams", getContextName());
// get portlet handle
@@ -176,7 +176,7 @@
abstract RuntimeContext getRuntimeContext();
- abstract MarkupParams getMarkupParams();
+ abstract MimeRequest getParams();
abstract PortletContext getPortletContext();
@@ -200,7 +200,7 @@
* @param portlet
* @return a MarkupRequest containing the most appropriate information to base markup
generation for this request
*/
- private MarkupRequest createMarkupRequestFrom(List<MarkupType> markupTypes,
MarkupParams params, Portlet portlet)
+ private MarkupRequest createMarkupRequestFrom(List<MarkupType> markupTypes,
MimeRequest params, Portlet portlet)
throws UnsupportedMimeType, UnsupportedMode, UnsupportedWindowState
{
List<String> desiredMIMETypes = params.getMimeTypes();
@@ -283,7 +283,7 @@
}
catch (IllegalArgumentException e)
{
- throw WSRP2ExceptionFactory.throwWSException(UnsupportedWindowState.class,
"Unsupported window state '" + params.getMode() + "'", e);
+ throw WSRP2ExceptionFactory.throwWSException(UnsupportedWindowState.class,
"Unsupported window state '" + params.getWindowState() + "'",
e);
}
// get the character set
@@ -400,7 +400,7 @@
return UserContextConverter.createPortalUserContextFrom(userContext,
supportedLocales, preferredLocale);
}
- private PortalContext createPortalContext(final MarkupParams params, final
MarkupRequest markupRequest)
+ private PortalContext createPortalContext(final MimeRequest params, final
MarkupRequest markupRequest)
{
return new PortalContext()
{
@@ -463,7 +463,7 @@
// fix-me: check that the correct semantics is used.
- private SecurityContext createSecurityContext(final MarkupParams params, final
RuntimeContext runtimeContext,
+ private SecurityContext createSecurityContext(final MimeRequest params, final
RuntimeContext runtimeContext,
final org.oasis.wsrp.v2.UserContext
wsrpUserContext)
{
return new SecurityContext()
Added:
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
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ResourceRequestProcessor.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -0,0 +1,229 @@
+/******************************************************************************
+ * 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;
+import org.oasis.wsrp.v2.UnsupportedWindowState;
+import org.oasis.wsrp.v2.UserContext;
+
+/**
+ *
+ * @author <a href="mailto:mwringe@redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class ResourceRequestProcessor extends RequestProcessor
+{
+
+ 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);
+ this.getResource = getResource;
+ 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
+ {
+ return AccessMode.READ_ONLY;
+ }
+
+ @Override
+ String getContextName()
+ {
+ return MarkupHandler.GET_RESOURCE;
+ }
+
+ @Override
+ MimeRequest getParams()
+ {
+ return getResource.getResourceParams();
+ }
+
+ @Override
+ RegistrationContext getRegistrationContext()
+ {
+ return getResource.getRegistrationContext();
+ }
+
+ @Override
+ RuntimeContext getRuntimeContext()
+ {
+ return getResource.getRuntimeContext();
+ }
+
+ @Override
+ UserContext getUserContext()
+ {
+ return getResource.getUserContext();
+ }
+
+ @Override
+ PortletInvocation initInvocation(WSRPPortletInvocationContext context)
+ {
+ // MUST match namespace generation used in PortletResponseImpl.getNamespace in
portlet module...
+ namespace =
PortletUtils.generateNamespaceFrom(context.getWindowContext().getId());
+ ResourceInvocation resourceInvocation = new ResourceInvocation(context);
+
+ ResourceParams resourceParams = this.getResource.getResourceParams();
+
+
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)
+ {
+ CacheLevel cacheLevel =
CacheLevel.valueOf(resourceParams.getResourceCacheability());
+ resourceInvocation.setCacheLevel(cacheLevel);
+ }
+
+ return resourceInvocation;
+ }
+}
+
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-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPPortletInvocationContext.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -136,7 +136,6 @@
if (url instanceof WSRPResourceURL)
{
WSRPResourceURL resourceURL = (WSRPResourceURL)url;
- resourceURL.buildURLWith(request, instanceContext.getPortletContext());
}
return url.toString();
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPRequestContext.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPRequestContext.java 2010-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPRequestContext.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -28,6 +28,7 @@
import org.gatein.pc.api.spi.RequestContext;
import org.oasis.wsrp.v2.InteractionParams;
import org.oasis.wsrp.v2.NamedString;
+import org.oasis.wsrp.v2.ResourceParams;
import org.oasis.wsrp.v2.UploadContext;
import javax.mail.MessagingException;
@@ -231,10 +232,16 @@
public static WSRPRequestContext createRequestContext(MarkupRequest markupRequest,
InteractionParams interactionParams)
{
- List<NamedString> formParams = interactionParams.getFormParameters();
- List<UploadContext> uploadContexts = interactionParams.getUploadContexts();
-
-
+ return createRequestContext(markupRequest, interactionParams.getFormParameters(),
interactionParams.getUploadContexts());
+ }
+
+ public static WSRPRequestContext createRequestContext(MarkupRequest markupRequest,
ResourceParams resourceParams)
+ {
+ return createRequestContext(markupRequest, resourceParams.getFormParameters(),
resourceParams.getUploadContexts());
+ }
+
+ public static WSRPRequestContext createRequestContext(MarkupRequest markupRequest,
List<NamedString> formParams, List<UploadContext> uploadContexts)
+ {
if (uploadContexts != null && !uploadContexts.isEmpty())
{
try
Modified:
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v2/MarkupEndpoint.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v2/MarkupEndpoint.java 2010-07-20
16:10:35 UTC (rev 3666)
+++
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/v2/MarkupEndpoint.java 2010-07-20
19:47:00 UTC (rev 3667)
@@ -31,6 +31,7 @@
import org.oasis.wsrp.v2.EventParams;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.GetMarkup;
+import org.oasis.wsrp.v2.GetResource;
import org.oasis.wsrp.v2.HandleEvents;
import org.oasis.wsrp.v2.HandleEventsFailed;
import org.oasis.wsrp.v2.HandleEventsResponse;
@@ -56,6 +57,7 @@
import org.oasis.wsrp.v2.ReleaseSessions;
import org.oasis.wsrp.v2.ResourceContext;
import org.oasis.wsrp.v2.ResourceParams;
+import org.oasis.wsrp.v2.ResourceResponse;
import org.oasis.wsrp.v2.ResourceSuspended;
import org.oasis.wsrp.v2.ReturnAny;
import org.oasis.wsrp.v2.RuntimeContext;
@@ -182,7 +184,20 @@
InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, OperationNotSupported,
ResourceSuspended, UnsupportedLocale, UnsupportedMimeType, UnsupportedMode,
UnsupportedWindowState
{
- throw new NotYetImplemented();
+ forceSessionAccess();
+ GetResource getResource = new GetResource();
+ getResource.setPortletContext(portletContext.value);
+ getResource.setRegistrationContext(registrationContext);
+ getResource.setResourceParams(resourceParams);
+ getResource.setRuntimeContext(runtimeContext);
+ getResource.setUserContext(userContext);
+
+ ResourceResponse response = producer.getResource(getResource);
+
+ resourceContext.value = response.getResourceContext();
+ sessionContext.value = response.getSessionContext();
+ portletContext.value = response.getPortletContext();
+ extensions.value = response.getExtensions();
}
public void performBlockingInteraction(@WebParam(name =
"registrationContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") RegistrationContext registrationContext,
@WebParam(name = "portletContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") PortletContext portletContext,
@WebParam(name = "runtimeContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") RuntimeContext runtimeContext,
@WebParam(name = "userContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") UserContext userContext, @WebParam(name =
"markupParams", targetNamespace = "urn:oasis:names:tc:wsrp:v2:types")
MarkupParams markupParams, @WebParam(name = "interactionParams", targetNamespace
= "urn:oasis:names:tc:wsrp:v2:types") InteractionParams interactionParams,
@WebParam(name = "updateResponse", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types", mode = WebParam.Mode.OUT)
Holder<UpdateResponse> updateResponse, @WebParam(name = "redirectURL",
targetNamespace = "urn:oasis:na!
mes:tc:wsrp:v2:types", mode = WebParam.Mode.OUT) Holder<String> redirectURL,
@WebParam(name = "extensions", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types", mode = WebParam.Mode.OUT)
Holder<List<Extension>> extensions) throws AccessDenied,
InconsistentParameters, InvalidCookie, InvalidHandle, InvalidRegistration, InvalidSession,
InvalidUserCategory, MissingParameters, ModifyRegistrationRequired, OperationFailed,
PortletStateChangeRequired, ResourceSuspended, UnsupportedLocale, UnsupportedMimeType,
UnsupportedMode, UnsupportedWindowState