Author: chris.laprun(a)jboss.com
Date: 2007-01-10 18:27:44 -0500 (Wed, 10 Jan 2007)
New Revision: 5987
Added:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ActionRequestProcessor.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupRequest.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RequestProcessor.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPInstanceContext.java
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/invocation/WSRPActionContext.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
Log:
- Re-factored MarkupHandler to extract common code into RequestProcessor and sub-classes.
- Use portlet context where appropriate.
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/invocation/WSRPActionContext.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/invocation/WSRPActionContext.java 2007-01-10
22:41:12 UTC (rev 5986)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/invocation/WSRPActionContext.java 2007-01-10
23:27:44 UTC (rev 5987)
@@ -58,7 +58,7 @@
public WSRPActionContext(StateString navigationalState,
SecurityContext securityContext, HTTPStreamInfo streamInfo,
PortalContext portalContext,
UserContext userContext, InstanceContext instanceContext,
WindowContext windowContext,
- StateString interactionState, Mode mode, WindowState
windowState,
+ Mode mode, WindowState windowState, StateString
interactionState,
PortletParameters formParameters, String characterEncoding,
String contentType)
{
super(navigationalState, securityContext, streamInfo, portalContext, userContext,
instanceContext,
Added: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ActionRequestProcessor.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ActionRequestProcessor.java 2007-01-10
22:41:12 UTC (rev 5986)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ActionRequestProcessor.java 2007-01-10
23:27:44 UTC (rev 5987)
@@ -0,0 +1,204 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, 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.jboss.portal.wsrp.producer;
+
+import org.jboss.portal.portlet.PortletParameters;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.invocation.ActionInvocation;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.RenderResponse;
+import org.jboss.portal.portlet.spi.PortalContext;
+import org.jboss.portal.portlet.spi.SecurityContext;
+import org.jboss.portal.portlet.spi.UserContext;
+import org.jboss.portal.portlet.spi.WindowContext;
+import org.jboss.portal.portlet.state.AccessMode;
+import org.jboss.portal.server.util.HTTPStreamInfo;
+import org.jboss.portal.wsrp.WSRPTypeFactory;
+import org.jboss.portal.wsrp.WSRPUtils;
+import org.jboss.portal.wsrp.core.InteractionParams;
+import org.jboss.portal.wsrp.core.InvalidHandleFault;
+import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
+import org.jboss.portal.wsrp.core.MarkupParams;
+import org.jboss.portal.wsrp.core.MissingParametersFault;
+import org.jboss.portal.wsrp.core.NamedString;
+import org.jboss.portal.wsrp.core.OperationFailedFault;
+import org.jboss.portal.wsrp.core.PerformBlockingInteraction;
+import org.jboss.portal.wsrp.core.PortletContext;
+import org.jboss.portal.wsrp.core.RegistrationContext;
+import org.jboss.portal.wsrp.core.RuntimeContext;
+import org.jboss.portal.wsrp.core.StateChange;
+import org.jboss.portal.wsrp.core.UnsupportedMimeTypeFault;
+import org.jboss.portal.wsrp.core.UnsupportedModeFault;
+import org.jboss.portal.wsrp.core.UnsupportedWindowStateFault;
+import org.jboss.portal.wsrp.core.UpdateResponse;
+import org.jboss.portal.wsrp.invocation.WSRPActionContext;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+class ActionRequestProcessor extends RequestProcessor
+{
+ private final PerformBlockingInteraction performBlockingInteraction;
+ private final InteractionParams interactionParams;
+
+ public ActionRequestProcessor(WSRPProducerImpl producer, PerformBlockingInteraction
performBlockingInteraction, InteractionParams interactionParams)
+ throws UnsupportedMimeTypeFault, UnsupportedWindowStateFault, InvalidHandleFault,
UnsupportedModeFault,
+ MissingParametersFault, InvalidRegistrationFault, OperationFailedFault
+ {
+ super(producer);
+ this.performBlockingInteraction = performBlockingInteraction;
+ this.interactionParams = interactionParams;
+ prepareInvocation();
+ }
+
+ RegistrationContext getRegistrationContext()
+ {
+ return performBlockingInteraction.getRegistrationContext();
+ }
+
+ RuntimeContext getRuntimeContext()
+ {
+ return performBlockingInteraction.getRuntimeContext();
+ }
+
+ MarkupParams getMarkupParams()
+ {
+ return performBlockingInteraction.getMarkupParams();
+ }
+
+ PortletContext getPortletContext()
+ {
+ return performBlockingInteraction.getPortletContext();
+ }
+
+ org.jboss.portal.wsrp.core.UserContext getUserContext()
+ {
+ return performBlockingInteraction.getUserContext();
+ }
+
+ String getContextName()
+ {
+ return MarkupHandler.PBI;
+ }
+
+ AccessMode getAccessMode() throws MissingParametersFault
+ {
+ StateChange stateChange = interactionParams.getPortletStateChange();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(stateChange,
"portletStateChange", "InteractionParams");
+ return WSRPUtils.getAccessModeFromStateChange(stateChange);
+ }
+
+ void initInvocation(StateString navigationalState, SecurityContext securityContext,
+ HTTPStreamInfo streamInfo, PortalContext portalContext,
+ UserContext userContext,
+ WindowContext windowContext
+ )
+ {
+ PortletParameters parameters;
+ NamedString[] formParams = interactionParams.getFormParameters();
+ if (formParams != null && formParams.length > 0)
+ {
+ int length = formParams.length;
+ Map params = new HashMap(length);
+ for (int i = 0; i < length; i++)
+ {
+ NamedString formParam = formParams[i];
+ String paramName = formParam.getName();
+ String paramValue = formParam.getValue();
+ if (params.containsKey(paramName))
+ {
+ // handle multi-valued parameters...
+ String[] oldValues = (String[])params.get(paramName);
+ int valuesLength = oldValues.length;
+ String[] newValues = new String[valuesLength + 1];
+ System.arraycopy(oldValues, 0, newValues, 0, valuesLength);
+ newValues[valuesLength] = paramValue;
+ params.put(paramName, newValues);
+ }
+ else
+ {
+ params.put(paramName, new String[]{paramValue});
+ }
+ }
+ parameters = new PortletParameters(params);
+ }
+ else
+ {
+ parameters = new PortletParameters();
+ }
+
+ StateString interactionState =
createNavigationalState(interactionParams.getInteractionState());
+
+ WSRPActionContext actionContext = new WSRPActionContext(navigationalState,
securityContext, streamInfo,
+ portalContext, userContext, instanceContext, windowContext,
+ WSRPUtils.getJSR168PortletModeFromWSRPName(markupRequest.getMode()),
+ WSRPUtils.getJSR168WindowStateFromWSRPName(markupRequest.getWindowState()),
interactionState, parameters,
+ markupRequest.getCharacterSet(), markupRequest.getMimeType());
+ setInvocation(new ActionInvocation(actionContext));
+ actionContext.contextualize(invocation);
+ invocation.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE, portlet.getContext());
+ }
+
+ Object processResponse(PortletInvocationResponse response)
+ {
+ if (response instanceof RenderResponse)
+ {
+ RenderResponse renderResult = (RenderResponse)response;
+ UpdateResponse updateResponse = WSRPTypeFactory.createUpdateResponse();
+
updateResponse.setNewMode(WSRPUtils.convertJSR168PortletModeNameToWSRPName(getNewStateOrNull(renderResult,
true)));
+
updateResponse.setNewWindowState(WSRPUtils.convertJSR168WindowStateNameToWSRPName(getNewStateOrNull(renderResult,
false)));
+ StateString ns = renderResult.getNavigationalState();
+ updateResponse.setNavigationalState(ns != null ? ns.getStringValue() : null);
+
+ // deal with implicit cloning and state modification
+ if (instanceContext.wasModified())
+ {
+ PortletContext updatedPortletContext =
WSRPTypeFactory.createPortletContext(instanceContext.getId());
+ updatedPortletContext.setPortletState(instanceContext.getState());
+ updateResponse.setPortletContext(updatedPortletContext);
+ }
+
+ return WSRPTypeFactory.createBlockingInteractionResponse(updateResponse);
+ }
+ else
+ {
+ // result should be HTTPRedirectionResult
+ HTTPRedirectionResponse redirectionResult = (HTTPRedirectionResponse)response;
+ return
WSRPTypeFactory.createBlockingInteractionResponse(redirectionResult.getLocation());
+ }
+ }
+
+ private String getNewStateOrNull(RenderResponse renderResult, boolean forMode)
+ {
+ Object state = forMode ? (Object)renderResult.getMode() :
renderResult.getWindowState();
+ return state != null ? state.toString() : null;
+ }
+}
Property changes on:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ActionRequestProcessor.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java 2007-01-10
22:41:12 UTC (rev 5986)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java 2007-01-10
23:27:44 UTC (rev 5987)
@@ -24,36 +24,13 @@
package org.jboss.portal.wsrp.producer;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.MediaType;
-import org.jboss.portal.common.util.LocaleInfo;
-import org.jboss.portal.common.util.ParameterValidation;
-import org.jboss.portal.portlet.OpaqueStateString;
-import org.jboss.portal.portlet.PortletParameters;
-import org.jboss.portal.portlet.Portlet;
-import org.jboss.portal.portlet.PortletInvoker;
import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.StateEvent;
-import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.info.CacheInfo;
-import org.jboss.portal.portlet.invocation.ActionInvocation;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.invocation.RenderInvocation;
import org.jboss.portal.portlet.invocation.response.ErrorResponse;
import org.jboss.portal.portlet.invocation.response.FragmentResponse;
import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.invocation.response.RenderResponse;
-import org.jboss.portal.portlet.spi.InstanceContext;
-import org.jboss.portal.portlet.spi.PortalContext;
-import org.jboss.portal.portlet.spi.SecurityContext;
-import org.jboss.portal.portlet.spi.UserContext;
-import org.jboss.portal.portlet.spi.WindowContext;
-import org.jboss.portal.portlet.state.AccessMode;
import org.jboss.portal.portlet.state.producer.PortletStateChangeRequiredException;
-import org.jboss.portal.server.util.HTTPStreamInfo;
-import org.jboss.portal.wsrp.UserContextConverter;
-import org.jboss.portal.wsrp.WSRPConstants;
-import org.jboss.portal.wsrp.WSRPTypeFactory;
import org.jboss.portal.wsrp.WSRPUtils;
import org.jboss.portal.wsrp.core.AccessDeniedFault;
import org.jboss.portal.wsrp.core.BlockingInteractionResponse;
@@ -66,44 +43,23 @@
import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
import org.jboss.portal.wsrp.core.InvalidSessionFault;
import org.jboss.portal.wsrp.core.InvalidUserCategoryFault;
-import org.jboss.portal.wsrp.core.MarkupContext;
-import org.jboss.portal.wsrp.core.MarkupParams;
import org.jboss.portal.wsrp.core.MarkupResponse;
-import org.jboss.portal.wsrp.core.MarkupType;
import org.jboss.portal.wsrp.core.MissingParametersFault;
-import org.jboss.portal.wsrp.core.NamedString;
import org.jboss.portal.wsrp.core.OperationFailedFault;
import org.jboss.portal.wsrp.core.PerformBlockingInteraction;
-import org.jboss.portal.wsrp.core.PortletContext;
-import org.jboss.portal.wsrp.core.PortletDescription;
import org.jboss.portal.wsrp.core.PortletStateChangeRequiredFault;
import org.jboss.portal.wsrp.core.ReleaseSessions;
import org.jboss.portal.wsrp.core.ReturnAny;
-import org.jboss.portal.wsrp.core.RuntimeContext;
-import org.jboss.portal.wsrp.core.StateChange;
import org.jboss.portal.wsrp.core.UnsupportedLocaleFault;
import org.jboss.portal.wsrp.core.UnsupportedMimeTypeFault;
import org.jboss.portal.wsrp.core.UnsupportedModeFault;
import org.jboss.portal.wsrp.core.UnsupportedWindowStateFault;
-import org.jboss.portal.wsrp.core.UpdateResponse;
import org.jboss.portal.wsrp.core.UploadContext;
import org.jboss.portal.wsrp.core.WSRP_v1_Markup_PortType;
-import org.jboss.portal.wsrp.invocation.WSRPActionContext;
-import org.jboss.portal.wsrp.invocation.WSRPRenderContext;
-import javax.activation.MimeTypeParseException;
import javax.portlet.PortletModeException;
import javax.portlet.WindowStateException;
import java.rmi.RemoteException;
-import java.security.Principal;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -112,15 +68,12 @@
*/
class MarkupHandler extends ServiceHandler implements WSRP_v1_Markup_PortType
{
- private static final String WINDOW_STATE = "window state";
- private static final String PORTLET_MODE = "portlet mode";
- private static final String PBI = "PerformBlockingInteraction";
- private static final String GET_MARKUP = "GetMarkup";
+ static final String PBI = "PerformBlockingInteraction";
+ static final String GET_MARKUP = "GetMarkup";
private Logger log = Logger.getLogger(MarkupHandler.class);
- private static final String EMPTY = "";
- private static final String CHARSET_SEPARATOR = "; charset=";
+
MarkupHandler(WSRPProducerImpl producer)
{
super(producer);
@@ -134,71 +87,16 @@
OperationFailedFault, MissingParametersFault, InvalidUserCategoryFault,
InvalidRegistrationFault,
UnsupportedMimeTypeFault, RemoteException
{
+
WSRPUtils.throwOperationFailedFaultIfValueIsMissing(getMarkup, GET_MARKUP);
- producer.checkRegistration(getMarkup.getRegistrationContext());
- // get session information and deal with it
- final RuntimeContext runtimeContext = getMarkup.getRuntimeContext();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(runtimeContext,
"RuntimeContext", GET_MARKUP);
+ RequestProcessor requestProcessor = new RenderRequestProcessor(producer,
getMarkup);
- checkForSessionIDs(runtimeContext);
-
- // get markup parameters
- final MarkupParams params = getMarkup.getMarkupParams();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(params,
"MarkupParams", GET_MARKUP);
-
- // get portlet handle
- PortletContext portletContext = getMarkup.getPortletContext();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext,
"PortletContext", GET_MARKUP);
- final String portletHandle = portletContext.getPortletHandle();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletHandle, "portlet
handle", "PortletContext");
-
- // retrieve the portlet
- Portlet portlet;
- try
- {
- portlet = producer.getPortletWith(portletHandle);
- }
- catch (PortletInvokerException e)
- {
- throw WSRPUtils.createOperationFailedFault(e);
- }
-
- // get portlet description for the desired portlet...
- final String[] desiredLocales = params.getLocales();
- PortletDescription portletDescription =
producer.getPortletDescription(portletHandle, desiredLocales);
- MarkupType[] markupTypes = portletDescription.getMarkupTypes();
-
- // based on the markup parameters and portlet description generate the most
appropriate markup request
- final MarkupRequest markupRequest = createMarkupRequestFrom(markupTypes, params,
portlet);
-
- // prepare information for invocation
- StateString navigationalState =
createNavigationalState(params.getNavigationalState());
-
- final org.jboss.portal.wsrp.core.UserContext wsrpUserContext =
getMarkup.getUserContext();
- checkUserContext(wsrpUserContext);
-
- SecurityContext securityContext = createSecurityContext(params, runtimeContext,
wsrpUserContext);
- HTTPStreamInfo streamInfo = createStreamInfo(markupRequest);
- PortalContext portalContext = createPortalContext(params, markupRequest);
- UserContext userContext = createUserContext(wsrpUserContext,
markupRequest.getLocale(), desiredLocales);
- InstanceContext instanceContext = createInstanceContext(portletHandle,
AccessMode.READ_ONLY);
- WindowContext windowContext = createWindowContext(portletHandle, runtimeContext);
-
- // prepare the invocation
- WSRPRenderContext renderContext = new WSRPRenderContext(navigationalState,
securityContext, streamInfo,
- portalContext, userContext, instanceContext, windowContext,
- WSRPUtils.getJSR168PortletModeFromWSRPName(markupRequest.getMode()),
- WSRPUtils.getJSR168WindowStateFromWSRPName(markupRequest.getWindowState()));
- RenderInvocation render = new RenderInvocation(renderContext);
- renderContext.contextualize(render);
- render.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE, portlet.getContext());
-
PortletInvocationResponse response;
try
{
- log.debug("RenderInvocation on portlet '" + portletHandle +
"'");
- response = producer.getInvoker().invoke(render);
+ log.debug("RenderInvocation on portlet '" +
requestProcessor.getPortletContext().getPortletHandle() + "'");
+ response = producer.getInvoker().invoke(requestProcessor.getInvocation());
log.debug("RenderInvocation done");
}
catch (PortletInvokerException e)
@@ -208,64 +106,9 @@
checkForError(response);
- FragmentResponse fragment = (FragmentResponse)response;
- String markupString = null;
- byte[] markupBinary = null;
- switch (fragment.getType())
- {
- case FragmentResponse.TYPE_CHARS:
- markupString = fragment.getChars().toString();
- break;
- case FragmentResponse.TYPE_BYTES:
- markupBinary = fragment.getBytes().toByteArray(); // 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.getMimeType(),
markupString);
- }
- else
- {
- markupContext =
WSRPTypeFactory.createMarkupContext(markupRequest.getMimeTypeWithCharset(),
markupBinary);
- }
- markupContext.setLocale(markupRequest.getLocale());
- markupContext.setRequiresUrlRewriting(Boolean.TRUE);
- markupContext.setPreferredTitle(portletDescription.getTitle().getValue());
-
- // cache information
- CacheInfo cacheInfo = portlet.getInfo().getCache();
- if (cacheInfo != null)
- {
- int expires = cacheInfo.getExpirationSecs();
- // only create a CacheControl if expiration time is not 0
- if (expires != 0)
- {
- markupContext.setCacheControl(WSRPTypeFactory.createCacheControl(expires,
WSRPConstants.CACHE_PER_USER));
- }
- }
-
- return new MarkupResponse(markupContext, null, null);
+ return (MarkupResponse)requestProcessor.processResponse(response);
}
- private void checkForSessionIDs(RuntimeContext runtimeContext) throws
OperationFailedFault
- {
- if (runtimeContext.getSessionID() != null)
- {
- throwOperationFaultOnSessionOperation();
- }
- }
-
- private void throwOperationFaultOnSessionOperation() throws OperationFailedFault
- {
- throw WSRPUtils.createOperationFailedFault(new IllegalArgumentException("JBoss
Portal's Producer manages " +
- "sessions completely on the server side, passing or trying to release
sessionIDs is therefore an error."));
- }
-
public BlockingInteractionResponse
performBlockingInteraction(PerformBlockingInteraction performBlockingInteraction)
throws InvalidSessionFault, UnsupportedModeFault, UnsupportedMimeTypeFault,
OperationFailedFault,
UnsupportedWindowStateFault, UnsupportedLocaleFault, AccessDeniedFault,
PortletStateChangeRequiredFault,
@@ -273,9 +116,7 @@
InvalidHandleFault, InvalidCookieFault, RemoteException
{
WSRPUtils.throwOperationFailedFaultIfValueIsMissing(performBlockingInteraction,
PBI);
- producer.checkRegistration(performBlockingInteraction.getRegistrationContext());
-
- InteractionParams interactionParams =
performBlockingInteraction.getInteractionParams();
+ final InteractionParams interactionParams =
performBlockingInteraction.getInteractionParams();
WSRPUtils.throwMissingParametersFaultIfValueIsMissing(interactionParams,
"InteractionParams", PBI);
// fix-me: upload contexts are not supported, fail fast!
@@ -285,106 +126,14 @@
throw WSRPUtils.createOperationFailedFault(new
UnsupportedOperationException("UploadContexts are not currently supported."));
}
- PortletContext portletContext = performBlockingInteraction.getPortletContext();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext,
"PortletContext", PBI);
- String portletHandle = portletContext.getPortletHandle();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletHandle, "portlet
handle", "PortletContext");
- RuntimeContext runtimeContext = performBlockingInteraction.getRuntimeContext();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(runtimeContext,
"RuntimeContext", PBI);
+ RequestProcessor requestProcessor = new ActionRequestProcessor(producer,
performBlockingInteraction, interactionParams);
- org.jboss.portal.wsrp.core.UserContext wsrpUserContext =
performBlockingInteraction.getUserContext();
- checkUserContext(wsrpUserContext);
-
- PortletInvoker invoker = producer.getInvoker();
- final Portlet portlet;
- try
- {
- portlet =
invoker.getPortlet(org.jboss.portal.portlet.PortletContext.createPortletContext(portletHandle));
- }
- catch (PortletInvokerException e)
- {
- throw WSRPUtils.createOperationFailedFault(e);
- }
- MarkupParams markupParams = performBlockingInteraction.getMarkupParams();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(markupParams,
"MarkupParams", PBI);
-
- // get portlet description for the desired portlet...
- final String[] desiredLocales = markupParams.getLocales();
- PortletDescription portletDescription =
producer.getPortletDescription(portletHandle, desiredLocales);
- if (Boolean.TRUE.equals(portletDescription.getUsesMethodGet()))
- {
- throw WSRPUtils.createOperationFailedFault(
- new UnsupportedOperationException("Portlets using GET method in forms
are not currently supported."));
- }
- MarkupType[] markupTypes = portletDescription.getMarkupTypes();
-
- // based on the markup parameters and portlet description generate the most
appropriate markup request
- final MarkupRequest markupRequest = createMarkupRequestFrom(markupTypes,
markupParams, portlet);
-
- // create information for action context
- StateString navigationalState =
createNavigationalState(markupParams.getNavigationalState());
- SecurityContext securityContext = createSecurityContext(markupParams,
runtimeContext, wsrpUserContext);
- HTTPStreamInfo streamInfo = createStreamInfo(markupRequest);
- PortalContext portalContext = createPortalContext(markupParams, markupRequest);
- UserContext userContext = createUserContext(wsrpUserContext,
markupRequest.getLocale(), desiredLocales);
- WindowContext windowContext = createWindowContext(portletHandle, runtimeContext);
-
- StateChange stateChange = interactionParams.getPortletStateChange();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(stateChange,
"portletStateChange", "InteractionParams");
- WSRPInstanceContext instanceContext = createInstanceContext(portletHandle,
WSRPUtils.getAccessModeFromStateChange(stateChange));
-
-
- PortletParameters parameters;
- NamedString[] formParams = interactionParams.getFormParameters();
- if (formParams != null && formParams.length > 0)
- {
- int length = formParams.length;
- Map params = new HashMap(length);
- for (int i = 0; i < length; i++)
- {
- NamedString formParam = formParams[i];
- String paramName = formParam.getName();
- String paramValue = formParam.getValue();
- if (params.containsKey(paramName))
- {
- // handle multi-valued parameters...
- String[] oldValues = (String[])params.get(paramName);
- int valuesLength = oldValues.length;
- String[] newValues = new String[valuesLength + 1];
- System.arraycopy(oldValues, 0, newValues, 0, valuesLength);
- newValues[valuesLength] = paramValue;
- params.put(paramName, newValues);
- }
- else
- {
- params.put(paramName, new String[]{paramValue});
- }
- }
- parameters = new PortletParameters(params);
- }
- else
- {
- parameters = new PortletParameters();
- }
- log.debug("form parameters:\n" + parameters);
-
- StateString interactionState =
createNavigationalState(interactionParams.getInteractionState());
-
- WSRPActionContext context = new WSRPActionContext(navigationalState,
securityContext, streamInfo,
- portalContext, userContext, instanceContext, windowContext,
- interactionState,
WSRPUtils.getJSR168PortletModeFromWSRPName(markupRequest.getMode()),
- WSRPUtils.getJSR168WindowStateFromWSRPName(markupRequest.getWindowState()),
parameters,
- markupRequest.getCharacterSet(), markupRequest.getMimeType());
- ActionInvocation invocation = new ActionInvocation(context);
- context.contextualize(invocation);
- invocation.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE, portlet.getContext());
-
PortletInvocationResponse response;
try
{
- log.debug("ActionInvocation on portlet '" + portletHandle +
"'");
- response = producer.getInvoker().invoke(invocation);
+ log.debug("ActionInvocation on portlet '" +
requestProcessor.getPortletContext().getPortletHandle() + "'");
+ response = producer.getInvoker().invoke(requestProcessor.getInvocation());
log.debug("ActionInvocation done");
}
catch (PortletStateChangeRequiredException e)
@@ -393,44 +142,34 @@
}
catch (PortletInvokerException e)
{
- log.fatal(e);
throw WSRPUtils.createOperationFailedFault(e);
}
checkForError(response);
- if (response instanceof RenderResponse)
- {
- RenderResponse renderResult = (RenderResponse)response;
- UpdateResponse updateResponse = WSRPTypeFactory.createUpdateResponse();
-
updateResponse.setNewMode(WSRPUtils.convertJSR168PortletModeNameToWSRPName(getNewStateOrNull(renderResult,
true)));
-
updateResponse.setNewWindowState(WSRPUtils.convertJSR168WindowStateNameToWSRPName(getNewStateOrNull(renderResult,
false)));
- StateString ns = renderResult.getNavigationalState();
- updateResponse.setNavigationalState(ns != null ? ns.getStringValue() : null);
+ return (BlockingInteractionResponse)requestProcessor.processResponse(response);
+ }
- // deal with implicit cloning and state modification
- if (instanceContext.wasModified())
- {
- PortletContext updatedPortletContext =
WSRPTypeFactory.createPortletContext(instanceContext.getId());
- updatedPortletContext.setPortletState(instanceContext.getState());
- updateResponse.setPortletContext(updatedPortletContext);
- }
+ public ReturnAny releaseSessions(ReleaseSessions releaseSessions)
+ throws InvalidRegistrationFault, OperationFailedFault, MissingParametersFault,
AccessDeniedFault, RemoteException
+ {
+ throwOperationFaultOnSessionOperation();
+ return null;
+ }
+ public ReturnAny initCookie(InitCookie initCookie)
+ throws AccessDeniedFault, OperationFailedFault, InvalidRegistrationFault,
RemoteException
+ {
+ WSRPUtils.throwOperationFailedFaultIfValueIsMissing(initCookie,
"InitCookie");
+ producer.checkRegistration(initCookie.getRegistrationContext());
- return WSRPTypeFactory.createBlockingInteractionResponse(updateResponse);
- }
- else
- {
- // result should be HTTPRedirectionResult
- HTTPRedirectionResponse redirectionResult = (HTTPRedirectionResponse)response;
- return
WSRPTypeFactory.createBlockingInteractionResponse(redirectionResult.getLocation());
- }
+ return new ReturnAny(); // todo: implement when actually needed
}
- private String getNewStateOrNull(RenderResponse renderResult, boolean forMode)
+ static void throwOperationFaultOnSessionOperation() throws OperationFailedFault
{
- Object state = forMode ? (Object)renderResult.getMode() :
renderResult.getWindowState();
- return state != null ? state.toString() : null;
+ throw WSRPUtils.createOperationFailedFault(new IllegalArgumentException("JBoss
Portal's Producer manages " +
+ "sessions completely on the server side, passing or trying to release
sessionIDs is therefore an error."));
}
private void checkForError(PortletInvocationResponse response)
@@ -468,459 +207,4 @@
+ response.getClass().getName()));
}
}
-
- public ReturnAny releaseSessions(ReleaseSessions releaseSessions)
- throws InvalidRegistrationFault, OperationFailedFault, MissingParametersFault,
AccessDeniedFault, RemoteException
- {
- throwOperationFaultOnSessionOperation();
- return null;
- }
-
- public ReturnAny initCookie(InitCookie initCookie)
- throws AccessDeniedFault, OperationFailedFault, InvalidRegistrationFault,
RemoteException
- {
- WSRPUtils.throwOperationFailedFaultIfValueIsMissing(initCookie,
"InitCookie");
- producer.checkRegistration(initCookie.getRegistrationContext());
-
- return new ReturnAny(); // todo: implement when actually needed
- }
-
- // Parameter checking methods
***************************************************************************************
-
- private void checkUserContext(org.jboss.portal.wsrp.core.UserContext wsrpUserContext)
throws MissingParametersFault
- {
- if (wsrpUserContext != null)
- {
-
WSRPUtils.throwMissingParametersFaultIfValueIsMissing(wsrpUserContext.getUserContextKey(),
"User Context Key", "UserContext");
- }
- }
-
- // Invocation support methods
***************************************************************************************
- private StateString createNavigationalState(String navigationalState)
- {
- // fix-me: create opaque NS and implement an interceptor that does conversion to
jboss NS
-// PortletNavigationalState navigationalState = new
OpaquePortletNavigationalState(navigationalState);
- if (navigationalState == null)
- {
- return null;
- }
- else
- {
- return new OpaqueStateString(navigationalState);
- }
- }
-
- private WSRPInstanceContext createInstanceContext(final String portletHandle, final
AccessMode accessMode)
- {
- return new WSRPInstanceContext(portletHandle, accessMode);
- }
-
- private WindowContext createWindowContext(final String portletHandle, final
RuntimeContext runtimeContext)
- {
- return new WindowContext()
- {
- public String getId()
- {
- String prefix = runtimeContext.getNamespacePrefix();
- if (prefix != null && prefix.length() > 0)
- {
- return prefix;
- }
- else
- {
- log.debug("No provided namespace prefix for portlet '" +
portletHandle + "'. Using portlet handle as namespace.");
- return portletHandle;
- }
- }
- };
- }
-
- private UserContext createUserContext(final org.jboss.portal.wsrp.core.UserContext
userContext,
- String preferredLocale, final String[]
supportedLocales)
- {
- // todo: investigate ways to cache this information?
- // fix-me: should getInformations be put in the request attribute
PortletRequest.USER_INFO?
- return UserContextConverter.createPortalUserContextFrom(userContext,
supportedLocales, preferredLocale);
- }
-
- private PortalContext createPortalContext(final MarkupParams params, final
MarkupHandler.MarkupRequest markupRequest)
- {
- return new PortalContext()
- {
- public Set getWindowStates()
- {
- String[] validNewWindowStates = params.getValidNewWindowStates();
- if (validNewWindowStates != null)
- {
- Set states = new HashSet(validNewWindowStates.length);
- for (int i = 0; i < validNewWindowStates.length; i++)
- {
- String state = validNewWindowStates[i];
- states.add(WSRPUtils.getJSR168WindowStateFromWSRPName(state));
- }
- return states;
- }
- return markupRequest.getSupportedWindowStates();
- }
-
- public Set getModes()
- {
- String[] validNewModes = params.getValidNewModes();
- if (validNewModes != null)
- {
- Set modes = new HashSet(validNewModes.length);
- for (int i = 0; i < validNewModes.length; i++)
- {
- String mode = validNewModes[i];
- modes.add(WSRPUtils.getJSR168PortletModeFromWSRPName(mode));
- }
- return modes;
- }
- return markupRequest.getSupportedModes();
- }
-
- public Map getProperties()
- {
- return Collections.EMPTY_MAP;
- }
- };
- }
-
- private HTTPStreamInfo createStreamInfo(MarkupRequest markupRequest)
- throws UnsupportedMimeTypeFault
- {
- HTTPStreamInfo streamInfo;
- try
- {
- streamInfo = new
HTTPStreamInfo(MediaType.parseMimeType(markupRequest.getMimeType()),
markupRequest.getCharacterSet());
- }
- catch (MimeTypeParseException e)
- {
- throw
(UnsupportedMimeTypeFault)WSRPUtils.createFaultFrom(UnsupportedMimeTypeFault.class, e);
- }
- return streamInfo;
- }
-
- // fix-me: check that the correct semantics is used.
- private SecurityContext createSecurityContext(final MarkupParams params, final
RuntimeContext runtimeContext,
- final
org.jboss.portal.wsrp.core.UserContext wsrpUserContext)
- {
- return new SecurityContext()
- {
- public boolean isSecure()
- {
- return params.isSecureClientCommunication();
- }
-
- public String getAuthType()
- {
- return runtimeContext.getUserAuthentication();
- }
-
- public String getRemoteUser()
- {
- if (wsrpUserContext != null)
- {
- return wsrpUserContext.getUserContextKey();
- }
- return null;
- }
-
- public Principal getUserPrincipal()
- {
- return null;
- }
-
- public boolean isUserInRole(String roleName)
- {
- if (wsrpUserContext != null)
- {
- List userCategories = Arrays.asList(wsrpUserContext.getUserCategories());
- return userCategories.contains(roleName);
- }
- return false;
- }
-
- public boolean isAuthenticated()
- {
- return wsrpUserContext != null;
- }
- };
- }
-
- /**
- * Returns the most appropriate information to base markup generation on based on a
Portlet's specified markup types
- * and a markup request parameters.
- *
- * @param markupTypes the Portlet's specified markup types
- * @param params the markup request parameters
- * @param portlet
- * @return a MarkupRequest containing the most appropriate information to base markup
generation for this request
- */
- private MarkupRequest createMarkupRequestFrom(MarkupType[] markupTypes, MarkupParams
params, Portlet portlet)
- throws UnsupportedMimeTypeFault, UnsupportedModeFault, UnsupportedWindowStateFault
- {
- String[] desiredMIMETypes = params.getMimeTypes();
- MarkupType markupType = null;
-
- // Get the MIME type to use
- for (int i = 0; markupType == null && i < desiredMIMETypes.length; i++)
- {
- String desiredMIMEType = desiredMIMETypes[i];
- for (int j = 0; j < markupTypes.length; j++)
- {
- if (desiredMIMEType.equalsIgnoreCase(markupTypes[j].getMimeType()))
- {
- markupType = markupTypes[j];
- break;
- }
- }
- }
-
- // no MIME type was found: error!
- if (markupType == null)
- {
- throw
(UnsupportedMimeTypeFault)WSRPUtils.createFaultFrom(UnsupportedMimeTypeFault.class,
- new IllegalArgumentException("None of the specified MIME types are
supported by this Portlet."));
- }
-
- // get the mode
- String mode = null;
- try
- {
- mode = getMatchingOrFailFrom(markupType.getModes(), params.getMode(),
PORTLET_MODE);
- }
- catch (IllegalArgumentException e)
- {
- throw
(UnsupportedModeFault)WSRPUtils.createFaultFrom(UnsupportedModeFault.class, e);
- }
-
- // get the window state
- String windowState = null;
- try
- {
- windowState = getMatchingOrFailFrom(markupType.getWindowStates(),
params.getWindowState(), WINDOW_STATE);
- }
- catch (IllegalArgumentException e)
- {
- throw
(UnsupportedWindowStateFault)WSRPUtils.createFaultFrom(UnsupportedWindowStateFault.class,
e);
- }
-
- // get the character set
- String characterSet = getMatchingOrDefaultFrom(new String[0],
params.getMarkupCharacterSets(), WSRPConstants.DEFAULT_CHARACTER_SET);
-
- return new MarkupRequest(markupType, mode, windowState, characterSet, portlet);
- }
-
- /**
- * Retrieves the desired value from the set of possible values if such value exists or
throw an
- * <code>IllegalArgumentException</code>.
- *
- * @param possibleValues the set of supported values
- * @param desired the desired value
- * @param valueType a name identifying the type of the desired value (for error
reporting purpose)
- * @return the desired value
- * @throws IllegalArgumentException if the desired value is not found in the set of
possible values
- */
- private String getMatchingOrFailFrom(String[] possibleValues, String desired, String
valueType) throws IllegalArgumentException
- {
- List possibleList = Arrays.asList(possibleValues);
- if (possibleList.contains(desired))
- {
- return desired;
- }
- throw new IllegalArgumentException(desired + " is not a supported " +
valueType);
- }
-
- /**
- * Retrieves the best matching value from a set of possible values based on an ordered
set of preferred values or the
- * given default value if no matching value is found.
- *
- * @param possibleValues the set of possible values
- * @param preferredValues the ordered (according to user preferences) set of preferred
values
- * @param defaultValue the default value to be used if no match can be found
- * @return the first match in the set of possible values from the ordered set of
preferred values or the default
- * value if no such value can be found
- */
- private String getMatchingOrDefaultFrom(String[] possibleValues, String[]
preferredValues, String defaultValue)
- {
- if (preferredValues != null && possibleValues != null)
- {
- List possibleList = Arrays.asList(possibleValues);
-
- for (int i = 0; i < preferredValues.length; i++)
- {
- if (possibleList.contains(preferredValues[i]))
- {
- return preferredValues[i];
- }
- }
- }
-
- return defaultValue;
- }
-
- /**
- * Retrieves the matching value from a set of possible values based on a desired value
or the given default one if no
- * match can be found.
- *
- * @param possibleValues the set of possible values
- * @param desired the desired value
- * @param defaultValue the default value if no match can be found
- * @return the desired value if it's the set of possible values, the specified
default value otherwise
- */
- private String getMatchingOrDefaultFrom(String[] possibleValues, String desired,
String defaultValue)
- {
- List possibleList = Arrays.asList(possibleValues);
- if (possibleList.contains(desired))
- {
- return desired;
- }
- else
- {
- return defaultValue;
- }
- }
-
- /**
- * Wrapper around information needed to perform a Markup invocation.
- *
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @since 2.4
- */
- class MarkupRequest
- {
- private String mode;
- private String windowState;
- private MarkupType markupType;
- private String characterSet;
- private Portlet portlet;
-
- public MarkupRequest(MarkupType markupType, String mode, String windowState, String
characterSet, Portlet portlet)
- {
- this.characterSet = characterSet;
- this.markupType = markupType;
- this.mode = mode;
- this.windowState = windowState;
- this.portlet = portlet;
- }
-
- public String getMimeTypeWithCharset()
- {
- return getMimeType() + CHARSET_SEPARATOR + getCharacterSet();
- }
-
- public String getMimeType()
- {
- return markupType.getMimeType();
- }
-
- public String getLocale()
- {
- String[] locales = markupType.getLocales();
- if (locales != null && locales.length != 0)
- {
- return locales[0];
- }
- else
- {
- return LocaleInfo.getRFC3066LanguageTagFor(Locale.ENGLISH); // no locale was
provided, use English...
- }
- }
-
- public String getMode()
- {
- return mode;
- }
-
- public String getWindowState()
- {
- return windowState;
- }
-
- public MarkupType getMarkupType()
- {
- return markupType;
- }
-
- public String getCharacterSet()
- {
- return characterSet;
- }
-
- public Portlet getPortlet()
- {
- return portlet;
- }
-
- public Set getSupportedModes()
- {
- String[] modes = markupType.getModes();
- int length = modes.length;
- Set result = new HashSet(length);
- for (int i = 0; i < length; i++)
- {
- result.add(WSRPUtils.getJSR168PortletModeFromWSRPName(modes[i]));
- }
- return result;
- }
-
- public Set getSupportedWindowStates()
- {
- String[] states = markupType.getWindowStates();
- int length = states.length;
- Set result = new HashSet(length);
- for (int i = 0; i < length; i++)
- {
- result.add(WSRPUtils.getJSR168WindowStateFromWSRPName(states[i]));
- }
- return result;
- }
- }
-
- class WSRPInstanceContext implements InstanceContext
- {
- private String id;
- private byte[] state;
- private final AccessMode accessMode;
- private boolean wasModified = false;
-
- public WSRPInstanceContext(String portletHandle, AccessMode accessMode)
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletHandle,
"portlet handle", "InstanceContext");
- ParameterValidation.throwIllegalArgExceptionIfNull(accessMode,
"AccessMode");
-
- this.id = portletHandle;
- this.accessMode = accessMode;
- }
-
- public String getId()
- {
- return id;
- }
-
- public AccessMode getAccessMode()
- {
- return accessMode;
- }
-
- public void onStateEvent(StateEvent event)
- {
- org.jboss.portal.portlet.PortletContext portletContext =
event.getPortletContext();
- ParameterValidation.throwIllegalArgExceptionIfNull(portletContext,
"PortletContext");
- wasModified = true;
- id = portletContext.getId();
- state = portletContext.getState();
- }
-
- public boolean wasModified()
- {
- return wasModified;
- }
-
- public byte[] getState()
- {
- return state;
- }
- }
}
Added: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupRequest.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupRequest.java 2007-01-10
22:41:12 UTC (rev 5986)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupRequest.java 2007-01-10
23:27:44 UTC (rev 5987)
@@ -0,0 +1,130 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, 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.jboss.portal.wsrp.producer;
+
+import org.jboss.portal.common.util.LocaleInfo;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.wsrp.WSRPUtils;
+import org.jboss.portal.wsrp.core.MarkupType;
+
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Wrapper around information needed to perform a Markup invocation.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @since 2.6
+ */
+class MarkupRequest
+{
+ private String mode;
+ private String windowState;
+ private MarkupType markupType;
+ private String characterSet;
+ private Portlet portlet;
+ private static final String CHARSET_SEPARATOR = "; charset=";
+
+ public MarkupRequest(MarkupType markupType, String mode, String windowState, String
characterSet, Portlet portlet)
+ {
+ this.characterSet = characterSet;
+ this.markupType = markupType;
+ this.mode = mode;
+ this.windowState = windowState;
+ this.portlet = portlet;
+ }
+
+ public String getMimeTypeWithCharset()
+ {
+ return getMimeType() + CHARSET_SEPARATOR + getCharacterSet();
+ }
+
+ public String getMimeType()
+ {
+ return markupType.getMimeType();
+ }
+
+ public String getLocale()
+ {
+ String[] locales = markupType.getLocales();
+ if (locales != null && locales.length != 0)
+ {
+ return locales[0];
+ }
+ else
+ {
+ return LocaleInfo.getRFC3066LanguageTagFor(Locale.ENGLISH); // no locale was
provided, use English...
+ }
+ }
+
+ public String getMode()
+ {
+ return mode;
+ }
+
+ public String getWindowState()
+ {
+ return windowState;
+ }
+
+ public MarkupType getMarkupType()
+ {
+ return markupType;
+ }
+
+ public String getCharacterSet()
+ {
+ return characterSet;
+ }
+
+ public Portlet getPortlet()
+ {
+ return portlet;
+ }
+
+ public Set getSupportedModes()
+ {
+ String[] modes = markupType.getModes();
+ int length = modes.length;
+ Set result = new HashSet(length);
+ for (int i = 0; i < length; i++)
+ {
+ result.add(WSRPUtils.getJSR168PortletModeFromWSRPName(modes[i]));
+ }
+ return result;
+ }
+
+ public Set getSupportedWindowStates()
+ {
+ String[] states = markupType.getWindowStates();
+ int length = states.length;
+ Set result = new HashSet(length);
+ for (int i = 0; i < length; i++)
+ {
+ result.add(WSRPUtils.getJSR168WindowStateFromWSRPName(states[i]));
+ }
+ return result;
+ }
+}
Property changes on:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupRequest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java 2007-01-10
22:41:12 UTC (rev 5986)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java 2007-01-10
23:27:44 UTC (rev 5987)
@@ -104,13 +104,10 @@
PortletContext portletContext = getPortletDescription.getPortletContext();
WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext,
PORTLET_CONTEXT, GET_PORTLET_DESCRIPTION);
- String handle = portletContext.getPortletHandle();
- WSRPUtils.throwMissingParametersFaultIfValueIsMissing(handle, "portlet
handle", PORTLET_CONTEXT);
-
UserContext userContext = getPortletDescription.getUserContext();
checkUserAuthorization(userContext);
- return
WSRPTypeFactory.createPortletDescriptionResponse(producer.getPortletDescription(handle,
getPortletDescription.getDesiredLocales()));
+ return
WSRPTypeFactory.createPortletDescriptionResponse(producer.getPortletDescription(portletContext,
getPortletDescription.getDesiredLocales()));
}
public PortletPropertyDescriptionResponse
getPortletPropertyDescription(GetPortletPropertyDescription
getPortletPropertyDescription)
Added: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java 2007-01-10
22:41:12 UTC (rev 5986)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java 2007-01-10
23:27:44 UTC (rev 5987)
@@ -0,0 +1,173 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, 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.jboss.portal.wsrp.producer;
+
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.info.CacheInfo;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.RenderInvocation;
+import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.spi.PortalContext;
+import org.jboss.portal.portlet.spi.SecurityContext;
+import org.jboss.portal.portlet.spi.UserContext;
+import org.jboss.portal.portlet.spi.WindowContext;
+import org.jboss.portal.portlet.state.AccessMode;
+import org.jboss.portal.server.util.HTTPStreamInfo;
+import org.jboss.portal.wsrp.WSRPConstants;
+import org.jboss.portal.wsrp.WSRPTypeFactory;
+import org.jboss.portal.wsrp.WSRPUtils;
+import org.jboss.portal.wsrp.core.GetMarkup;
+import org.jboss.portal.wsrp.core.InvalidHandleFault;
+import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
+import org.jboss.portal.wsrp.core.MarkupContext;
+import org.jboss.portal.wsrp.core.MarkupParams;
+import org.jboss.portal.wsrp.core.MarkupResponse;
+import org.jboss.portal.wsrp.core.MissingParametersFault;
+import org.jboss.portal.wsrp.core.OperationFailedFault;
+import org.jboss.portal.wsrp.core.PortletContext;
+import org.jboss.portal.wsrp.core.RegistrationContext;
+import org.jboss.portal.wsrp.core.RuntimeContext;
+import org.jboss.portal.wsrp.core.UnsupportedMimeTypeFault;
+import org.jboss.portal.wsrp.core.UnsupportedModeFault;
+import org.jboss.portal.wsrp.core.UnsupportedWindowStateFault;
+import org.jboss.portal.wsrp.invocation.WSRPRenderContext;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class RenderRequestProcessor extends RequestProcessor
+{
+ private static final String EMPTY = "";
+ private final GetMarkup getMarkup;
+
+ public RenderRequestProcessor(WSRPProducerImpl producer, GetMarkup getMarkup) throws
UnsupportedMimeTypeFault,
+ UnsupportedWindowStateFault, InvalidHandleFault, UnsupportedModeFault,
MissingParametersFault,
+ InvalidRegistrationFault, OperationFailedFault
+ {
+ super(producer);
+ this.getMarkup = getMarkup;
+ prepareInvocation();
+ }
+
+ RegistrationContext getRegistrationContext()
+ {
+ return getMarkup.getRegistrationContext();
+ }
+
+ RuntimeContext getRuntimeContext()
+ {
+ return getMarkup.getRuntimeContext();
+ }
+
+ MarkupParams getMarkupParams()
+ {
+ return getMarkup.getMarkupParams();
+ }
+
+ PortletContext getPortletContext()
+ {
+ return getMarkup.getPortletContext();
+ }
+
+ org.jboss.portal.wsrp.core.UserContext getUserContext()
+ {
+ return getMarkup.getUserContext();
+ }
+
+ String getContextName()
+ {
+ return MarkupHandler.GET_MARKUP;
+ }
+
+ AccessMode getAccessMode()
+ {
+ return AccessMode.READ_ONLY;
+ }
+
+ void initInvocation(StateString navigationalState, SecurityContext securityContext,
+ HTTPStreamInfo streamInfo, PortalContext portalContext,
+ UserContext userContext,
+ WindowContext windowContext
+ )
+ {
+ WSRPRenderContext renderContext = new WSRPRenderContext(navigationalState,
securityContext, streamInfo,
+ portalContext, userContext, instanceContext, windowContext,
+ WSRPUtils.getJSR168PortletModeFromWSRPName(markupRequest.getMode()),
+ WSRPUtils.getJSR168WindowStateFromWSRPName(markupRequest.getWindowState()));
+ setInvocation(new RenderInvocation(renderContext));
+ renderContext.contextualize(invocation);
+
+ invocation.setAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE, portlet.getContext());
+ }
+
+ Object processResponse(PortletInvocationResponse response)
+ {
+ FragmentResponse fragment = (FragmentResponse)response;
+ String markupString = null;
+ byte[] markupBinary = null;
+ switch (fragment.getType())
+ {
+ case FragmentResponse.TYPE_CHARS:
+ markupString = fragment.getChars().toString();
+ break;
+ case FragmentResponse.TYPE_BYTES:
+ markupBinary = fragment.getBytes().toByteArray(); // 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.getMimeType(),
markupString);
+ }
+ else
+ {
+ markupContext =
WSRPTypeFactory.createMarkupContext(markupRequest.getMimeTypeWithCharset(),
markupBinary);
+ }
+ markupContext.setLocale(markupRequest.getLocale());
+ markupContext.setRequiresUrlRewriting(Boolean.TRUE);
+ markupContext.setPreferredTitle(portletDescription.getTitle().getValue());
+
+ // cache information
+ CacheInfo cacheInfo = portlet.getInfo().getCache();
+ if (cacheInfo != null)
+ {
+ int expires = cacheInfo.getExpirationSecs();
+ // only create a CacheControl if expiration time is not 0
+ if (expires != 0)
+ {
+ markupContext.setCacheControl(WSRPTypeFactory.createCacheControl(expires,
WSRPConstants.CACHE_PER_USER));
+ }
+ }
+
+ return new MarkupResponse(markupContext, null, null);
+ }
+}
Property changes on:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RenderRequestProcessor.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RequestProcessor.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RequestProcessor.java 2007-01-10
22:41:12 UTC (rev 5986)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RequestProcessor.java 2007-01-10
23:27:44 UTC (rev 5987)
@@ -0,0 +1,460 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, 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.jboss.portal.wsrp.producer;
+
+import org.jboss.portal.common.MediaType;
+import org.jboss.portal.portlet.OpaqueStateString;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.spi.PortalContext;
+import org.jboss.portal.portlet.spi.SecurityContext;
+import org.jboss.portal.portlet.spi.UserContext;
+import org.jboss.portal.portlet.spi.WindowContext;
+import org.jboss.portal.portlet.state.AccessMode;
+import org.jboss.portal.server.util.HTTPStreamInfo;
+import org.jboss.portal.wsrp.UserContextConverter;
+import org.jboss.portal.wsrp.WSRPConstants;
+import org.jboss.portal.wsrp.WSRPUtils;
+import org.jboss.portal.wsrp.core.InvalidHandleFault;
+import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
+import org.jboss.portal.wsrp.core.MarkupParams;
+import org.jboss.portal.wsrp.core.MarkupType;
+import org.jboss.portal.wsrp.core.MissingParametersFault;
+import org.jboss.portal.wsrp.core.OperationFailedFault;
+import org.jboss.portal.wsrp.core.PortletContext;
+import org.jboss.portal.wsrp.core.PortletDescription;
+import org.jboss.portal.wsrp.core.RegistrationContext;
+import org.jboss.portal.wsrp.core.RuntimeContext;
+import org.jboss.portal.wsrp.core.UnsupportedMimeTypeFault;
+import org.jboss.portal.wsrp.core.UnsupportedModeFault;
+import org.jboss.portal.wsrp.core.UnsupportedWindowStateFault;
+
+import javax.activation.MimeTypeParseException;
+import java.security.Principal;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public abstract class RequestProcessor
+{
+ private static final String WINDOW_STATE = "window state";
+ private static final String PORTLET_MODE = "portlet mode";
+
+ protected PortletInvocation invocation;
+ protected MarkupRequest markupRequest;
+ protected PortletDescription portletDescription;
+ protected Portlet portlet;
+ protected WSRPInstanceContext instanceContext;
+ protected WSRPProducerImpl producer;
+
+
+ protected RequestProcessor(WSRPProducerImpl producer)
+ {
+ this.producer = producer;
+ }
+
+ void prepareInvocation() throws InvalidRegistrationFault, OperationFailedFault,
MissingParametersFault, InvalidHandleFault, UnsupportedMimeTypeFault,
UnsupportedWindowStateFault, UnsupportedModeFault
+ {
+ producer.checkRegistration(getRegistrationContext());
+
+ // get session information and deal with it
+ final RuntimeContext runtimeContext = getRuntimeContext();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(runtimeContext,
"RuntimeContext", getContextName());
+
+ checkForSessionIDs(runtimeContext);
+
+ // get markup parameters
+ final MarkupParams params = getMarkupParams();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(params,
"MarkupParams", getContextName());
+
+ // get portlet handle
+ PortletContext wsrpPC = getPortletContext();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(wsrpPC,
"PortletContext", getContextName());
+ final String portletHandle = wsrpPC.getPortletHandle();
+ WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletHandle, "portlet
handle", "PortletContext");
+ org.jboss.portal.portlet.PortletContext originalPortletContext =
WSRPUtils.convertToPortalPortletContext(wsrpPC);
+
+ // retrieve the portlet
+ try
+ {
+ portlet = producer.getPortletWith(originalPortletContext);
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRPUtils.createOperationFailedFault(e);
+ }
+
+ // get portlet description for the desired portlet...
+ final String[] desiredLocales = params.getLocales();
+ portletDescription = producer.getPortletDescription(wsrpPC, desiredLocales);
+ if (Boolean.TRUE.equals(portletDescription.getUsesMethodGet()))
+ {
+ throw WSRPUtils.createOperationFailedFault(
+ new UnsupportedOperationException("Portlets using GET method in forms
are not currently supported."));
+ }
+ MarkupType[] markupTypes = portletDescription.getMarkupTypes();
+
+ // based on the markup parameters and portlet description generate the most
appropriate markup request
+ markupRequest = createMarkupRequestFrom(markupTypes, params, portlet);
+
+ // prepare information for invocation
+ StateString navigationalState =
createNavigationalState(params.getNavigationalState());
+
+ final org.jboss.portal.wsrp.core.UserContext wsrpUserContext = getUserContext();
+ checkUserContext(wsrpUserContext);
+
+ SecurityContext securityContext = createSecurityContext(params, runtimeContext,
wsrpUserContext);
+ HTTPStreamInfo streamInfo = createStreamInfo(markupRequest);
+ PortalContext portalContext = createPortalContext(params, markupRequest);
+ UserContext userContext = createUserContext(wsrpUserContext,
markupRequest.getLocale(), desiredLocales);
+ instanceContext = createInstanceContext(portletHandle, getAccessMode());
+ WindowContext windowContext = createWindowContext(portletHandle, runtimeContext);
+
+ // prepare the invocation
+ initInvocation(navigationalState, securityContext, streamInfo, portalContext,
userContext, windowContext);
+ }
+
+ abstract RegistrationContext getRegistrationContext();
+
+ abstract RuntimeContext getRuntimeContext();
+
+ abstract MarkupParams getMarkupParams();
+
+ abstract PortletContext getPortletContext();
+
+ abstract org.jboss.portal.wsrp.core.UserContext getUserContext();
+
+ abstract String getContextName();
+
+ abstract AccessMode getAccessMode() throws MissingParametersFault;
+
+ abstract void initInvocation(StateString navigationalState, SecurityContext
securityContext,
+ HTTPStreamInfo streamInfo, PortalContext portalContext,
UserContext userContext,
+ WindowContext windowContext);
+
+ abstract Object processResponse(PortletInvocationResponse response);
+
+
+ /**
+ * Returns the most appropriate information to base markup generation on based on a
Portlet's specified markup types
+ * and a markup request parameters.
+ *
+ * @param markupTypes the Portlet's specified markup types
+ * @param params the markup request parameters
+ * @param portlet
+ * @return a MarkupRequest containing the most appropriate information to base markup
generation for this request
+ */
+ private MarkupRequest createMarkupRequestFrom(MarkupType[] markupTypes, MarkupParams
params, Portlet portlet)
+ throws UnsupportedMimeTypeFault, UnsupportedModeFault, UnsupportedWindowStateFault
+ {
+ String[] desiredMIMETypes = params.getMimeTypes();
+ MarkupType markupType = null;
+
+ // Get the MIME type to use
+ for (int i = 0; markupType == null && i < desiredMIMETypes.length; i++)
+ {
+ String desiredMIMEType = desiredMIMETypes[i];
+ for (int j = 0; j < markupTypes.length; j++)
+ {
+ if (desiredMIMEType.equalsIgnoreCase(markupTypes[j].getMimeType()))
+ {
+ markupType = markupTypes[j];
+ break;
+ }
+ }
+ }
+
+ // no MIME type was found: error!
+ if (markupType == null)
+ {
+ throw
(UnsupportedMimeTypeFault)WSRPUtils.createFaultFrom(UnsupportedMimeTypeFault.class,
+ new IllegalArgumentException("None of the specified MIME types are
supported by this Portlet."));
+ }
+
+ // get the mode
+ String mode = null;
+ try
+ {
+ mode = getMatchingOrFailFrom(markupType.getModes(), params.getMode(),
PORTLET_MODE);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw
(UnsupportedModeFault)WSRPUtils.createFaultFrom(UnsupportedModeFault.class, e);
+ }
+
+ // get the window state
+ String windowState = null;
+ try
+ {
+ windowState = getMatchingOrFailFrom(markupType.getWindowStates(),
params.getWindowState(), WINDOW_STATE);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw
(UnsupportedWindowStateFault)WSRPUtils.createFaultFrom(UnsupportedWindowStateFault.class,
e);
+ }
+
+ // get the character set
+ String characterSet = getMatchingOrDefaultFrom(new String[0],
params.getMarkupCharacterSets(), WSRPConstants.DEFAULT_CHARACTER_SET);
+
+ return new MarkupRequest(markupType, mode, windowState, characterSet, portlet);
+ }
+
+ /**
+ * Retrieves the desired value from the set of possible values if such value exists or
throw an
+ * <code>IllegalArgumentException</code>.
+ *
+ * @param possibleValues the set of supported values
+ * @param desired the desired value
+ * @param valueType a name identifying the type of the desired value (for error
reporting purpose)
+ * @return the desired value
+ * @throws IllegalArgumentException if the desired value is not found in the set of
possible values
+ */
+ private String getMatchingOrFailFrom(String[] possibleValues, String desired, String
valueType) throws IllegalArgumentException
+ {
+ List possibleList = Arrays.asList(possibleValues);
+ if (possibleList.contains(desired))
+ {
+ return desired;
+ }
+ throw new IllegalArgumentException(desired + " is not a supported " +
valueType);
+ }
+
+ /**
+ * Retrieves the best matching value from a set of possible values based on an ordered
set of preferred values or the
+ * given default value if no matching value is found.
+ *
+ * @param possibleValues the set of possible values
+ * @param preferredValues the ordered (according to user preferences) set of preferred
values
+ * @param defaultValue the default value to be used if no match can be found
+ * @return the first match in the set of possible values from the ordered set of
preferred values or the default
+ * value if no such value can be found
+ */
+ private String getMatchingOrDefaultFrom(String[] possibleValues, String[]
preferredValues, String defaultValue)
+ {
+ if (preferredValues != null && possibleValues != null)
+ {
+ List possibleList = Arrays.asList(possibleValues);
+
+ for (int i = 0; i < preferredValues.length; i++)
+ {
+ if (possibleList.contains(preferredValues[i]))
+ {
+ return preferredValues[i];
+ }
+ }
+ }
+
+ return defaultValue;
+ }
+
+ private void checkUserContext(org.jboss.portal.wsrp.core.UserContext wsrpUserContext)
throws MissingParametersFault
+ {
+ if (wsrpUserContext != null)
+ {
+
WSRPUtils.throwMissingParametersFaultIfValueIsMissing(wsrpUserContext.getUserContextKey(),
"User Context Key", "UserContext");
+ }
+ }
+
+
+ private void checkForSessionIDs(RuntimeContext runtimeContext) throws
OperationFailedFault
+ {
+ if (runtimeContext.getSessionID() != null)
+ {
+ MarkupHandler.throwOperationFaultOnSessionOperation();
+ }
+ }
+
+ protected StateString createNavigationalState(String navigationalState)
+ {
+ // fix-me: create opaque NS and implement an interceptor that does conversion to
jboss NS
+// PortletNavigationalState navigationalState = new
OpaquePortletNavigationalState(navigationalState);
+ if (navigationalState == null)
+ {
+ return null;
+ }
+ else
+ {
+ return new OpaqueStateString(navigationalState);
+ }
+ }
+
+ private WSRPInstanceContext createInstanceContext(final String portletHandle, final
AccessMode accessMode)
+ {
+ return new WSRPInstanceContext(portletHandle, accessMode);
+ }
+
+ private WindowContext createWindowContext(final String portletHandle, final
RuntimeContext runtimeContext)
+ {
+ return new WindowContext()
+ {
+ public String getId()
+ {
+ String prefix = runtimeContext.getNamespacePrefix();
+ if (prefix != null && prefix.length() > 0)
+ {
+ return prefix;
+ }
+ else
+ {
+ // No provided namespace prefix for portlet, using portlet handle instead
+ return portletHandle;
+ }
+ }
+ };
+ }
+
+ private UserContext createUserContext(final org.jboss.portal.wsrp.core.UserContext
userContext,
+ String preferredLocale, final String[]
supportedLocales)
+ {
+ // todo: investigate ways to cache this information?
+ // fix-me: should getInformations be put in the request attribute
PortletRequest.USER_INFO?
+ return UserContextConverter.createPortalUserContextFrom(userContext,
supportedLocales, preferredLocale);
+ }
+
+ private PortalContext createPortalContext(final MarkupParams params, final
MarkupRequest markupRequest)
+ {
+ return new PortalContext()
+ {
+ public Set getWindowStates()
+ {
+ String[] validNewWindowStates = params.getValidNewWindowStates();
+ if (validNewWindowStates != null)
+ {
+ Set states = new HashSet(validNewWindowStates.length);
+ for (int i = 0; i < validNewWindowStates.length; i++)
+ {
+ String state = validNewWindowStates[i];
+ states.add(WSRPUtils.getJSR168WindowStateFromWSRPName(state));
+ }
+ return states;
+ }
+ return markupRequest.getSupportedWindowStates();
+ }
+
+ public Set getModes()
+ {
+ String[] validNewModes = params.getValidNewModes();
+ if (validNewModes != null)
+ {
+ Set modes = new HashSet(validNewModes.length);
+ for (int i = 0; i < validNewModes.length; i++)
+ {
+ String mode = validNewModes[i];
+ modes.add(WSRPUtils.getJSR168PortletModeFromWSRPName(mode));
+ }
+ return modes;
+ }
+ return markupRequest.getSupportedModes();
+ }
+
+ public Map getProperties()
+ {
+ return Collections.EMPTY_MAP;
+ }
+ };
+ }
+
+ private HTTPStreamInfo createStreamInfo(MarkupRequest markupRequest)
+ throws UnsupportedMimeTypeFault
+ {
+ HTTPStreamInfo streamInfo;
+ try
+ {
+ streamInfo = new
HTTPStreamInfo(MediaType.parseMimeType(markupRequest.getMimeType()),
markupRequest.getCharacterSet());
+ }
+ catch (MimeTypeParseException e)
+ {
+ throw
(UnsupportedMimeTypeFault)WSRPUtils.createFaultFrom(UnsupportedMimeTypeFault.class, e);
+ }
+ return streamInfo;
+ }
+
+ // fix-me: check that the correct semantics is used.
+ private SecurityContext createSecurityContext(final MarkupParams params, final
RuntimeContext runtimeContext,
+ final
org.jboss.portal.wsrp.core.UserContext wsrpUserContext)
+ {
+ return new SecurityContext()
+ {
+ public boolean isSecure()
+ {
+ return params.isSecureClientCommunication();
+ }
+
+ public String getAuthType()
+ {
+ return runtimeContext.getUserAuthentication();
+ }
+
+ public String getRemoteUser()
+ {
+ if (wsrpUserContext != null)
+ {
+ return wsrpUserContext.getUserContextKey();
+ }
+ return null;
+ }
+
+ public Principal getUserPrincipal()
+ {
+ return null;
+ }
+
+ public boolean isUserInRole(String roleName)
+ {
+ if (wsrpUserContext != null)
+ {
+ List userCategories = Arrays.asList(wsrpUserContext.getUserCategories());
+ return userCategories.contains(roleName);
+ }
+ return false;
+ }
+
+ public boolean isAuthenticated()
+ {
+ return wsrpUserContext != null;
+ }
+ };
+ }
+
+ public PortletInvocation getInvocation()
+ {
+ return invocation;
+ }
+
+ public void setInvocation(PortletInvocation invocation)
+ {
+ this.invocation = invocation;
+ }
+}
Property changes on:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RequestProcessor.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java 2007-01-10
22:41:12 UTC (rev 5986)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/ServiceDescriptionHandler.java 2007-01-10
23:27:44 UTC (rev 5987)
@@ -25,6 +25,7 @@
import org.jboss.logging.Logger;
import org.jboss.portal.common.util.LocaleInfo;
+import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
@@ -41,6 +42,7 @@
import org.jboss.portal.wsrp.core.MarkupType;
import org.jboss.portal.wsrp.core.ModelDescription;
import org.jboss.portal.wsrp.core.OperationFailedFault;
+import org.jboss.portal.wsrp.core.PortletContext;
import org.jboss.portal.wsrp.core.PortletDescription;
import org.jboss.portal.wsrp.core.ServiceDescription;
import org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType;
@@ -109,12 +111,13 @@
return offeredPortletDescriptions;
}
- public PortletDescription getPortletDescription(String handle, String[]
desiredLocales) throws InvalidHandleFault, OperationFailedFault
+ public PortletDescription getPortletDescription(PortletContext portletContext,
String[] desiredLocales) throws InvalidHandleFault, OperationFailedFault
{
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "portlet
context");
Portlet portlet;
try
{
- portlet = producer.getPortletWith(handle);
+ portlet =
producer.getPortletWith(WSRPUtils.convertToPortalPortletContext(portletContext));
}
catch (PortletInvokerException e)
{
Added: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPInstanceContext.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPInstanceContext.java 2007-01-10
22:41:12 UTC (rev 5986)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPInstanceContext.java 2007-01-10
23:27:44 UTC (rev 5987)
@@ -0,0 +1,80 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, 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.jboss.portal.wsrp.producer;
+
+import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.portlet.StateEvent;
+import org.jboss.portal.portlet.spi.InstanceContext;
+import org.jboss.portal.portlet.state.AccessMode;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+class WSRPInstanceContext implements InstanceContext
+{
+ private String id;
+ private byte[] state;
+ private final AccessMode accessMode;
+ private boolean wasModified = false;
+
+ public WSRPInstanceContext(String portletHandle, AccessMode accessMode)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletHandle,
"portlet handle", "InstanceContext");
+ ParameterValidation.throwIllegalArgExceptionIfNull(accessMode,
"AccessMode");
+
+ this.id = portletHandle;
+ this.accessMode = accessMode;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public AccessMode getAccessMode()
+ {
+ return accessMode;
+ }
+
+ public void onStateEvent(StateEvent event)
+ {
+ org.jboss.portal.portlet.PortletContext portletContext =
event.getPortletContext();
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletContext,
"PortletContext");
+ wasModified = true;
+ id = portletContext.getId();
+ state = portletContext.getState();
+ }
+
+ public boolean wasModified()
+ {
+ return wasModified;
+ }
+
+ public byte[] getState()
+ {
+ return state;
+ }
+}
Property changes on:
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPInstanceContext.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2007-01-10
22:41:12 UTC (rev 5986)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2007-01-10
23:27:44 UTC (rev 5987)
@@ -370,22 +370,22 @@
this.invoker = invoker;
}
- Portlet getPortletWith(String handle) throws InvalidHandleFault,
PortletInvokerException
+ Portlet getPortletWith(org.jboss.portal.portlet.PortletContext portletContext) throws
InvalidHandleFault, PortletInvokerException
{
Portlet portlet;
try
{
- portlet =
invoker.getPortlet(org.jboss.portal.portlet.PortletContext.createPortletContext(handle));
+ portlet = invoker.getPortlet(portletContext);
}
catch (NoSuchPortletException e)
{
throw (InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class,
- new IllegalArgumentException("Couldn't find portlet with handle:
" + handle));
+ new IllegalArgumentException("Couldn't find portlet with handle
'" + portletContext.getId() + "'"));
}
if (!isRemotable(portlet))
{
throw (InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class,
- new IllegalArgumentException("Portlet with handle: " + handle +
" is not remotely available."));
+ new IllegalArgumentException("Portlet '" +
portletContext.getId() + "' is not remotely available."));
}
return portlet;
@@ -409,9 +409,9 @@
return remotablePortlets;
}
- public PortletDescription getPortletDescription(String handle, String[] locales)
throws InvalidHandleFault, OperationFailedFault
+ public PortletDescription getPortletDescription(PortletContext portletContext,
String[] locales) throws InvalidHandleFault, OperationFailedFault
{
- return serviceDescriptionHandler.getPortletDescription(handle, locales);
+ return serviceDescriptionHandler.getPortletDescription(portletContext, locales);
}
/**