Author: chris.laprun(a)jboss.com
Date: 2010-08-11 09:15:34 -0400 (Wed, 11 Aug 2010)
New Revision: 3804
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/MarkupHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/RegistrationHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceDescriptionHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MarkupRequest.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPInstanceContext.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPPortletInvocationContext.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPRequestContext.java
Removed:
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/MarkupRequest.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MimeResponseProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.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/ResourceRequestProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/UpdateNavigationalStateResponseProcessor.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPInstanceContext.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
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/Utils.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java
Log:
- GTNWSRP-57: Producer side. Moved handlers to handlers package and processors to
handlers.processors package. :)
Deleted:
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-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ActionRequestProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,143 +0,0 @@
-/*
- * 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.pc.api.StateString;
-import org.gatein.pc.api.invocation.ActionInvocation;
-import org.gatein.pc.api.invocation.PortletInvocation;
-import org.gatein.pc.api.invocation.response.HTTPRedirectionResponse;
-import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
-import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
-import org.gatein.pc.api.state.AccessMode;
-import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
-import org.oasis.wsrp.v2.InteractionParams;
-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;
-import org.oasis.wsrp.v2.PortletContext;
-import org.oasis.wsrp.v2.RegistrationContext;
-import org.oasis.wsrp.v2.RuntimeContext;
-import org.oasis.wsrp.v2.StateChange;
-import org.oasis.wsrp.v2.UnsupportedMimeType;
-import org.oasis.wsrp.v2.UnsupportedMode;
-import org.oasis.wsrp.v2.UnsupportedWindowState;
-import org.oasis.wsrp.v2.UpdateResponse;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 13121 $
- * @since 2.6
- */
-class ActionRequestProcessor extends UpdateNavigationalStateResponseProcessor
-{
- private final PerformBlockingInteraction performBlockingInteraction;
-
- ActionRequestProcessor(WSRPProducerImpl producer, PerformBlockingInteraction
performBlockingInteraction)
- throws UnsupportedMimeType, UnsupportedWindowState, InvalidHandle, UnsupportedMode,
MissingParameters,
- InvalidRegistration, OperationFailed
- {
- super(producer);
- this.performBlockingInteraction = performBlockingInteraction;
- prepareInvocation();
- }
-
- RegistrationContext getRegistrationContext()
- {
- return performBlockingInteraction.getRegistrationContext();
- }
-
- RuntimeContext getRuntimeContext()
- {
- return performBlockingInteraction.getRuntimeContext();
- }
-
- MimeRequest getParams()
- {
- return performBlockingInteraction.getMarkupParams();
- }
-
- PortletContext getPortletContext()
- {
- return performBlockingInteraction.getPortletContext();
- }
-
- org.oasis.wsrp.v2.UserContext getUserContext()
- {
- return performBlockingInteraction.getUserContext();
- }
-
- String getContextName()
- {
- return MarkupHandler.PBI;
- }
-
- AccessMode getAccessMode() throws MissingParameters
- {
- StateChange stateChange =
performBlockingInteraction.getInteractionParams().getPortletStateChange();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(stateChange,
"portletStateChange", "InteractionParams");
- return WSRPUtils.getAccessModeFromStateChange(stateChange);
- }
-
- PortletInvocation initInvocation(WSRPPortletInvocationContext context)
- {
- ActionInvocation invocation = new ActionInvocation(context);
- InteractionParams interactionParams =
performBlockingInteraction.getInteractionParams();
-
- // Request context
- WSRPRequestContext requestContext =
WSRPRequestContext.createRequestContext(markupRequest, interactionParams);
- invocation.setRequestContext(requestContext);
-
- // Interaction state, navigational state is already taken care of in
RequestProcessor.prepareInvocation
- StateString interactionState =
createNavigationalState(interactionParams.getInteractionState());
- invocation.setInteractionState(interactionState);
-
- // Form parameters
- invocation.setForm(requestContext.getForm());
-
- return invocation;
- }
-
- Object processResponse(PortletInvocationResponse response)
- {
- if (response instanceof UpdateNavigationalStateResponse)
- {
- UpdateNavigationalStateResponse stateResponse =
(UpdateNavigationalStateResponse)response;
- UpdateResponse updateResponse = createUpdateResponse(stateResponse);
-
- return WSRPTypeFactory.createBlockingInteractionResponse(updateResponse);
- }
- else
- {
- // result should be HTTPRedirectionResult
- HTTPRedirectionResponse redirectionResult = (HTTPRedirectionResponse)response;
- return
WSRPTypeFactory.createBlockingInteractionResponse(redirectionResult.getLocation());
- }
- }
-}
Deleted:
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-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/EventRequestProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,178 +0,0 @@
-/*
- * 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.util.ParameterValidation;
-import org.gatein.pc.api.invocation.EventInvocation;
-import org.gatein.pc.api.invocation.PortletInvocation;
-import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
-import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
-import org.gatein.pc.api.state.AccessMode;
-import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.payload.PayloadUtils;
-import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
-import org.oasis.wsrp.v2.Event;
-import org.oasis.wsrp.v2.EventParams;
-import org.oasis.wsrp.v2.EventPayload;
-import org.oasis.wsrp.v2.HandleEvents;
-import org.oasis.wsrp.v2.HandleEventsResponse;
-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;
-import org.oasis.wsrp.v2.PortletContext;
-import org.oasis.wsrp.v2.RegistrationContext;
-import org.oasis.wsrp.v2.RuntimeContext;
-import org.oasis.wsrp.v2.StateChange;
-import org.oasis.wsrp.v2.UnsupportedMimeType;
-import org.oasis.wsrp.v2.UnsupportedMode;
-import org.oasis.wsrp.v2.UnsupportedWindowState;
-import org.oasis.wsrp.v2.UpdateResponse;
-import org.oasis.wsrp.v2.UserContext;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision$
- */
-public class EventRequestProcessor extends UpdateNavigationalStateResponseProcessor
-{
- private HandleEvents handleEvents;
-
- public EventRequestProcessor(WSRPProducerImpl producer, HandleEvents handleEvents)
throws OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters,
UnsupportedMimeType, UnsupportedWindowState, InvalidRegistration, OperationNotSupported
- {
- super(producer);
- this.handleEvents = handleEvents;
-
- // validate request parameters
- EventParams eventParams = handleEvents.getEventParams();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(eventParams,
"event params", "HandleEvents");
-
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(eventParams.getPortletStateChange(),
"portletStateChange", "EventParams");
- List<Event> events = eventParams.getEvents();
- if (!ParameterValidation.existsAndIsNotEmpty(events))
- {
- throw WSRP2ExceptionFactory.createWSException(MissingParameters.class,
- "EventParams must provide at least one event to process", null);
- }
-
- if (events.size() > 1)
- {
- throw WSRP2ExceptionFactory.createWSException(OperationNotSupported.class,
- "GateIn currently doesn't support sending multiple events to process
at once.", null);
- }
- prepareInvocation();
- }
-
- @Override
- RegistrationContext getRegistrationContext()
- {
- return handleEvents.getRegistrationContext();
- }
-
- @Override
- RuntimeContext getRuntimeContext()
- {
- return handleEvents.getRuntimeContext();
- }
-
- @Override
- MimeRequest getParams()
- {
- return handleEvents.getMarkupParams();
- }
-
- @Override
- PortletContext getPortletContext()
- {
- return handleEvents.getPortletContext();
- }
-
- @Override
- UserContext getUserContext()
- {
- return handleEvents.getUserContext();
- }
-
- @Override
- String getContextName()
- {
- return "HandleEvents";
- }
-
- @Override
- AccessMode getAccessMode() throws MissingParameters
- {
- StateChange stateChange = handleEvents.getEventParams().getPortletStateChange();
-
- return WSRPUtils.getAccessModeFromStateChange(stateChange);
- }
-
- @Override
- PortletInvocation initInvocation(WSRPPortletInvocationContext context)
- {
- EventInvocation eventInvocation = new EventInvocation(context);
-
- List<Event> events = handleEvents.getEventParams().getEvents();
-
- if (events.size() > 1)
- {
- throw new NotYetImplemented("Need to support multiple events at
once...");
- }
-
- // since we currently don't support sending multiple events to process at once,
assume there's only one
- Event event = events.get(0);
-
- eventInvocation.setName(event.getName());
- EventPayload payload = event.getPayload();
-
- eventInvocation.setPayload(PayloadUtils.getPayloadAsSerializable(event.getType(),
payload));
-
- return eventInvocation;
- }
-
- @Override
- Object processResponse(PortletInvocationResponse response)
- {
- if (response instanceof UpdateNavigationalStateResponse)
- {
- UpdateNavigationalStateResponse unsResponse =
(UpdateNavigationalStateResponse)response;
- HandleEventsResponse eventsResponse =
WSRPTypeFactory.createHandleEventsReponse();
-
- UpdateResponse updateResponse = createUpdateResponse(unsResponse);
- eventsResponse.setUpdateResponse(updateResponse);
-
- return eventsResponse;
- }
- else
- {
- throw new IllegalArgumentException("Cannot process response: " +
response);
- }
- }
-}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupHandler.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupHandler.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,265 +0,0 @@
-/*
- * 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.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;
-import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
-import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
-import org.gatein.pc.portlet.state.producer.PortletStateChangeRequiredException;
-import org.gatein.wsrp.servlet.ServletAccess;
-import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
-import org.oasis.wsrp.v2.AccessDenied;
-import org.oasis.wsrp.v2.BlockingInteractionResponse;
-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.HandleEventsResponse;
-import org.oasis.wsrp.v2.InconsistentParameters;
-import org.oasis.wsrp.v2.InitCookie;
-import org.oasis.wsrp.v2.InteractionParams;
-import org.oasis.wsrp.v2.InvalidCookie;
-import org.oasis.wsrp.v2.InvalidHandle;
-import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.InvalidSession;
-import org.oasis.wsrp.v2.InvalidUserCategory;
-import org.oasis.wsrp.v2.MarkupResponse;
-import org.oasis.wsrp.v2.MissingParameters;
-import org.oasis.wsrp.v2.ModifyRegistrationRequired;
-import org.oasis.wsrp.v2.OperationFailed;
-import org.oasis.wsrp.v2.OperationNotSupported;
-import org.oasis.wsrp.v2.PerformBlockingInteraction;
-import org.oasis.wsrp.v2.PortletStateChangeRequired;
-import org.oasis.wsrp.v2.ReleaseSessions;
-import org.oasis.wsrp.v2.ResourceResponse;
-import org.oasis.wsrp.v2.ResourceSuspended;
-import org.oasis.wsrp.v2.UnsupportedLocale;
-import org.oasis.wsrp.v2.UnsupportedMimeType;
-import org.oasis.wsrp.v2.UnsupportedMode;
-import org.oasis.wsrp.v2.UnsupportedWindowState;
-
-import javax.portlet.PortletModeException;
-import javax.portlet.WindowStateException;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 10090 $
- * @since 2.4
- */
-class MarkupHandler extends ServiceHandler implements MarkupInterface
-{
- static final String PBI = "PerformBlockingInteraction";
- static final String GET_MARKUP = "GetMarkup";
- static final String GET_RESOURCE = "GetResource";
-
- MarkupHandler(WSRPProducerImpl producer)
- {
- super(producer);
- }
-
- // Markup implementation
********************************************************************************************
-
-
- public MarkupResponse getMarkup(GetMarkup getMarkup)
- throws AccessDenied, InconsistentParameters, InvalidCookie, InvalidHandle,
InvalidRegistration, InvalidSession,
- InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, ResourceSuspended,
- UnsupportedLocale, UnsupportedMimeType, UnsupportedMode, UnsupportedWindowState
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getMarkup, GET_MARKUP);
-
- RequestProcessor requestProcessor = new RenderRequestProcessor(producer,
getMarkup);
-
- String handle = requestProcessor.getPortletContext().getPortletHandle();
- PortletInvocationResponse response;
- try
- {
- log.debug("RenderInvocation on portlet '" + handle +
"'");
- response =
producer.getPortletInvoker().invoke(requestProcessor.getInvocation());
- log.debug("RenderInvocation done");
- }
- catch (PortletInvokerException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not render portlet '" + handle + "'", e);
- }
-
- checkForError(response);
-
- return (MarkupResponse)requestProcessor.processResponse(response);
- }
-
- public ResourceResponse getResource(GetResource getResource)
- throws AccessDenied, InconsistentParameters, InvalidCookie, InvalidHandle,
InvalidRegistration, InvalidSession,
- InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, OperationNotSupported,
- 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 AccessDenied, InconsistentParameters, InvalidCookie, InvalidHandle,
InvalidRegistration, InvalidSession,
- InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, PortletStateChangeRequired,
- ResourceSuspended, UnsupportedLocale, UnsupportedMimeType, UnsupportedMode,
UnsupportedWindowState
- {
-
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(performBlockingInteraction,
PBI);
- final InteractionParams interactionParams =
performBlockingInteraction.getInteractionParams();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(interactionParams,
"InteractionParams", PBI);
-
- RequestProcessor requestProcessor = new ActionRequestProcessor(producer,
performBlockingInteraction);
-
- PortletInvocationResponse response;
- String handle = requestProcessor.getPortletContext().getPortletHandle();
- try
- {
- log.debug("ActionInvocation on portlet '" + handle +
"'");
- response =
producer.getPortletInvoker().invoke(requestProcessor.getInvocation());
- log.debug("ActionInvocation done");
- }
- catch (PortletStateChangeRequiredException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(PortletStateChangeRequired.class,
e.getLocalizedMessage(), e);
- }
- catch (PortletInvokerException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not perform action on portlet '" + handle + "'", e);
- }
-
- checkForError(response);
-
- return (BlockingInteractionResponse)requestProcessor.processResponse(response);
- }
-
- public List<Extension> releaseSessions(ReleaseSessions releaseSessions)
- throws AccessDenied, InvalidRegistration, MissingParameters,
ModifyRegistrationRequired, OperationFailed,
- OperationNotSupported, ResourceSuspended
- {
- // our producer never sends session ids so a Consumer trying to release sessions is
an error condition
- throwOperationFaultOnSessionOperation();
- return null;
- }
-
- public List<Extension> initCookie(InitCookie initCookie)
- throws AccessDenied, InvalidRegistration, ModifyRegistrationRequired,
OperationFailed, OperationNotSupported,
- ResourceSuspended
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(initCookie,
"InitCookie");
- producer.getRegistrationOrFailIfInvalid(initCookie.getRegistrationContext());
-
- // Force HTTP session creation... this is required for BEA Weblogic version <
9.2.
- // See
http://jira.jboss.com/jira/browse/JBPORTAL-1220
- String sessionId = ServletAccess.getRequest().getSession().getId();
- log.debug("Got init cookie operation, created a session with id " +
sessionId);
-
- return Collections.emptyList();
- }
-
- public HandleEventsResponse handleEvents(HandleEvents handleEvents)
- throws AccessDenied, InconsistentParameters, InvalidCookie, InvalidHandle,
InvalidRegistration, InvalidSession,
- InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, OperationNotSupported,
- PortletStateChangeRequired, ResourceSuspended, UnsupportedLocale,
UnsupportedMimeType, UnsupportedMode,
- UnsupportedWindowState
- {
- EventRequestProcessor requestProcessor = new EventRequestProcessor(producer,
handleEvents);
-
- PortletInvocationResponse response;
- String handle = requestProcessor.getPortletContext().getPortletHandle();
-
- try
- {
- log.debug("EventInvocation on portlet '" + handle +
"'");
- response =
producer.getPortletInvoker().invoke(requestProcessor.getInvocation());
- log.debug("EventInvocation done");
- }
- catch (PortletStateChangeRequiredException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(PortletStateChangeRequired.class,
e.getLocalizedMessage(), e);
- }
- catch (PortletInvokerException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not handle event on portlet '" + handle + "'", e);
- }
-
- checkForError(response);
-
- return (HandleEventsResponse)requestProcessor.processResponse(response);
- }
-
- static void throwOperationFaultOnSessionOperation() throws OperationFailed
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "JBoss
Portal's Producer" +
- " manages sessions completely on the server side, passing or trying to
release sessionIDs is therefore an error.",
- null);
- }
-
- private void checkForError(PortletInvocationResponse response)
- throws UnsupportedMode, OperationFailed, UnsupportedWindowState
- {
- if (response instanceof ErrorResponse)
- {
- ErrorResponse errorResult = (ErrorResponse)response;
- Throwable cause = errorResult.getCause();
- if (cause instanceof PortletModeException)
- {
- throw WSRP2ExceptionFactory.throwWSException(UnsupportedMode.class,
"Unsupported mode: " + ((PortletModeException)cause).getMode(), null);
- }
- if (cause instanceof WindowStateException)
- {
- throw WSRP2ExceptionFactory.throwWSException(UnsupportedWindowState.class,
"Unsupported window state: " + ((WindowStateException)cause).getState(), null);
- }
- // todo: deal with other exceptions
-
- // we're not sure what happened so throw an OperationFailedFault
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
errorResult.getMessage(), cause);
-
- }
- 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);
- }
- }
-}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupRequest.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupRequest.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupRequest.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,130 +0,0 @@
-/*
- * 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.pc.api.Mode;
-import org.gatein.pc.api.WindowState;
-import org.gatein.pc.api.Portlet;
-import org.gatein.wsrp.WSRPUtils;
-import org.oasis.wsrp.v2.MarkupType;
-
-import java.util.HashSet;
-import java.util.List;
-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 getMediaTypeWithCharset()
- {
- return getMediaType() + CHARSET_SEPARATOR + getCharacterSet();
- }
-
- public String getMediaType()
- {
- return markupType.getMimeType();
- }
-
- public String getLocale()
- {
- List<String> locales = markupType.getLocales();
- if (locales != null && !locales.isEmpty())
- {
- return locales.get(0);
- }
- else
- {
- return WSRPUtils.toString(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<Mode> getSupportedModes()
- {
- List<String> modes = markupType.getModes();
- Set<Mode> result = new HashSet<Mode>(modes.size());
- for (String mode : modes)
- {
- result.add(WSRPUtils.getJSR168PortletModeFromWSRPName(mode));
- }
- return result;
- }
-
- public Set<WindowState> getSupportedWindowStates()
- {
- List<String> states = markupType.getWindowStates();
- Set<WindowState> result = new HashSet<WindowState>(states.size());
- for (String state : states)
- {
- result.add(WSRPUtils.getJSR168WindowStateFromWSRPName(state));
- }
- return result;
- }
-}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MimeResponseProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MimeResponseProcessor.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MimeResponseProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,126 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
- * contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.gatein.wsrp.producer;
-
-import org.gatein.common.net.URLTools;
-import org.gatein.pc.api.invocation.response.ContentResponse;
-import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
-import org.gatein.wsrp.WSRPConstants;
-import org.gatein.wsrp.WSRPRewritingConstants;
-import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.servlet.ServletAccess;
-import org.oasis.wsrp.v2.MimeResponse;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision$
- */
-public abstract class MimeResponseProcessor<LocalMimeResponse extends MimeResponse>
extends RequestProcessor
-{
- protected String namespace;
- private static final String EMPTY = "";
-
- protected MimeResponseProcessor(WSRPProducerImpl producer)
- {
- super(producer);
- }
-
- /**
- * Process String returned from RenderResult to add rewriting token if necessary,
replacing namespaces by the WSRP
- * rewrite token. fix-me: need to check for producer rewriting
- *
- * @param renderString the String to be processed for rewriting marking
- * @return a String processed to add rewriting tokens as necessary
- */
- protected String processFragmentString(String renderString)
- {
- String result = renderString.replaceAll(namespace,
WSRPRewritingConstants.WSRP_REWRITE_TOKEN);
-
- result = URLTools.replaceURLsBy(result, new
WSRPUtils.AbsoluteURLReplacementGenerator(ServletAccess.getRequest()));
- return result;
- }
-
- Object processResponse(PortletInvocationResponse response)
- {
- ContentResponse content = (ContentResponse)response;
- String itemString = null;
- byte[] itemBinary = null;
- String contentType = content.getContentType();
- switch (content.getType())
- {
- case ContentResponse.TYPE_CHARS:
- itemString = processFragmentString(content.getChars());
- break;
- case ContentResponse.TYPE_BYTES:
- itemBinary = content.getBytes(); // fix-me: might need to convert to Base64?
- break;
- case ContentResponse.TYPE_EMPTY:
- itemString = EMPTY;
- contentType = markupRequest.getMediaType(); // assume we got what we asked
for :)
- break;
- }
-
- LocalMimeResponse mimeResponse = WSRPTypeFactory.createMimeResponse(contentType,
itemString, itemBinary, getReifiedClass());
-
- mimeResponse.setLocale(markupRequest.getLocale());
-
- //TODO: figure out requiresRewriting and useCachedItem
- Boolean requiresRewriting = true;
- Boolean useCachedItem = false;
- mimeResponse.setRequiresRewriting(requiresRewriting);
- mimeResponse.setUseCachedItem(useCachedItem);
-
- //TODO: check if anything actually uses the ccpp profile warning
- String ccppProfileWarning = null;
- mimeResponse.setCcppProfileWarning(ccppProfileWarning);
-
- // cache information
- int expires = content.getCacheControl().getExpirationSecs();
- // only create a CacheControl if expiration time is not 0
- if (expires != 0)
- {
- // if expires is negative, replace by -1 to make sure
- if (expires < 0)
- {
- expires = -1;
- }
-
- mimeResponse.setCacheControl(WSRPTypeFactory.createCacheControl(expires,
WSRPConstants.CACHE_PER_USER));
- }
-
- additionallyProcessIfNeeded(mimeResponse, response);
-
- return createResponse(mimeResponse);
- }
-
- protected abstract Object createResponse(LocalMimeResponse mimeResponse);
-
- protected abstract Class<LocalMimeResponse> getReifiedClass();
-
- protected void additionallyProcessIfNeeded(LocalMimeResponse mimeResponse,
PortletInvocationResponse response)
- {
- // default implementation does nothing
- }
-}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,802 +0,0 @@
-/*
- * 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 com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
-import org.gatein.common.NotYetImplemented;
-import org.gatein.common.i18n.LocalizedString;
-import org.gatein.common.logging.Logger;
-import org.gatein.common.logging.LoggerFactory;
-import org.gatein.exports.data.ExportContext;
-import org.gatein.exports.data.ExportPortletData;
-import org.gatein.pc.api.InvalidPortletIdException;
-import org.gatein.pc.api.NoSuchPortletException;
-import org.gatein.pc.api.Portlet;
-import org.gatein.pc.api.PortletInvokerException;
-import org.gatein.pc.api.PortletStateType;
-import org.gatein.pc.api.info.PortletInfo;
-import org.gatein.pc.api.info.PreferenceInfo;
-import org.gatein.pc.api.info.PreferencesInfo;
-import org.gatein.pc.api.state.DestroyCloneFailure;
-import org.gatein.pc.api.state.PropertyChange;
-import org.gatein.pc.api.state.PropertyMap;
-import org.gatein.registration.Registration;
-import org.gatein.registration.RegistrationLocal;
-import org.gatein.wsrp.WSRPConstants;
-import org.gatein.wsrp.WSRPExceptionFactory;
-import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.spec.v2.ErrorCodes;
-import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
-import org.oasis.wsrp.v2.AccessDenied;
-import org.oasis.wsrp.v2.ClonePortlet;
-import org.oasis.wsrp.v2.CopyPortlets;
-import org.oasis.wsrp.v2.CopyPortletsResponse;
-import org.oasis.wsrp.v2.DestroyPortlets;
-import org.oasis.wsrp.v2.DestroyPortletsResponse;
-import org.oasis.wsrp.v2.ExportByValueNotSupported;
-import org.oasis.wsrp.v2.ExportPortlets;
-import org.oasis.wsrp.v2.ExportPortletsResponse;
-import org.oasis.wsrp.v2.ExportedPortlet;
-import org.oasis.wsrp.v2.Extension;
-import org.oasis.wsrp.v2.FailedPortlets;
-import org.oasis.wsrp.v2.GetPortletDescription;
-import org.oasis.wsrp.v2.GetPortletProperties;
-import org.oasis.wsrp.v2.GetPortletPropertyDescription;
-import org.oasis.wsrp.v2.GetPortletsLifetime;
-import org.oasis.wsrp.v2.GetPortletsLifetimeResponse;
-import org.oasis.wsrp.v2.ImportPortlet;
-import org.oasis.wsrp.v2.ImportPortlets;
-import org.oasis.wsrp.v2.ImportPortletsFailed;
-import org.oasis.wsrp.v2.ImportPortletsResponse;
-import org.oasis.wsrp.v2.ImportedPortlet;
-import org.oasis.wsrp.v2.InconsistentParameters;
-import org.oasis.wsrp.v2.InvalidHandle;
-import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.InvalidUserCategory;
-import org.oasis.wsrp.v2.Lifetime;
-import org.oasis.wsrp.v2.MissingParameters;
-import org.oasis.wsrp.v2.ModifyRegistrationRequired;
-import org.oasis.wsrp.v2.OperationFailed;
-import org.oasis.wsrp.v2.OperationFailedFault;
-import org.oasis.wsrp.v2.OperationNotSupported;
-import org.oasis.wsrp.v2.PortletContext;
-import org.oasis.wsrp.v2.PortletDescription;
-import org.oasis.wsrp.v2.PortletDescriptionResponse;
-import org.oasis.wsrp.v2.PortletPropertyDescriptionResponse;
-import org.oasis.wsrp.v2.Property;
-import org.oasis.wsrp.v2.PropertyDescription;
-import org.oasis.wsrp.v2.PropertyList;
-import org.oasis.wsrp.v2.ReleaseExport;
-import org.oasis.wsrp.v2.ResetProperty;
-import org.oasis.wsrp.v2.ResourceList;
-import org.oasis.wsrp.v2.ResourceSuspended;
-import org.oasis.wsrp.v2.ReturnAny;
-import org.oasis.wsrp.v2.SetExportLifetime;
-import org.oasis.wsrp.v2.SetPortletProperties;
-import org.oasis.wsrp.v2.SetPortletsLifetime;
-import org.oasis.wsrp.v2.SetPortletsLifetimeResponse;
-import org.oasis.wsrp.v2.UserContext;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-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: 11147 $
- * @since 2.4
- */
-class PortletManagementHandler extends ServiceHandler implements
PortletManagementInterface
-{
- private static final String GET_PORTLET_PROPERTY_DESCRIPTION =
"GetPortletPropertyDescription";
- private static final String GET_PORTLET_PROPERTIES =
"GetPortletProperties";
- private static final String PORTLET_CONTEXT = "PortletContext";
- private static final String GET_PORTLET_DESCRIPTION =
"GetPortletDescription";
-
- private static final Logger log =
LoggerFactory.getLogger(PortletManagementHandler.class);
-
- PortletManagementHandler(WSRPProducerImpl producer)
- {
- super(producer);
- }
-
- public PortletDescriptionResponse getPortletDescription(GetPortletDescription
getPortletDescription)
- throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
- MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getPortletDescription,
GET_PORTLET_DESCRIPTION);
- Registration registration =
producer.getRegistrationOrFailIfInvalid(getPortletDescription.getRegistrationContext());
-
- PortletContext portletContext = getPortletDescription.getPortletContext();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext,
PORTLET_CONTEXT, GET_PORTLET_DESCRIPTION);
-
- UserContext userContext = getPortletDescription.getUserContext();
- checkUserAuthorization(userContext);
-
- // RegistrationLocal.setRegistration is called further down the invocation in
ServiceDescriptionHandler.getPortletDescription
- PortletDescription description = producer.getPortletDescription(portletContext,
getPortletDescription.getDesiredLocales(), registration);
- return WSRPTypeFactory.createPortletDescriptionResponse(description);
- }
-
- public PortletPropertyDescriptionResponse
getPortletPropertyDescription(GetPortletPropertyDescription
getPortletPropertyDescription)
- throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
- MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
- {
-
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getPortletPropertyDescription,
GET_PORTLET_PROPERTY_DESCRIPTION);
-
- PortletContext portletContext = getPortletPropertyDescription.getPortletContext();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext,
PORTLET_CONTEXT, GET_PORTLET_PROPERTY_DESCRIPTION);
-
- Registration registration =
producer.getRegistrationOrFailIfInvalid(getPortletPropertyDescription.getRegistrationContext());
-
- UserContext userContext = getPortletPropertyDescription.getUserContext();
- checkUserAuthorization(userContext);
-
- List<String> desiredLocales =
getPortletPropertyDescription.getDesiredLocales();
- Portlet portlet = getPortletFrom(portletContext, registration);
- PortletInfo info = portlet.getInfo();
- PreferencesInfo prefsInfo = info.getPreferences();
-
- List<PropertyDescription> descs = Collections.emptyList();
- if (prefsInfo != null)
- {
- Set keySet = prefsInfo.getKeys();
- descs = new ArrayList<PropertyDescription>(keySet.size());
- for (Object key : keySet)
- {
- PreferenceInfo prefInfo = prefsInfo.getPreference((String)key);
-
- // WSRP Spec 8.7: return only the portion of the Portlet's persistent
state the user is allowed to modify
- // if read only status is not determined, we consider it as being read-only
to be safe
- Boolean readOnly = prefInfo.isReadOnly();
- if (readOnly != null && !readOnly)
- {
- //todo: check what we should use key
- //todo: right now we only support String properties
- PropertyDescription desc =
WSRPTypeFactory.createPropertyDescription(prefInfo.getKey(), WSRPConstants.XSD_STRING);
-
desc.setLabel(Utils.convertToWSRPLocalizedString(prefInfo.getDisplayName(),
desiredLocales));
- desc.setHint(Utils.convertToWSRPLocalizedString(prefInfo.getDescription(),
desiredLocales));
- descs.add(desc);
- }
- }
- }
-
- return WSRPTypeFactory.createPortletPropertyDescriptionResponse(descs);
- }
-
- public PortletContext clonePortlet(ClonePortlet clonePortlet)
- throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
- MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(clonePortlet,
"ClonePortlet");
-
- PortletContext portletContext = clonePortlet.getPortletContext();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext,
"PortletContext", "ClonePortlet");
-
- Registration registration =
producer.getRegistrationOrFailIfInvalid(clonePortlet.getRegistrationContext());
-
- UserContext userContext = clonePortlet.getUserContext();
- checkUserAuthorization(userContext);
-
- org.gatein.pc.api.PortletContext portalPC =
WSRPUtils.convertToPortalPortletContext(portletContext);
- try
- {
- RegistrationLocal.setRegistration(registration);
- org.gatein.pc.api.PortletContext response =
producer.getPortletInvoker().createClone(PortletStateType.OPAQUE, portalPC);
- return WSRPUtils.convertToWSRPPortletContext(response);
- }
- catch (NoSuchPortletException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(InvalidHandle.class, "Failed
to create clone for portlet '" + portletContext.getPortletHandle(), e);
- }
- catch (InvalidPortletIdException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
"Failed to create clone for portlet '" + portletContext.getPortletHandle(),
e);
- }
- catch (PortletInvokerException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Failed
to create clone for portlet '" + portletContext.getPortletHandle(), e);
- }
- finally
- {
- RegistrationLocal.setRegistration(null);
- }
- }
-
- public DestroyPortletsResponse destroyPortlets(DestroyPortlets destroyPortlets)
- throws InconsistentParameters, InvalidRegistration, MissingParameters,
ModifyRegistrationRequired,
- OperationFailed, OperationNotSupported, ResourceSuspended
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(destroyPortlets,
"DestroyPortlets");
-
- List<String> handles = destroyPortlets.getPortletHandles();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(handles, "portlet
handles to be destroyed", "DestroyPortlets");
-
- Registration registration =
producer.getRegistrationOrFailIfInvalid(destroyPortlets.getRegistrationContext());
-
- List<org.gatein.pc.api.PortletContext> portletContexts = new
ArrayList<org.gatein.pc.api.PortletContext>(handles.size());
- for (String handle : handles)
- {
-
portletContexts.add(org.gatein.pc.api.PortletContext.createPortletContext(handle));
- }
-
- try
- {
- RegistrationLocal.setRegistration(registration);
- List<DestroyCloneFailure> failuresList =
producer.getPortletInvoker().destroyClones(portletContexts);
- int failuresNumber = failuresList.size();
- List<FailedPortlets> failedPortlets;
- if (failuresNumber > 0)
- {
- // for each reason of failure, record the associated portlet handles,
expecting one portlet handle per message
- Multimap<String, String> reasonToHandles =
HashMultimap.create(failuresNumber, 1);
- for (DestroyCloneFailure failure : failuresList)
- {
- reasonToHandles.put(failure.getMessage(), failure.getPortletId());
- }
-
- // create a FailedPortlets object for each reason
- failedPortlets = new
ArrayList<FailedPortlets>(reasonToHandles.size());
- for (String reason : reasonToHandles.keys())
- {
-
failedPortlets.add(WSRPTypeFactory.createFailedPortlets(reasonToHandles.get(reason),
ErrorCodes.Codes.OPERATIONFAILED, reason));
- }
- }
- else
- {
- failedPortlets = null;
- }
-
- return WSRPTypeFactory.createDestroyPortletsResponse(failedPortlets);
- }
- catch (PortletInvokerException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Failed
to destroy clones", e);
- }
- finally
- {
- RegistrationLocal.setRegistration(null);
- }
- }
-
- public GetPortletsLifetimeResponse getPortletsLifetime(GetPortletsLifetime
getPortletsLifetime)
- throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
ModifyRegistrationRequired,
- OperationFailed, OperationNotSupported, ResourceSuspended
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class,
"Lifetime operations are not currently supported.", null);
- }
-
- public SetPortletsLifetimeResponse setPortletsLifetime(SetPortletsLifetime
setPortletsLifetime)
- throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
ModifyRegistrationRequired,
- OperationFailed, OperationNotSupported, ResourceSuspended
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class,
"Lifetime operations are not currently supported.", null);
- }
-
- public CopyPortletsResponse copyPortlets(CopyPortlets copyPortlets)
- throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
- MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
- {
- throw new NotYetImplemented();
- }
-
- public PortletContext setPortletProperties(SetPortletProperties setPortletProperties)
- throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
- MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(setPortletProperties,
"SetPortletProperties");
-
- PortletContext portletContext = setPortletProperties.getPortletContext();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext,
"PortletContext", "SetPortletProperties");
-
- PropertyList propertyList = setPortletProperties.getPropertyList();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(propertyList,
"PropertyList", "SetPortletProperties");
-
- Registration registration =
producer.getRegistrationOrFailIfInvalid(setPortletProperties.getRegistrationContext());
-
- checkUserAuthorization(setPortletProperties.getUserContext());
-
- List<Property> properties = propertyList.getProperties();
- List<ResetProperty> resetProperties = propertyList.getResetProperties();
- int changesCount = 0;
- if (properties != null)
- {
- changesCount += properties.size();
- }
- if (resetProperties != null)
- {
- changesCount += resetProperties.size();
- }
-
- if (changesCount > 0)
- {
- List<PropertyChange> changes = new
ArrayList<PropertyChange>(changesCount);
-
- if (properties != null)
- {
- for (Property property : properties)
- {
- String value = property.getStringValue();
-
- // todo: deal with XML values...
- // List<Object> values = property.getAny();
- // todo: deal with language?
- // String lang = property.getLang();
-
- changes.add(PropertyChange.newUpdate(property.getName().toString(),
value));
- }
- }
-
- if (resetProperties != null)
- {
- for (ResetProperty resetProperty : resetProperties)
- {
- changes.add(PropertyChange.newReset(resetProperty.getName().toString()));
- }
- }
-
- try
- {
- RegistrationLocal.setRegistration(registration);
- org.gatein.pc.api.PortletContext resultContext =
-
producer.getPortletInvoker().setProperties(WSRPUtils.convertToPortalPortletContext(portletContext),
- changes.toArray(new PropertyChange[changes.size()]));
- return WSRPUtils.convertToWSRPPortletContext(resultContext);
- }
- catch (NoSuchPortletException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(InvalidHandle.class,
"Failed to set properties for portlet '" + portletContext.getPortletHandle()
+ "'", e);
- }
- catch (InvalidPortletIdException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
"Failed to set properties for portlet '" + portletContext.getPortletHandle()
+ "'", e);
- }
- catch (PortletInvokerException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Failed to set properties for portlet '" + portletContext.getPortletHandle()
+ "'", e);
- }
- finally
- {
- RegistrationLocal.setRegistration(null);
- }
- }
-
- return portletContext;
- }
-
- public PropertyList getPortletProperties(GetPortletProperties getPortletProperties)
- throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
- MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getPortletProperties,
GET_PORTLET_PROPERTIES);
-
- PortletContext portletContext = getPortletProperties.getPortletContext();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext,
PORTLET_CONTEXT, GET_PORTLET_PROPERTIES);
-
- Registration registration =
producer.getRegistrationOrFailIfInvalid(getPortletProperties.getRegistrationContext());
-
- UserContext userContext = getPortletProperties.getUserContext();
- checkUserAuthorization(userContext);
-
- List<String> names = getPortletProperties.getNames();
- Set<String> keys = new HashSet<String>(names);
-
- try
- {
- PropertyMap properties;
- org.gatein.pc.api.PortletContext jbpContext =
WSRPUtils.convertToPortalPortletContext(portletContext);
-
- RegistrationLocal.setRegistration(registration);
- if (keys != null)
- {
- properties = producer.getPortletInvoker().getProperties(jbpContext, keys);
- }
- else
- {
- properties = producer.getPortletInvoker().getProperties(jbpContext);
- }
-
- //todo: we need to check that the user can actually modify the properties
- Portlet portlet = getPortletFrom(portletContext, registration);
- PortletInfo info = portlet.getInfo();
-
- PropertyList result = WSRPTypeFactory.createPropertyList();
- int propertyNb = properties.size();
-
- if (propertyNb > 0)
- {
- PreferenceInfo prefInfo;
- String key;
- List<String> values;
- LocalizedString displayName;
-
- for (Map.Entry<String, List<String>> entry :
properties.entrySet())
- {
- key = entry.getKey();
- values = entry.getValue();
- prefInfo = info.getPreferences().getPreference(key);
- displayName = prefInfo.getDisplayName();
- String lang = WSRPUtils.toString(displayName.getDefaultLocale());
-
- // todo: support multi-valued properties
- if (values.size() != 1)
- {
- throw new UnsupportedOperationException("Currently doesn't
support multi-valued properties!");
- }
- result.getProperties().add(WSRPTypeFactory.createProperty(key, lang,
values.get(0))); //todo: check what we should use key
- }
- }
-
- return result;
- }
- catch (PortletInvokerException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(InvalidHandle.class, "Could
not retrieve properties for portlet '" + portletContext + "'", e);
- }
- finally
- {
- RegistrationLocal.setRegistration(null);
- }
- }
-
- public ExportPortletsResponse exportPortlets(ExportPortlets exportPortlets) throws
AccessDenied,
- ExportByValueNotSupported, InconsistentParameters, InvalidHandle,
InvalidRegistration, InvalidUserCategory,
- MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
- {
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(exportPortlets,
"ExportPortlets", "ExportPortlets");
-
- List<PortletContext> portletContexts = exportPortlets.getPortletContext();
- if (portletContexts == null || portletContexts.isEmpty())
- {
- throw WSRP2ExceptionFactory.createWSException(MissingParameters.class,
"Missing required portletContext in ExportPortlets.", null);
- }
-
- Registration registration =
producer.getRegistrationOrFailIfInvalid(exportPortlets.getRegistrationContext());
-
- UserContext userContext = exportPortlets.getUserContext();
- checkUserAuthorization(userContext);
-
- boolean exportByValueRequired;
- if (exportPortlets.isExportByValueRequired() != null)
- {
- exportByValueRequired = exportPortlets.isExportByValueRequired();
- }
- else
- {
- exportByValueRequired = false;
- }
-
-
- //check that the export manager can handle export by value
- if (exportByValueRequired &&
!producer.getExportManager().supportExportByValue())
- {
- //TODO: instead of passing a string here, we should pass a resource so that its
localized
- WSRP2ExceptionFactory.throwWSException(ExportByValueNotSupported.class,
"The consumer is requesting portlets to be exported by value, but this consumer only
supports export by reference.", null);
- }
-
-
- List<ExportedPortlet> exportedPortlets = new
ArrayList<ExportedPortlet>();
- Map<String, FailedPortlets> failedPortletsMap = new HashMap<String,
FailedPortlets>();
-
- try
- {
- RegistrationLocal.setRegistration(registration);
-
- //TODO: try catch here?
- ExportContext exportContext =
producer.getExportManager().createExportContext(exportByValueRequired,
exportPortlets.getLifetime());
-
- for (PortletContext portletContext : exportPortlets.getPortletContext())
- {
- try
- {
- byte[] exportData;
-
- String portletHandle = portletContext.getPortletHandle();
- byte[] portletState = portletContext.getPortletState();
-
- if (portletHandle != null)
- {
- org.gatein.pc.api.PortletContext portalPC =
WSRPUtils.convertToPortalPortletContext(portletContext);
-
- producer.getPortletInvoker().getPortlet(portalPC);
-
- org.gatein.pc.api.PortletContext exportedPortalPC =
producer.getPortletInvoker().exportPortletContext(PortletStateType.OPAQUE, portalPC);
-
- PortletContext exportedPortalContext =
WSRPUtils.convertToWSRPPortletContext(exportedPortalPC);
- portletHandle = exportedPortalContext.getPortletHandle();
- portletState = exportedPortalContext.getPortletState();
-
- if (exportedPortalPC == null)
- {
- WSRP2ExceptionFactory.throwWSException(InvalidHandle.class,
"Could not find a portlet with handle " + portletHandle + " in the
producer", null);
- }
- }
- else
- {
- WSRP2ExceptionFactory.throwWSException(InvalidHandle.class, "A
portlet handle cannot be null.", null);
- }
-
- //get the exportPortletData
- ExportPortletData exportPortletData =
producer.getExportManager().createExportPortletData(exportContext, portletHandle,
portletState);
-
- //Create the exportedPortlet
- ExportedPortlet exportedPortlet =
WSRPTypeFactory.createExportedPortlet(portletHandle, exportPortletData.encodeAsBytes());
- exportedPortlets.add(exportedPortlet);
- }
-
- catch (Exception e)
- {
- if (log.isWarnEnabled())
- {
- log.warn("Error occured while trying to export a portlet.",
e);
- }
-
- ErrorCodes.Codes errorCode;
- String reason;
- if (e instanceof NoSuchPortletException || e instanceof InvalidHandle)
- {
- errorCode = ErrorCodes.Codes.INVALIDHANDLE;
- reason = "The specified portlet handle is invalid";
- }
- else // default error message.
- {
- errorCode = ErrorCodes.Codes.OPERATIONFAILED;
- reason = "Error preparing portlet for export";
- }
-
- if (!failedPortletsMap.containsKey(errorCode.name()))
- {
- List<String> portletHandles = new ArrayList<String>();
- portletHandles.add(portletContext.getPortletHandle());
-
- FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, errorCode, reason);
- failedPortletsMap.put(errorCode.name(), failedPortlets);
- }
- else
- {
- FailedPortlets failedPortlets =
failedPortletsMap.get(errorCode.name());
-
failedPortlets.getPortletHandles().add(portletContext.getPortletHandle());
- }
- }
- }
-
- //TODO: handle resourceLists better (should be using for things like errors)
- ResourceList resourceList = null;
-
- return
WSRPTypeFactory.createExportPortletsResponse(exportContext.encodeAsBytes(),
exportedPortlets, new ArrayList<FailedPortlets>(failedPortletsMap.values()),
exportContext.getLifeTime(), resourceList);
- }
- catch (Exception e)//TODO ADD PROPER EXCEPTION HANDLING
- {
- e.printStackTrace();
- throw new OperationFailed("TODO: add proper error handling", new
OperationFailedFault());
- }
- finally
- {
- RegistrationLocal.setRegistration(null);
- }
- }
-
- public ImportPortletsResponse importPortlets(ImportPortlets importPortlets) throws
OperationFailed, InvalidRegistration, MissingParameters
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(importPortlets,
"ImportPortlets");
-
- List<ImportPortlet> importPortletList = importPortlets.getImportPortlet();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(importPortletList,
"ImportPortlet", "ImportPortlets");
-
- Registration registration =
producer.getRegistrationOrFailIfInvalid(importPortlets.getRegistrationContext());
-
- // check if we have a valid userContext or not
- UserContext userContext = importPortlets.getUserContext();
- checkUserAuthorization(userContext);
-
- try
- {
- RegistrationLocal.setRegistration(registration);
-
- byte[] importContext = importPortlets.getImportContext();
-
- Lifetime lifeTime = importPortlets.getLifetime();
-
- List<ImportedPortlet> importedPortlets = new
ArrayList<ImportedPortlet>();
- Map<String, ImportPortletsFailed> failedPortletsMap = new
HashMap<String, ImportPortletsFailed>();
-
- ExportContext exportContext;
- try
- {
- exportContext =
producer.getExportManager().createExportContext(importContext);
- }
- catch (Exception e)
- {
- throw WSRPExceptionFactory.createWSException(OperationFailed.class,
"Invalid ImportContext.", e);
- }
-
- for (ImportPortlet importPortlet : importPortletList)
- {
- try
- {
- byte[] portletData = importPortlet.getExportData();
-
- ExportPortletData exportPortletData =
producer.getExportManager().createExportPortletData(exportContext, lifeTime,
portletData);
-
- String portletHandle = exportPortletData.getPortletHandle();
- byte[] portletState = exportPortletData.getPortletState();
-
- PortletContext pc = WSRPTypeFactory.createPortletContext(portletHandle,
portletState);
- org.gatein.pc.api.PortletContext pcPortletContext =
WSRPUtils.convertToPortalPortletContext(pc);
-
- org.gatein.pc.api.PortletContext cpc =
producer.getPortletInvoker().importPortletContext(PortletStateType.OPAQUE,
pcPortletContext);
- PortletContext wpc = WSRPUtils.convertToWSRPPortletContext(cpc);
-
- ImportedPortlet importedPortlet =
WSRPTypeFactory.createImportedPortlet(importPortlet.getImportID(), wpc);
-
- importedPortlets.add(importedPortlet);
- }
- catch (Exception e)
- {
- if (log.isWarnEnabled())
- {
- log.warn("Error occured while trying to import a portlet.",
e);
- }
-
- ErrorCodes.Codes errorCode;
- String reason;
- if (e instanceof NoSuchPortletException || e instanceof InvalidHandle)
- {
- errorCode = ErrorCodes.Codes.INVALIDHANDLE;
- reason = "The specified portlet handle is invalid";
- }
- else if (e instanceof OperationFailed)
- {
- errorCode = ErrorCodes.Codes.OPERATIONFAILED;
- reason = e.getMessage();
- }
- else if (e instanceof PortletInvokerException || e instanceof
UnsupportedOperationException || e instanceof IllegalArgumentException)
- {
- errorCode = ErrorCodes.Codes.OPERATIONFAILED;
- reason = "Error trying to create imported portlet.";
- }
- else // default error message.
- {
- errorCode = ErrorCodes.Codes.OPERATIONFAILED;
- reason = "Error preparing portlet for export";
- }
-
- if (!failedPortletsMap.containsKey(errorCode.name()))
- {
- List<String> portleIDs = new ArrayList<String>();
- portleIDs.add(importPortlet.getImportID());
-
- ImportPortletsFailed failedPortlets =
WSRPTypeFactory.createImportPortletsFailed(portleIDs, errorCode, reason);
- failedPortletsMap.put(errorCode.name(), failedPortlets);
- }
- else
- {
- ImportPortletsFailed failedPortlets =
failedPortletsMap.get(errorCode.name());
- failedPortlets.getImportID().add(importPortlet.getImportID());
- }
- }
- }
-
- ResourceList resourceList = null; //TODO: figure out what exactly should be
stored in the resource list here
-
- return WSRPTypeFactory.createImportPortletsResponse(importedPortlets, new
ArrayList<ImportPortletsFailed>(failedPortletsMap.values()), resourceList);
- }
- finally
- {
- RegistrationLocal.setRegistration(null);
- }
- }
-
- public List<Extension> releaseExport(ReleaseExport releaseExport)
- {
- try
- {
- if (releaseExport != null)
- {
- ExportContext exportContext =
producer.getExportManager().createExportContext(releaseExport.getExportContext());
- producer.getExportManager().releaseExport(exportContext);
- }
- }
- catch (Exception e)
- {
- if (log.isWarnEnabled())
- {
- log.warn("Error occured while trying to perform a ReleaseExport",
e);
- }
- }
-
- //this method shouldn't return anything
- return new ReturnAny().getExtensions();
- }
-
- public Lifetime setExportLifetime(SetExportLifetime setExportLifetime) throws
OperationFailed, InvalidRegistration
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(setExportLifetime,
"setExportLifetimePortlets");
-
- byte[] exportContextBytes = setExportLifetime.getExportContext();
- //NOTE: we can't throw a MissingParameterException since its not allowed as
part of the spec
- if (exportContextBytes == null)
- {
- WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot call
setExportLifetime with an empty ExportContext.", null);
- }
-
- Registration registration =
producer.getRegistrationOrFailIfInvalid(setExportLifetime.getRegistrationContext());
-
- // check if we have a valid userContext or not
- UserContext userContext = setExportLifetime.getUserContext();
- checkUserAuthorization(userContext);
-
- try
- {
- RegistrationLocal.setRegistration(registration);
-
- ExportContext exportContext =
producer.getExportManager().createExportContext(exportContextBytes);
-
- return producer.getExportManager().setExportLifetime(exportContext,
setExportLifetime.getLifetime());
-
- }
- catch (Exception e)
- {
- throw WSRPExceptionFactory.createWSException(OperationFailed.class,
"Operation Failed while trying to setExportLifetime.", e);
- }
- finally
- {
- RegistrationLocal.setRegistration(null);
- }
- }
-
- private void checkUserAuthorization(UserContext userContext)
- {
- //todo: implement
- if (userContext != null)
- {
-
- }
- }
-
- private Portlet getPortletFrom(PortletContext portletContext, Registration
registration) throws InvalidHandle
- {
- Portlet portlet;
- try
- {
- RegistrationLocal.setRegistration(registration);
- portlet =
producer.getPortletInvoker().getPortlet(WSRPUtils.convertToPortalPortletContext(portletContext));
- return portlet;
- }
- catch (PortletInvokerException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(InvalidHandle.class, "Could
not retrieve portlet '" + portletContext.getPortletHandle() + "'",
e);
- }
- finally
- {
- RegistrationLocal.setRegistration(null);
- }
- }
-}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,406 +0,0 @@
-/*
- * 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.util.ParameterValidation;
-import org.gatein.pc.api.Mode;
-import org.gatein.pc.api.WindowState;
-import org.gatein.registration.Consumer;
-import org.gatein.registration.ConsumerCapabilities;
-import org.gatein.registration.NoSuchRegistrationException;
-import org.gatein.registration.Registration;
-import org.gatein.registration.RegistrationException;
-import org.gatein.registration.RegistrationStatus;
-import org.gatein.registration.RegistrationUtils;
-import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
-import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
-import org.oasis.wsrp.v2.AccessDenied;
-import org.oasis.wsrp.v2.Extension;
-import org.oasis.wsrp.v2.GetRegistrationLifetime;
-import org.oasis.wsrp.v2.InvalidHandle;
-import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.Lifetime;
-import org.oasis.wsrp.v2.MissingParameters;
-import org.oasis.wsrp.v2.ModifyRegistration;
-import org.oasis.wsrp.v2.ModifyRegistrationRequired;
-import org.oasis.wsrp.v2.OperationFailed;
-import org.oasis.wsrp.v2.OperationNotSupported;
-import org.oasis.wsrp.v2.Property;
-import org.oasis.wsrp.v2.RegistrationContext;
-import org.oasis.wsrp.v2.RegistrationData;
-import org.oasis.wsrp.v2.RegistrationState;
-import org.oasis.wsrp.v2.ResourceSuspended;
-import org.oasis.wsrp.v2.SetRegistrationLifetime;
-
-import javax.xml.namespace.QName;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 13202 $
- * @since 2.4
- */
-class RegistrationHandler extends ServiceHandler implements RegistrationInterface
-{
- RegistrationHandler(WSRPProducerImpl producer)
- {
- super(producer);
- }
-
- public RegistrationContext register(RegistrationData registrationData)
- throws MissingParameters, OperationFailed, OperationNotSupported
- {
- ProducerRegistrationRequirements registrationRequirements =
producer.getProducerRegistrationRequirements();
- if (registrationRequirements.isRegistrationRequired())
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(registrationData,
"RegistrationData");
- String consumerName = registrationData.getConsumerName();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(consumerName,
"consumer name", "RegistrationData");
-
- String consumerAgent = registrationData.getConsumerAgent();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(consumerAgent,
"consumer agent", "RegistrationData");
-
- Registration registration;
- try
- {
- log.debug("Attempting to register consumer named '" +
consumerName + "', agent '" + consumerAgent + "'.");
-
- // check that the consumer agent is valid before trying to register
- RegistrationUtils.validateConsumerAgent(consumerAgent);
-
- registration =
producer.getRegistrationManager().addRegistrationTo(consumerName,
createRegistrationProperties(registrationData),
registrationRequirements.getRegistrationProperties(), true);
- updateRegistrationInformation(registration, registrationData);
- }
- catch (Exception e)
- {
- String msg = "Could not register consumer named '" +
consumerName + "'";
- log.debug(msg, e);
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, msg, e);
- }
-
- RegistrationContext registrationContext =
WSRPTypeFactory.createRegistrationContext(registration.getRegistrationHandle());
- log.debug("Registration completed without error.");
- return registrationContext;
- }
-
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Registration shouldn't be attempted if registration is not required",
null);
- }
-
- private void updateRegistrationInformation(Registration registration, RegistrationData
registrationData)
- {
- registration.setStatus(RegistrationStatus.VALID);
- Consumer consumer = registration.getConsumer();
- consumer.setConsumerAgent(registrationData.getConsumerAgent());
- ConsumerCapabilities capabilities = consumer.getCapabilities();
-
- List<String> modeStrings = registrationData.getConsumerModes();
- int modesNb = modeStrings.size();
- if (modesNb > 0)
- {
- List<Mode> modes = new ArrayList<Mode>(modesNb);
- for (String modeString : modeStrings)
- {
- modes.add(WSRPUtils.getJSR168PortletModeFromWSRPName(modeString));
- }
- capabilities.setSupportedModes(modes);
- }
-
- List<String> wsStrings = registrationData.getConsumerWindowStates();
- int wsNb = wsStrings.size();
- if (wsNb > 0)
- {
- List<WindowState> windowStates = new ArrayList<WindowState>(wsNb);
- for (String wsString : wsStrings)
- {
- windowStates.add(WSRPUtils.getJSR168WindowStateFromWSRPName(wsString));
- }
- capabilities.setSupportedWindowStates(windowStates);
- }
-
- capabilities.setSupportedUserScopes(registrationData.getConsumerUserScopes());
- capabilities.setSupportsGetMethod(registrationData.isMethodGetSupported());
-
- producer.getRegistrationManager().getPersistenceManager().saveChangesTo(consumer);
- }
-
- public List<Extension> deregister(RegistrationContext deregister)
- throws InvalidRegistration, OperationFailed, OperationNotSupported,
ResourceSuspended
- {
- if (producer.getProducerRegistrationRequirements().isRegistrationRequired())
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(deregister,
"RegistrationContext");
-
- String registrationHandle = deregister.getRegistrationHandle();
- if (ParameterValidation.isNullOrEmpty(registrationHandle))
- {
- throwInvalidRegistrationFault("Null or empty registration
handle");
- }
-
- log.debug("Attempting to deregister registration with handle '" +
registrationHandle + "'");
-
- String msg = "Could not deregister registration with handle '" +
registrationHandle + "'";
- try
- {
- producer.getRegistrationManager().removeRegistration(registrationHandle);
- }
- catch (NoSuchRegistrationException e)
- {
- log.debug(msg, e);
- throwInvalidRegistrationFault(e.getLocalizedMessage());
- }
- catch (RegistrationException e)
- {
- log.debug(msg, e);
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, msg, e);
- }
-
- return Collections.emptyList();
- }
-
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Deregistration shouldn't be attempted if registration is not required",
null);
- }
-
- public RegistrationState modifyRegistration(ModifyRegistration modifyRegistration)
- throws InvalidRegistration, MissingParameters, OperationFailed,
OperationNotSupported, ResourceSuspended
- {
- if (producer.getProducerRegistrationRequirements().isRegistrationRequired())
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(modifyRegistration,
"ModifyRegistration");
-
- RegistrationContext registrationContext =
modifyRegistration.getRegistrationContext();
-
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(registrationContext,
"RegistrationContext", "ModifyRegistration");
- String registrationHandle = registrationContext.getRegistrationHandle();
- if (ParameterValidation.isNullOrEmpty(registrationHandle))
- {
- throwInvalidRegistrationFault("Null or empty registration
handle");
- }
-
- RegistrationData registrationData = modifyRegistration.getRegistrationData();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(registrationData,
"RegistrationData", "ModifyRegistration");
-
- String consumerName = registrationData.getConsumerName();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(consumerName,
"consumer name", "RegistrationData");
-
- String consumerAgent = registrationData.getConsumerAgent();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(consumerAgent,
"consumer agent", "RegistrationData");
-
- log.debug("Attempting to modify registration with handle '" +
registrationHandle + "'");
- String msg = "Could not modify registration with handle '" +
registrationHandle + "'";
- try
- {
- Registration registration =
producer.getRegistrationManager().getRegistration(registrationHandle);
-
- Map<QName, Object> properties =
createRegistrationProperties(registrationData);
-
- // check that the given registration properties are acceptable according to
expectations and policy
- ProducerRegistrationRequirements req =
producer.getProducerRegistrationRequirements();
- req.getPolicy().validateRegistrationDataFor(properties, consumerName,
req.getRegistrationProperties(), producer.getRegistrationManager());
-
- registration.updateProperties(properties);
- updateRegistrationInformation(registration, registrationData);
- }
- catch (NoSuchRegistrationException e)
- {
- log.debug(msg, e);
- throwInvalidRegistrationFault(e.getLocalizedMessage());
- }
- catch (RegistrationException e)
- {
- log.debug(msg, e);
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, msg, e);
- }
-
-
- log.debug("Modified registration with handle '" +
registrationHandle + "'");
- return null;
- }
-
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Modifying
a registration shouldn't be attempted if registration is not required", null);
- }
-
- public Lifetime getRegistrationLifetime(GetRegistrationLifetime
getRegistrationLifetime)
- throws AccessDenied, InvalidHandle, InvalidRegistration,
ModifyRegistrationRequired, OperationFailed,
- OperationNotSupported, ResourceSuspended
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class,
"Lifetime operations are not currently supported.", null);
- }
-
- public Lifetime setRegistrationLifetime(SetRegistrationLifetime
setRegistrationLifetime)
- throws AccessDenied, InvalidHandle, InvalidRegistration,
ModifyRegistrationRequired, OperationFailed,
- OperationNotSupported, ResourceSuspended
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class,
"Lifetime operations are not currently supported.", null);
- }
-
- /**
- * @param reg
- * @param throwExceptionIfInvalid
- * @return
- * @since 2.6.2
- */
- boolean isRegistrationValid(Registration reg, boolean throwExceptionIfInvalid) throws
InvalidRegistration, OperationFailed
- {
- if (reg == null)
- {
- if (producer.getProducerRegistrationRequirements().isRegistrationRequired())
- {
- log.debug("Registration is required yet no RegistrationContext was
provided: registration invalid!");
- if (throwExceptionIfInvalid)
- {
- throwInvalidRegistrationFault("registration is required yet no
RegistrationContext was provided!");
- }
- return false;
- }
-
- log.debug("Registration not required, no registration: registration
valid!");
- return true;
- }
- else
- {
- boolean isValid = RegistrationStatus.VALID.equals(reg.getStatus());
- boolean isPending = RegistrationStatus.PENDING.equals(reg.getStatus());
- log.debug("Registration required: registration is " + (isValid ?
"valid!" : (isPending ? "pending!" : "invalid!")));
-
- if (throwExceptionIfInvalid)
- {
- if (isPending)
- {
- throwOperationFailedFault("Registration with handle '" +
reg.getRegistrationHandle()
- + "' is pending. Consumer needs to call
modifyRegistration().", null);
- }
- else
- {
- if (!isValid)
- {
- throwInvalidRegistrationFault("registration with handle
'" + reg.getRegistrationHandle() + "' is not valid!");
- }
- }
- }
-
- return isValid;
- }
- }
-
- /**
- * @param registrationContext
- * @return
- * @since 2.6.2
- */
- Registration getRegistrationFrom(RegistrationContext registrationContext) throws
InvalidRegistration, OperationFailed
- {
- if (producer.getProducerRegistrationRequirements().isRegistrationRequired())
- {
- if (registrationContext == null)
- {
- throwInvalidRegistrationFault("registration context is missing but
registration is required");
- }
-
- String regHandle = registrationContext.getRegistrationHandle();
- if (regHandle == null)
- {
- throwInvalidRegistrationFault("registration handle is missing but
registration is required");
- }
-
- try
- {
- Registration registration =
producer.getRegistrationManager().getRegistration(regHandle);
- if (registration == null)
- {
- throwInvalidRegistrationFault("provided registration handle
'" + regHandle + "' is not registered with this producer");
- }
- return registration;
- }
- catch (RegistrationException e)
- {
- throwOperationFailedFault("Failed to retrieve registration information
associated with handle " + regHandle, e);
- return null;
- }
- }
- else
- {
- if (registrationContext != null)
- {
- throwInvalidRegistrationFault("no registration necessary yet one was
provided!");
- }
- return null;
- }
- }
-
- private void throwOperationFailedFault(String message, RegistrationException e) throws
OperationFailed
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, message, e);
- }
-
- boolean throwInvalidRegistrationFault(String message) throws InvalidRegistration
- {
- throw WSRP2ExceptionFactory.throwWSException(InvalidRegistration.class,
"Invalid registration: " + message, null);
- }
-
- private Map<QName, Object> createRegistrationProperties(RegistrationData
registrationData)
- {
- List<Property> regProperties = registrationData.getRegistrationProperties();
- Map<QName, Object> properties;
- if (regProperties != null && !regProperties.isEmpty())
- {
- properties = new HashMap<QName, Object>(regProperties.size());
- for (Property property : regProperties)
- {
- // todo: should be more detailed here... use the language, allow other value
types...
- QName propName = property.getName();
- String propValue = property.getStringValue();
- if (producer.getProducerRegistrationRequirements().acceptValueFor(propName,
propValue))
- {
- properties.put(propName, propValue);
- }
- else
- {
- throw new IllegalArgumentException("Registration properties named
'" + propName + "' with value '"
- + propValue + "' was rejected by the WSRP producer.");
- }
- }
- }
- else
- {
- properties = Collections.emptyMap();
- }
-
- return properties;
- }
-
- private List getListFromArray(String[] array, boolean useEmptyForNull)
- {
- if (array == null)
- {
- return useEmptyForNull ? Collections.EMPTY_LIST : null;
- }
- return Arrays.asList(array);
- }
-}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RenderRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RenderRequestProcessor.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RenderRequestProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,124 +0,0 @@
-/*
- * 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.pc.api.invocation.PortletInvocation;
-import org.gatein.pc.api.invocation.RenderInvocation;
-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.WSRPTypeFactory;
-import org.oasis.wsrp.v2.GetMarkup;
-import org.oasis.wsrp.v2.InvalidHandle;
-import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.MarkupContext;
-import org.oasis.wsrp.v2.MimeRequest;
-import org.oasis.wsrp.v2.MissingParameters;
-import org.oasis.wsrp.v2.OperationFailed;
-import org.oasis.wsrp.v2.PortletContext;
-import org.oasis.wsrp.v2.RegistrationContext;
-import org.oasis.wsrp.v2.RuntimeContext;
-import org.oasis.wsrp.v2.UnsupportedMimeType;
-import org.oasis.wsrp.v2.UnsupportedMode;
-import org.oasis.wsrp.v2.UnsupportedWindowState;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 13121 $
- * @since 2.6
- */
-public class RenderRequestProcessor extends MimeResponseProcessor<MarkupContext>
-{
- private final GetMarkup getMarkup;
-
- public RenderRequestProcessor(WSRPProducerImpl producer, GetMarkup getMarkup) throws
UnsupportedMimeType,
- UnsupportedWindowState, InvalidHandle, UnsupportedMode, MissingParameters,
InvalidRegistration, OperationFailed
- {
- super(producer);
- this.getMarkup = getMarkup;
- prepareInvocation();
- }
-
- RegistrationContext getRegistrationContext()
- {
- return getMarkup.getRegistrationContext();
- }
-
- RuntimeContext getRuntimeContext()
- {
- return getMarkup.getRuntimeContext();
- }
-
- MimeRequest getParams()
- {
- return getMarkup.getMarkupParams();
- }
-
- PortletContext getPortletContext()
- {
- return getMarkup.getPortletContext();
- }
-
- org.oasis.wsrp.v2.UserContext getUserContext()
- {
- return getMarkup.getUserContext();
- }
-
- String getContextName()
- {
- return MarkupHandler.GET_MARKUP;
- }
-
- AccessMode getAccessMode()
- {
- return AccessMode.READ_ONLY;
- }
-
- @Override
- PortletInvocation initInvocation(WSRPPortletInvocationContext context)
- {
- // MUST match namespace generation used in PortletResponseImpl.getNamespace in
portlet module...
- namespace =
PortletUtils.generateNamespaceFrom(context.getWindowContext().getId());
-
- return new RenderInvocation(context);
- }
-
- @Override
- protected Object createResponse(MarkupContext mimeResponse)
- {
- return WSRPTypeFactory.createMarkupResponse(mimeResponse);
- }
-
- @Override
- protected Class<MarkupContext> getReifiedClass()
- {
- return MarkupContext.class;
- }
-
- @Override
- protected void additionallyProcessIfNeeded(MarkupContext markupContext,
PortletInvocationResponse response)
- {
- markupContext.setPreferredTitle(portletDescription.getTitle().getValue());
- }
-}
Deleted:
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-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RequestProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,516 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
- * contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.gatein.wsrp.producer;
-
-import org.gatein.common.net.media.MediaType;
-import org.gatein.common.util.MarkupInfo;
-import org.gatein.common.util.ParameterValidation;
-import org.gatein.pc.api.Mode;
-import org.gatein.pc.api.Portlet;
-import org.gatein.pc.api.PortletInvokerException;
-import org.gatein.pc.api.StateString;
-import org.gatein.pc.api.WindowState;
-import org.gatein.pc.api.invocation.PortletInvocation;
-import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
-import org.gatein.pc.api.spi.PortalContext;
-import org.gatein.pc.api.spi.SecurityContext;
-import org.gatein.pc.api.spi.UserContext;
-import org.gatein.pc.api.spi.WindowContext;
-import org.gatein.pc.api.state.AccessMode;
-import org.gatein.registration.Registration;
-import org.gatein.wsrp.UserContextConverter;
-import org.gatein.wsrp.WSRPConstants;
-import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
-import org.oasis.wsrp.v2.InvalidHandle;
-import org.oasis.wsrp.v2.InvalidRegistration;
-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;
-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.RuntimeContext;
-import org.oasis.wsrp.v2.SessionParams;
-import org.oasis.wsrp.v2.UnsupportedMimeType;
-import org.oasis.wsrp.v2.UnsupportedMode;
-import org.oasis.wsrp.v2.UnsupportedWindowState;
-
-import java.security.Principal;
-import java.util.ArrayList;
-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: 13121 $
- * @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 InvalidRegistration, OperationFailed, InvalidHandle,
- UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode, MissingParameters
- {
- Registration registration =
producer.getRegistrationOrFailIfInvalid(getRegistrationContext());
-
- // get session information and deal with it
- final RuntimeContext runtimeContext = getRuntimeContext();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(runtimeContext,
"RuntimeContext", getContextName());
-
- checkForSessionIDs(runtimeContext);
-
- // get parameters
- final MimeRequest params = getParams();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(params,
"MarkupParams", getContextName());
-
- // get portlet handle
- PortletContext wsrpPC = getPortletContext();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(wsrpPC,
"PortletContext", getContextName());
- org.gatein.pc.api.PortletContext portletContext =
WSRPUtils.convertToPortalPortletContext(wsrpPC);
-
- // retrieve the portlet
- try
- {
- // calls RegistrationLocal.setRegistration so no need to here
- portlet = producer.getPortletWith(portletContext, registration);
- }
- catch (PortletInvokerException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not retrieve portlet '" + portletContext + "'", e);
- }
-
- // get portlet description for the desired portlet...
- final List<String> desiredLocales = params.getLocales();
- portletDescription = producer.getPortletDescription(portlet, desiredLocales);
- if (Boolean.TRUE.equals(portletDescription.isUsesMethodGet()))
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Portlets using GET method in forms are not currently supported.", null);
- }
-
- List<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
- final org.oasis.wsrp.v2.UserContext wsrpUserContext = getUserContext();
- checkUserContext(wsrpUserContext);
-
- SecurityContext securityContext = createSecurityContext(params, runtimeContext,
wsrpUserContext);
- MarkupInfo streamInfo = createStreamInfo(markupRequest);
- PortalContext portalContext = createPortalContext(params, markupRequest);
- UserContext userContext = createUserContext(wsrpUserContext,
markupRequest.getLocale(), desiredLocales);
- instanceContext = createInstanceContext(portletContext, getAccessMode(),
runtimeContext.getPortletInstanceKey());
- WindowContext windowContext = createWindowContext(portletContext.getId(),
runtimeContext);
-
- // prepare the invocation
- WSRPPortletInvocationContext context = new WSRPPortletInvocationContext(streamInfo,
securityContext, portalContext, userContext, instanceContext, windowContext);
- PortletInvocation invocation = initInvocation(context);
-
- invocation.setTarget(portlet.getContext());
-
invocation.setWindowState(WSRPUtils.getJSR168WindowStateFromWSRPName(markupRequest.getWindowState()));
-
invocation.setMode(WSRPUtils.getJSR168PortletModeFromWSRPName(markupRequest.getMode()));
-
- NavigationalContext navigationalContext = params.getNavigationalContext();
- if (navigationalContext != null)
- {
- StateString navigationalState =
createNavigationalState(navigationalContext.getOpaqueValue());
- invocation.setNavigationalState(navigationalState);
-
- List<NamedString> publicParams = navigationalContext.getPublicValues();
- if (ParameterValidation.existsAndIsNotEmpty(publicParams))
- {
- Map<String, String[]> publicNS =
WSRPUtils.createPublicNSFrom(publicParams);
- invocation.setPublicNavigationalState(publicNS);
- }
- }
-
- context.contextualize(invocation);
- setInvocation(invocation);
- }
-
- abstract RegistrationContext getRegistrationContext();
-
- abstract RuntimeContext getRuntimeContext();
-
- abstract MimeRequest getParams();
-
- abstract PortletContext getPortletContext();
-
- abstract org.oasis.wsrp.v2.UserContext getUserContext();
-
- abstract String getContextName();
-
- abstract AccessMode getAccessMode() throws MissingParameters;
-
- abstract PortletInvocation initInvocation(WSRPPortletInvocationContext context);
-
- 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(List<MarkupType> markupTypes,
MimeRequest params, Portlet portlet)
- throws UnsupportedMimeType, UnsupportedMode, UnsupportedWindowState
- {
- List<String> desiredMIMETypes = params.getMimeTypes();
- MarkupType markupType = null;
-
- // Get the MIME type to use
- for (String desiredMIMEType : desiredMIMETypes)
- {
- for (MarkupType type : markupTypes)
- {
- if (desiredMIMEType.equals(type.getMimeType()))
- {
- markupType = type;
- break;
- }
- }
- }
-
- // no MIME type was found: error!
- if (markupType == null)
- {
- throw WSRP2ExceptionFactory.throwWSException(UnsupportedMimeType.class,
"None of the specified MIME types are supported by portlet '" +
portlet.getContext().getId() + "'", null);
- }
-
- // use user-desired locales
- List<String> locales = params.getLocales();
- List<String> supportedLocales = new
ArrayList<String>(markupType.getLocales());
- if (supportedLocales != null)
- {
- // reset markup type locales
- markupType.getLocales().clear();
- boolean found = false;
-
- // find the best match
- for (String locale : locales)
- {
- for (String supportedLocale : supportedLocales)
- {
- if (locale.equals(supportedLocale))
- {
- markupType.getLocales().add(locale);
- found = true;
- break;
- }
- }
-
- if (found)
- {
- break;
- }
- }
-
- // if no best match was found, use whatever the user gave us
- if (!found)
- {
- markupType.getLocales().addAll(locales);
- }
- }
- else
- {
- markupType.getLocales().addAll(locales);
- }
-
- // get the mode
- String mode;
- try
- {
- mode = getMatchingOrFailFrom(markupType.getModes(), params.getMode(),
PORTLET_MODE);
- }
- catch (IllegalArgumentException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(UnsupportedMode.class,
"Unsupported mode '" + params.getMode() + "'", e);
- }
-
- // get the window state
- String windowState;
- try
- {
- windowState = getMatchingOrFailFrom(markupType.getWindowStates(),
params.getWindowState(), WINDOW_STATE);
- }
- catch (IllegalArgumentException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(UnsupportedWindowState.class,
"Unsupported window state '" + params.getWindowState() + "'",
e);
- }
-
- // get the character set
- String characterSet =
getMatchingOrDefaultFrom(Collections.<String>emptyList(),
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(List<String> possibleValues, String
desired, String valueType) throws IllegalArgumentException
- {
- if (possibleValues.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(List<String> possibleValues,
List<String> preferredValues, String defaultValue)
- {
- if (preferredValues != null && possibleValues != null)
- {
- for (String preferredValue : preferredValues)
- {
- if (possibleValues.contains(preferredValue))
- {
- return preferredValue;
- }
- }
- }
-
- return defaultValue;
- }
-
- private void checkUserContext(org.oasis.wsrp.v2.UserContext wsrpUserContext) throws
MissingParameters
- {
- if (wsrpUserContext != null)
- {
-
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(wsrpUserContext.getUserContextKey(),
"User Context Key", "UserContext");
- }
- }
-
-
- private void checkForSessionIDs(RuntimeContext runtimeContext) throws OperationFailed
- {
- SessionParams sessionParams = runtimeContext.getSessionParams();
- if (sessionParams != null && sessionParams.getSessionID() != null)
- {
- MarkupHandler.throwOperationFaultOnSessionOperation();
- }
- }
-
- protected StateString createNavigationalState(String navigationalState)
- {
- if (navigationalState == null)
- {
- return null;
- }
- else
- {
- return StateString.create(navigationalState);
- }
- }
-
- private WSRPInstanceContext createInstanceContext(org.gatein.pc.api.PortletContext
portletContext, final AccessMode accessMode, String instanceId)
- {
- return new WSRPInstanceContext(portletContext, accessMode, instanceId);
- }
-
- 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.oasis.wsrp.v2.UserContext
userContext,
- String preferredLocale, final List<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 MimeRequest params, final
MarkupRequest markupRequest)
- {
- return new PortalContext()
- {
-
- public String getInfo()
- {
- return PortalContext.VERSION.toString();
- }
-
- public Set<WindowState> getWindowStates()
- {
- List<String> validNewWindowStates = params.getValidNewWindowStates();
- if (ParameterValidation.existsAndIsNotEmpty(validNewWindowStates))
- {
- Set<WindowState> states = new
HashSet<WindowState>(validNewWindowStates.size());
- for (String state : validNewWindowStates)
- {
- states.add(WSRPUtils.getJSR168WindowStateFromWSRPName(state));
- }
- return states;
- }
- return markupRequest.getSupportedWindowStates();
- }
-
- public Set<Mode> getModes()
- {
- List<String> validNewModes = params.getValidNewModes();
- if (ParameterValidation.existsAndIsNotEmpty(validNewModes))
- {
- Set<Mode> modes = new HashSet<Mode>(validNewModes.size());
- for (String mode : validNewModes)
- {
- modes.add(WSRPUtils.getJSR168PortletModeFromWSRPName(mode));
- }
- return modes;
- }
- return markupRequest.getSupportedModes();
- }
-
- public Map<String, String> getProperties()
- {
- return Collections.emptyMap();
- }
- };
- }
-
- private MarkupInfo createStreamInfo(MarkupRequest markupRequest) throws
UnsupportedMimeType
- {
- MarkupInfo markupInfo;
- try
- {
- markupInfo = new MarkupInfo(MediaType.create(markupRequest.getMediaType()),
markupRequest.getCharacterSet());
- }
- catch (IllegalArgumentException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(UnsupportedMimeType.class,
e.getLocalizedMessage(), e);
- }
- return markupInfo;
- }
-
- // fix-me: check that the correct semantics is used.
-
- private SecurityContext createSecurityContext(final MimeRequest params, final
RuntimeContext runtimeContext,
- final org.oasis.wsrp.v2.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)
- {
- return wsrpUserContext != null &&
wsrpUserContext.getUserCategories().contains(roleName);
- }
-
- public boolean isAuthenticated()
- {
- return wsrpUserContext != null;
- }
- };
- }
-
- public PortletInvocation getInvocation()
- {
- return invocation;
- }
-
- public void setInvocation(PortletInvocation invocation)
- {
- this.invocation = invocation;
- }
-}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ResourceRequestProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ResourceRequestProcessor.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ResourceRequestProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,158 +0,0 @@
-/*
- * 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.pc.api.cache.CacheLevel;
-import org.gatein.pc.api.invocation.PortletInvocation;
-import org.gatein.pc.api.invocation.ResourceInvocation;
-import org.gatein.pc.api.state.AccessMode;
-import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
-import org.gatein.wsrp.WSRPResourceURL;
-import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
-import org.oasis.wsrp.v2.GetResource;
-import org.oasis.wsrp.v2.InvalidHandle;
-import org.oasis.wsrp.v2.InvalidRegistration;
-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.RegistrationContext;
-import org.oasis.wsrp.v2.ResourceContext;
-import org.oasis.wsrp.v2.ResourceParams;
-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
MimeResponseProcessor<ResourceContext>
-{
- private final GetResource getResource;
-
- public ResourceRequestProcessor(WSRPProducerImpl producer, GetResource getResource)
throws InvalidRegistration, OperationFailed, MissingParameters, InvalidHandle,
UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode
- {
- super(producer);
- this.getResource = getResource;
- prepareInvocation();
- }
-
- public PortletContext getPortletContext()
- {
- return getResource.getPortletContext();
- }
-
- @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();
-
- // only set the resource id if it's different from the place holder we use if
the portlet doesn't set one
- String id = this.getResource.getResourceParams().getResourceID();
- if (!WSRPResourceURL.DEFAULT_RESOURCE_ID.equals(id))
- {
- resourceInvocation.setResourceId(id);
- }
-
- 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()));
-
- String resourceCacheability = resourceParams.getResourceCacheability();
- if (resourceCacheability != null)
- {
- CacheLevel cacheLevel =
WSRPUtils.getCacheLevelFromResourceCacheability(resourceParams.getResourceCacheability());
- resourceInvocation.setCacheLevel(cacheLevel);
- }
- else
- {
- // according to JSR 286, cache level must default to ResourceURL.PAGE
- resourceInvocation.setCacheLevel(CacheLevel.PAGE);
- }
-
- return resourceInvocation;
- }
-
- @Override
- protected Object createResponse(ResourceContext resourceContext)
- {
- return WSRPTypeFactory.createResourceResponse(resourceContext);
- }
-
- @Override
- protected Class<ResourceContext> getReifiedClass()
- {
- return ResourceContext.class;
- }
-}
-
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,502 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
- * contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.gatein.wsrp.producer;
-
-import org.gatein.common.net.media.MediaType;
-import org.gatein.common.util.ParameterValidation;
-import org.gatein.pc.api.Portlet;
-import org.gatein.pc.api.PortletInvokerException;
-import org.gatein.pc.api.TransportGuarantee;
-import org.gatein.pc.api.info.CapabilitiesInfo;
-import org.gatein.pc.api.info.EventInfo;
-import org.gatein.pc.api.info.EventingInfo;
-import org.gatein.pc.api.info.MetaInfo;
-import org.gatein.pc.api.info.ModeInfo;
-import org.gatein.pc.api.info.NavigationInfo;
-import org.gatein.pc.api.info.ParameterInfo;
-import org.gatein.pc.api.info.PortletInfo;
-import org.gatein.pc.api.info.SecurityInfo;
-import org.gatein.pc.api.info.WindowStateInfo;
-import org.gatein.registration.Registration;
-import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
-import org.gatein.wsrp.registration.RegistrationPropertyDescription;
-import org.gatein.wsrp.spec.v2.WSRP2Constants;
-import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
-import org.oasis.wsrp.v2.CookieProtocol;
-import org.oasis.wsrp.v2.EventDescription;
-import org.oasis.wsrp.v2.GetServiceDescription;
-import org.oasis.wsrp.v2.InvalidHandle;
-import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.MarkupType;
-import org.oasis.wsrp.v2.ModelDescription;
-import org.oasis.wsrp.v2.ModifyRegistrationRequired;
-import org.oasis.wsrp.v2.OperationFailed;
-import org.oasis.wsrp.v2.ParameterDescription;
-import org.oasis.wsrp.v2.PortletContext;
-import org.oasis.wsrp.v2.PortletDescription;
-import org.oasis.wsrp.v2.RegistrationContext;
-import org.oasis.wsrp.v2.ResourceSuspended;
-import org.oasis.wsrp.v2.ServiceDescription;
-
-import javax.xml.namespace.QName;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-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>
- * @version $Revision: 12017 $
- * @since 2.4
- */
-class ServiceDescriptionHandler extends ServiceHandler implements
ServiceDescriptionInterface
-{
- // JBPORTAL-1220: force call to initCookie... Required so that BEA version < 9.2
will behave properly as a Consumer
- private static final CookieProtocol BEA_8_CONSUMER_FIX = CookieProtocol.PER_USER;
- private ServiceDescriptionInfo serviceDescription;
-
- ServiceDescriptionHandler(WSRPProducerImpl producer)
- {
- super(producer);
- serviceDescription = new ServiceDescriptionInfo(producer);
- }
-
- public ServiceDescription getServiceDescription(GetServiceDescription gs)
- throws InvalidRegistration, ModifyRegistrationRequired, OperationFailed,
ResourceSuspended
- {
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(gs,
"GetServiceDescription");
-
- RegistrationContext registrationContext = gs.getRegistrationContext();
-
- // if a RegistrationContext is provided, we need to validate the registration
information
- Registration registration = null;
- if (registrationContext != null)
- {
- registration = producer.getRegistrationOrFailIfInvalid(registrationContext);
- }
-
- ProducerRegistrationRequirements requirements =
producer.getProducerRegistrationRequirements();
-
- //update the registration properties with the registration requirements
- serviceDescription.updateRegistrationProperties(requirements);
-
- // if we don't have registration information but a registration is required,
send registration props information
- boolean needsRegistrationProperties = registration == null &&
requirements.isRegistrationRequired();
-
- // if we allow sending portlet descriptions even when not registered
- boolean needsPortletDescriptions = !(registration == null &&
requirements.isRegistrationRequired()
- && requirements.isRegistrationRequiredForFullDescription());
- if (needsPortletDescriptions)
- {
- Set<Portlet> portlets;
- try
- {
- portlets = producer.getRemotablePortlets();
- }
- catch (PortletInvokerException e)
- {
- log.warn("Could not retrieve portlets. Reason:\n\t" +
e.getLocalizedMessage());
- portlets = Collections.emptySet();
- }
- serviceDescription.updatePortletDescriptions(portlets, gs.getDesiredLocales(),
registration);
- }
-
- return serviceDescription.getServiceDescription(needsRegistrationProperties,
needsPortletDescriptions);
- }
-
- public PortletDescription getPortletDescription(PortletContext portletContext,
List<String> desiredLocales, Registration registration) throws InvalidHandle,
OperationFailed
- {
- ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "portlet
context");
- Portlet portlet;
- try
- {
- portlet =
producer.getPortletWith(WSRPUtils.convertToPortalPortletContext(portletContext),
registration);
- return getPortletDescription(portlet, desiredLocales);
- }
- catch (PortletInvokerException e)
- {
- throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not retrieve portlet '" + portletContext + "'", e);
- }
- }
-
- /**
- * Creates a PortletDescription based on the user desired locales (ordered according
to user preferences) for the
- * specified component.
- *
- * @param portlet
- * @param desiredLocales the user desired locales (ordered according to user
preferences) to use for the description
- * @return a PortletDescription describing the specified portlet
- */
- static PortletDescription getPortletDescription(Portlet portlet, List<String>
desiredLocales)
- {
- return getPortletDescription(portlet, desiredLocales, null);
- }
-
- /**
- * Creates a PortletDescription based on the user desired locales (ordered according
to user preferences) for the
- * specified component.
- *
- * @param portlet
- * @param desiredLocales the user desired locales (ordered according to user
preferences) to use for the description
- * @return a PortletDescription describing the specified portlet
- */
- static PortletDescription getPortletDescription(Portlet portlet, List<String>
desiredLocales, ServiceDescriptionInfo sdi)
- {
- org.gatein.pc.api.PortletContext context = portlet.getContext();
- PortletInfo info = portlet.getInfo();
- String handle = context.getId();
- if (log.isDebugEnabled())
- {
- log.debug("Constructing portlet description for: " + handle);
- }
-
- CapabilitiesInfo capInfo = info.getCapabilities();
- Collection<MediaType> allMediaTypes = capInfo.getMediaTypes();
- List<MarkupType> markupTypes = new
ArrayList<MarkupType>(allMediaTypes.size());
- for (MediaType mediaType : allMediaTypes)
- {
- MarkupType markupType = WSRPTypeFactory.createMarkupType(mediaType.getValue(),
- getModeNamesFrom(capInfo.getModes(mediaType)),
getWindowStateNamesFrom(capInfo.getWindowStates(mediaType)),
- getLocaleNamesFrom(capInfo.getLocales(mediaType)));
- markupTypes.add(markupType);
- }
-
- PortletDescription desc = WSRPTypeFactory.createPortletDescription(handle,
markupTypes);
-
- // group ID
- desc.setGroupID(info.getApplicationName());
-
- MetaInfo metaInfo = info.getMeta();
-
- // description
-
desc.setDescription(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.DESCRIPTION),
desiredLocales));
-
- // short title
-
desc.setShortTitle(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.SHORT_TITLE),
desiredLocales));
-
- // title
-
desc.setTitle(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.TITLE),
desiredLocales));
-
- // display name
-
desc.setDisplayName(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME),
desiredLocales));
-
- // keywords
- // metaInfo contains comma-separated keywords: we need to extract them into a list
- org.oasis.wsrp.v2.LocalizedString concatenatedKeywords =
- Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.KEYWORDS),
desiredLocales);
- if (concatenatedKeywords != null)
- {
- String commaSeparatedKeywords = concatenatedKeywords.getValue();
- if (commaSeparatedKeywords != null && commaSeparatedKeywords.length()
> 0)
- {
- String lang = concatenatedKeywords.getLang();
- String[] keywordArray = commaSeparatedKeywords.split(",");
- for (String keyword : keywordArray)
- {
- // todo: fix resource name
- desc.getKeywords().add(WSRPTypeFactory.createLocalizedString(lang,
concatenatedKeywords.getResourceName(), keyword.trim()));
- }
- }
- }
-
- // events
- EventingInfo eventsInfo = info.getEventing();
- if (eventsInfo != null)
- {
- Map<QName, ? extends EventInfo> producedEvents =
eventsInfo.getProducedEvents();
- if (ParameterValidation.existsAndIsNotEmpty(producedEvents))
- {
- List<QName> publishedEvents = desc.getPublishedEvents();
- for (Map.Entry<QName, ? extends EventInfo> entry :
producedEvents.entrySet())
- {
- publishedEvents.add(entry.getKey());
-
- // record event info in ServiceDescriptionInfo
- if (sdi != null)
- {
- sdi.addEventInfo(entry.getValue(), desiredLocales);
- }
- }
- }
- Map<QName, ? extends EventInfo> consumedEvents =
eventsInfo.getConsumedEvents();
- if (ParameterValidation.existsAndIsNotEmpty(consumedEvents))
- {
- List<QName> handledEvents = desc.getHandledEvents();
- for (Map.Entry<QName, ? extends EventInfo> entry :
consumedEvents.entrySet())
- {
- handledEvents.add(entry.getKey());
-
- // record event info in ServiceDescriptionInfo
- if (sdi != null)
- {
- sdi.addEventInfo(entry.getValue(), desiredLocales);
- }
- }
- }
- }
-
- // public parameters
- NavigationInfo navigationInfo = info.getNavigation();
- if (navigationInfo != null)
- {
- Collection<? extends ParameterInfo> parameterInfos =
navigationInfo.getPublicParameters();
- if (ParameterValidation.existsAndIsNotEmpty(parameterInfos))
- {
- List<ParameterDescription> publicValueDescriptions =
desc.getNavigationalPublicValueDescriptions();
- for (ParameterInfo parameterInfo : parameterInfos)
- {
- String id = parameterInfo.getId();
- ParameterDescription paramDesc =
WSRPTypeFactory.createParameterDescription(id);
-
paramDesc.setDescription(Utils.convertToWSRPLocalizedString(parameterInfo.getDescription(),
desiredLocales));
- paramDesc.setLabel(WSRPTypeFactory.createLocalizedString(id));
- List<QName> names = paramDesc.getNames();
- names.add(parameterInfo.getName());
- Collection<QName> aliases = parameterInfo.getAliases();
- if (ParameterValidation.existsAndIsNotEmpty(aliases))
- {
- names.addAll(aliases);
- }
-
- publicValueDescriptions.add(paramDesc);
- }
- }
- }
-
- // security
- SecurityInfo secInfo = info.getSecurity();
- if (secInfo.containsTransportGuarantee(TransportGuarantee.INTEGRAL)
- || secInfo.containsTransportGuarantee(TransportGuarantee.CONFIDENTIAL))
- {
- desc.setOnlySecure(true);
- }
-
- /* todo:
- * [O] ID portletID
- * [O] string userCategories[]
- * [O] string userProfileItems[]
- * [O] string portletManagedModes[]
- * [O] boolean usesMethodGet
- * [O] boolean defaultMarkupSecure
- * [O] boolean userContextStoredInSession
- * [O] boolean templatesStoredInSession
- * [O] boolean hasUserSpecificState
- * [O] boolean doesUrlTemplateProcessing
- * [O] boolean mayReturnPortletState
- * [O] Extension extensions[]
- */
- return desc;
- }
-
- private static List<String> getLocaleNamesFrom(Collection<Locale>
locales)
- {
- if (locales == null || locales.isEmpty())
- {
- return null;
- }
-
- List<String> localeNames = new ArrayList<String>(locales.size());
- for (Locale locale : locales)
- {
- localeNames.add(WSRPUtils.toString(locale));
- }
- return localeNames;
- }
-
- private static List<String>
getWindowStateNamesFrom(Collection<WindowStateInfo> windowStates)
- {
- List<String> result = new ArrayList<String>(windowStates.size());
- for (WindowStateInfo windowStateInfo : windowStates)
- {
-
result.add(WSRPUtils.convertJSR168WindowStateNameToWSRPName(windowStateInfo.getWindowStateName()));
- }
- return result;
- }
-
- private static List<String> getModeNamesFrom(Collection<ModeInfo> modes)
- {
- List<String> result = new ArrayList<String>(modes.size());
- for (ModeInfo modeInfo : modes)
- {
-
result.add(WSRPUtils.convertJSR168PortletModeNameToWSRPName(modeInfo.getModeName()));
- }
- return result;
- }
-
- private static class ServiceDescriptionInfo
- {
- /** Empty service description: no registration properties, no offered portlets */
- private ServiceDescription noRegistrationNoPortletsServiceDescription;
- /** No registration properties, offered portles */
- private ServiceDescription noRegistrationPortletsServiceDescription;
- /** Registration properties, no offered portlets */
- private ServiceDescription registrationNoPortletsServiceDescription;
- /** Registration properties, offered portlets */
- private ServiceDescription registrationPortletsServiceDescription;
-
- private long lastGenerated;
- private Map<QName, EventDescription> eventDescriptions;
-
- private static final List<String> OPTIONS = new ArrayList<String>(5);
-
- static
- {
- OPTIONS.add(WSRP2Constants.OPTIONS_EVENTS);
- OPTIONS.add(WSRP2Constants.OPTIONS_IMPORT);
- OPTIONS.add(WSRP2Constants.OPTIONS_EXPORT);
- }
-
- private ServiceDescriptionInfo(WSRPProducerImpl producer)
- {
- noRegistrationNoPortletsServiceDescription =
WSRPTypeFactory.createServiceDescription(false);
-
noRegistrationNoPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
-
noRegistrationNoPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
-
noRegistrationNoPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
-
- noRegistrationPortletsServiceDescription =
WSRPTypeFactory.createServiceDescription(false);
-
noRegistrationPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
-
noRegistrationPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
- noRegistrationPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
-
- registrationNoPortletsServiceDescription =
WSRPTypeFactory.createServiceDescription(false);
-
registrationNoPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
-
registrationNoPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
- registrationNoPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
-
- registrationPortletsServiceDescription =
WSRPTypeFactory.createServiceDescription(false);
-
registrationPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
-
registrationPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
- registrationPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
- }
-
- private void updateRegistrationProperties(ProducerRegistrationRequirements
requirements)
- {
- long lastModified = requirements.getLastModified();
- if (lastModified > lastGenerated)
- {
- if (log.isDebugEnabled())
- {
- log.debug("Re-generating registration properties information for
service description.");
- }
-
- // do not create a ModelDescription if there is no registration properties
- Map<QName, RegistrationPropertyDescription> info =
requirements.getRegistrationProperties();
- ModelDescription registrationProperties = null;
- if (ParameterValidation.existsAndIsNotEmpty(info))
- {
- registrationProperties =
Utils.convertRegistrationPropertiesToModelDescription(info);
- }
-
registrationNoPortletsServiceDescription.setRegistrationPropertyDescription(registrationProperties);
-
registrationPortletsServiceDescription.setRegistrationPropertyDescription(registrationProperties);
-
- // update need to register
-
noRegistrationNoPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
-
noRegistrationPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
-
registrationNoPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
-
registrationPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
-
- lastGenerated = System.nanoTime();
- }
- }
-
- private void updatePortletDescriptions(Set<Portlet> portlets,
List<String> desiredLocales, Registration registration)
- {
- if (ParameterValidation.existsAndIsNotEmpty(portlets))
- {
- Collection<PortletDescription> offeredPortletDescriptions = new
ArrayList<PortletDescription>(portlets.size());
-
- // reset event descriptions as they will be repopulated when we build the
portlet descriptions
- eventDescriptions = new HashMap<QName,
EventDescription>(portlets.size());
-
- for (Portlet portlet : portlets)
- {
- PortletDescription desc = getPortletDescription(portlet, desiredLocales,
this);
- offeredPortletDescriptions.add(desc);
- }
-
- // events
- Collection<EventDescription> events = eventDescriptions.values();
- List<EventDescription> eventDescriptions =
registrationPortletsServiceDescription.getEventDescriptions();
- eventDescriptions.clear();
- eventDescriptions.addAll(events);
-
- eventDescriptions =
registrationNoPortletsServiceDescription.getEventDescriptions();
- eventDescriptions.clear();
- eventDescriptions.addAll(events);
-
- eventDescriptions =
noRegistrationPortletsServiceDescription.getEventDescriptions();
- eventDescriptions.clear();
- eventDescriptions.addAll(events);
-
- eventDescriptions =
noRegistrationNoPortletsServiceDescription.getEventDescriptions();
- eventDescriptions.clear();
- eventDescriptions.addAll(events);
-
- // portlets
- List<PortletDescription> offeredPortlets =
registrationPortletsServiceDescription.getOfferedPortlets();
- offeredPortlets.clear();
- offeredPortlets.addAll(offeredPortletDescriptions);
-
- offeredPortlets =
noRegistrationPortletsServiceDescription.getOfferedPortlets();
- offeredPortlets.clear();
- offeredPortlets.addAll(offeredPortletDescriptions);
- }
- }
-
- private ServiceDescription getServiceDescription(boolean
needsRegistrationProperties, boolean needsPortletDescriptions)
- {
- if (needsRegistrationProperties)
- {
- return needsPortletDescriptions ? registrationPortletsServiceDescription :
registrationNoPortletsServiceDescription;
- }
- else
- {
- return needsPortletDescriptions ? noRegistrationPortletsServiceDescription :
noRegistrationNoPortletsServiceDescription;
- }
- }
-
- public void addEventInfo(EventInfo info, List<String> desiredLocales)
- {
- QName name = info.getName();
- if (!eventDescriptions.containsKey(name))
- {
- EventDescription desc = WSRPTypeFactory.createEventDescription(name);
- desc.setDescription(Utils.convertToWSRPLocalizedString(info.getDescription(),
desiredLocales));
- desc.setLabel(Utils.convertToWSRPLocalizedString(info.getDisplayName(),
desiredLocales));
- Collection<QName> aliases = info.getAliases();
- if (ParameterValidation.existsAndIsNotEmpty(aliases))
- {
- desc.getAliases().addAll(aliases);
- }
- // todo: deal with type info...
- eventDescriptions.put(name, desc);
- }
- }
- }
-}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceHandler.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceHandler.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,43 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2009, 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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 8784 $
- * @since 2.4
- */
-class ServiceHandler
-{
- protected WSRPProducerImpl producer;
- protected static final Logger log = LoggerFactory.getLogger(ServiceHandler.class);
-
- ServiceHandler(WSRPProducerImpl producer)
- {
- this.producer = producer;
- }
-}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/UpdateNavigationalStateResponseProcessor.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/UpdateNavigationalStateResponseProcessor.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/UpdateNavigationalStateResponseProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,82 +0,0 @@
-/*
- * 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.util.ParameterValidation;
-import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
-import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
-import org.oasis.wsrp.v2.NavigationalContext;
-import org.oasis.wsrp.v2.PortletContext;
-import org.oasis.wsrp.v2.UpdateResponse;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision$
- */
-public abstract class UpdateNavigationalStateResponseProcessor extends RequestProcessor
-{
- public UpdateNavigationalStateResponseProcessor(WSRPProducerImpl producer)
- {
- super(producer);
- }
-
- protected String getNewStateOrNull(UpdateNavigationalStateResponse renderResult,
boolean forMode)
- {
- Object state = forMode ? renderResult.getMode() : renderResult.getWindowState();
- return state != null ? state.toString() : null;
- }
-
- protected UpdateResponse createUpdateResponse(UpdateNavigationalStateResponse
stateResponse)
- {
- UpdateResponse updateResponse = WSRPTypeFactory.createUpdateResponse();
-
updateResponse.setNewMode(WSRPUtils.convertJSR168PortletModeNameToWSRPName(getNewStateOrNull(stateResponse,
true)));
-
updateResponse.setNewWindowState(WSRPUtils.convertJSR168WindowStateNameToWSRPName(getNewStateOrNull(stateResponse,
false)));
- NavigationalContext navigationalContext =
WSRPTypeFactory.createNavigationalContextOrNull(
- stateResponse.getNavigationalState(),
- stateResponse.getPublicNavigationalStateUpdates()
- );
- updateResponse.setNavigationalContext(navigationalContext);
-
- // events
- List<UpdateNavigationalStateResponse.Event> events =
stateResponse.getEvents();
- if (ParameterValidation.existsAndIsNotEmpty(events))
- {
- for (UpdateNavigationalStateResponse.Event event : events)
- {
- updateResponse.getEvents().add(WSRPTypeFactory.createEvent(event.getName(),
event.getPayload()));
- }
- }
-
- // deal with implicit cloning and state modification
- if (instanceContext.wasModified())
- {
- PortletContext updatedPortletContext =
WSRPUtils.convertToWSRPPortletContext(instanceContext.getPortletContext());
- updateResponse.setPortletContext(updatedPortletContext);
- }
- return updateResponse;
- }
-}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/Utils.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/Utils.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/Utils.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -28,7 +28,9 @@
import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.registration.LocalizedString;
import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.oasis.wsrp.v2.ModelDescription;
+import org.oasis.wsrp.v2.OperationFailed;
import org.oasis.wsrp.v2.PropertyDescription;
import javax.xml.namespace.QName;
@@ -192,4 +194,11 @@
}
return null;
}
+
+ public static void throwOperationFaultOnSessionOperation() throws OperationFailed
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "JBoss
Portal's Producer" +
+ " manages sessions completely on the server side, passing or trying to
release sessionIDs is therefore an error.",
+ null);
+ }
}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPInstanceContext.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPInstanceContext.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPInstanceContext.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,104 +0,0 @@
-/*
- * 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.util.ParameterValidation;
-import org.gatein.pc.api.PortletContext;
-import org.gatein.pc.api.PortletStateType;
-import org.gatein.pc.api.StateEvent;
-import org.gatein.pc.api.StatefulPortletContext;
-import org.gatein.pc.api.spi.InstanceContext;
-import org.gatein.pc.api.state.AccessMode;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 8784 $
- * @since 2.6
- */
-class WSRPInstanceContext implements InstanceContext
-{
- private PortletContext context;
- private String instanceId;
- private final AccessMode accessMode;
- private boolean wasModified = false;
-
- public WSRPInstanceContext(PortletContext portletContext, AccessMode accessMode,
String instanceId)
- {
- ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "portlet
context");
- ParameterValidation.throwIllegalArgExceptionIfNull(accessMode,
"AccessMode");
-
- this.context = portletContext;
- this.accessMode = accessMode;
-
- if (instanceId != null && instanceId.length() > 0)
- {
- this.instanceId = instanceId;
- }
- else
- {
- this.instanceId = portletContext.getId();
- }
- }
-
- public String getId()
- {
- return instanceId;
- }
-
- public AccessMode getAccessMode()
- {
- return accessMode;
- }
-
- public void onStateEvent(StateEvent event)
- {
- PortletContext portletContext = event.getPortletContext();
- ParameterValidation.throwIllegalArgExceptionIfNull(portletContext,
"PortletContext");
- wasModified = true;
- context = portletContext;
- }
-
- public boolean wasModified()
- {
- return wasModified;
- }
-
- PortletContext getPortletContext()
- {
- return context;
- }
-
- public PortletStateType<?> getStateType()
- {
- if (context instanceof StatefulPortletContext)
- {
- StatefulPortletContext spc = (StatefulPortletContext)context;
- return spc.getType();
- }
- else
- {
- return PortletStateType.OPAQUE;
- }
- }
-}
Deleted:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPPortletInvocationContext.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPPortletInvocationContext.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPPortletInvocationContext.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,156 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
- * contributors as indicated by the @authors tag. See the
- * copyright.txt in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.gatein.wsrp.producer;
-
-import org.gatein.common.net.URLTools;
-import org.gatein.common.util.MarkupInfo;
-import org.gatein.pc.api.ContainerURL;
-import org.gatein.pc.api.URLFormat;
-import org.gatein.pc.api.invocation.PortletInvocation;
-import org.gatein.pc.api.spi.PortalContext;
-import org.gatein.pc.api.spi.PortletInvocationContext;
-import org.gatein.pc.api.spi.SecurityContext;
-import org.gatein.pc.api.spi.UserContext;
-import org.gatein.pc.api.spi.WindowContext;
-import org.gatein.pc.portlet.impl.spi.AbstractClientContext;
-import org.gatein.pc.portlet.impl.spi.AbstractPortletInvocationContext;
-import org.gatein.pc.portlet.impl.spi.AbstractServerContext;
-import org.gatein.wsrp.WSRPPortletURL;
-import org.gatein.wsrp.WSRPRewritingConstants;
-import org.gatein.wsrp.WSRPUtils;
-import org.gatein.wsrp.servlet.ServletAccess;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 13121 $
- */
-class WSRPPortletInvocationContext extends AbstractPortletInvocationContext implements
PortletInvocationContext
-{
- private SecurityContext securityContext;
- private PortalContext portalContext;
- private UserContext userContext;
- private WSRPInstanceContext instanceContext;
- private WindowContext windowContext;
-
- private static final String EQ = "=";
- private static final String AMP = "&";
- private static final String EQ_TRUE = "=true";
- private HttpServletRequest request;
- private HttpServletResponse response;
-
- public WSRPPortletInvocationContext(MarkupInfo markupInfo, SecurityContext
securityContext, PortalContext portalContext, UserContext userContext,
- WSRPInstanceContext instanceContext, WindowContext
windowContext)
- {
- super(markupInfo);
-
- this.securityContext = securityContext;
- this.portalContext = portalContext;
- this.userContext = userContext;
- this.instanceContext = instanceContext;
- this.windowContext = windowContext;
-
- request = ServletAccess.getRequest();
- response = ServletAccess.getResponse();
- }
-
- public HttpServletRequest getClientRequest()
- {
- return request;
- }
-
- public HttpServletResponse getClientResponse()
- {
- return response;
- }
-
- /** Override the default behavior in order to avoid to encode when it is producer
written URL. */
- public String encodeResourceURL(String url)
- {
- if (url != null &&
!url.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE))
- {
- // make root relative URLs absolute. Optimization: we don't recheck the
presence of the WSRP token.
- url = WSRPUtils.getAbsoluteURLFor(url, false,
URLTools.getServerAddressFrom(getClientRequest()));
-
- // properly encode the URL
- url = URLTools.encodeXWWWFormURL(url);
-
- // build the WSRP resource URL with rewrite tokens
- StringBuffer sb = new StringBuffer(url.length() * 2);
-
sb.append(WSRPRewritingConstants.BEGIN_WSRP_REWRITE).append(WSRPRewritingConstants.URL_TYPE_NAME)
- .append(EQ).append(WSRPRewritingConstants.URL_TYPE_RESOURCE).append(AMP)
- .append(WSRPRewritingConstants.RESOURCE_URL).append(EQ).append(url)
- .append(AMP).append(WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE)
- .append(EQ_TRUE).append(WSRPRewritingConstants.END_WSRP_REWRITE);
- return sb.toString();
- }
-
- return url;
- }
-
- /**
- * <p>URL to be re-written are of the form:
<code>wsrp_rewrite?wsrp-urlType=value&amp;name1=value1&amp;name2=value2
- * .../wsrp_rewrite</code> </p> <ul>Examples: <li>Load a
resource
http://test.com/images/test.gif: <br/>
- *
<code>wsrp_rewrite?wsrp-urlType=resource&amp;wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&amp;wsrp-requiresRewrite=true/wsrp_rewrite</code></li>
- * <li>Declare a secure interaction back to the Portlet:<br/>
<code>wsrp_rewrite?wsrp-urlType=blockingAction&amp;wsrp-secureURL=true&amp;wsrp-navigationalState=a8h4K5JD9&amp;wsrp-interactionState=fg4h923mdk/wsrp_rewrite</code></li>
- * <li>Request the Consumer render the Portlet in a different mode and window
state:
- *
<code>wsrp_rewrite?wsrp-urlType=render&amp;wsrp-mode=help&amp;wsrp-windowState=maximized/wsrp_rewrite</code></li>
- * </ul>
- *
- * @param containerURL
- * @param urlFormat
- * @return
- */
- public String renderURL(ContainerURL containerURL, URLFormat urlFormat)
- {
- if (containerURL != null)
- {
- Boolean wantSecureBool = urlFormat.getWantSecure();
- boolean wantSecure = (wantSecureBool != null ? wantSecureBool : false);
- WSRPPortletURL url = WSRPPortletURL.create(containerURL, wantSecure);
- return url.toString();
- }
- return null;
- }
-
- public void contextualize(PortletInvocation invocation)
- {
- invocation.setClientContext(new AbstractClientContext(request));
- invocation.setServerContext(new AbstractServerContext(request, response));
-
- invocation.setSecurityContext(securityContext);
- invocation.setInstanceContext(instanceContext);
- invocation.setWindowContext(windowContext);
- invocation.setPortalContext(portalContext);
- invocation.setUserContext(userContext);
- }
-
- WindowContext getWindowContext()
- {
- return windowContext;
- }
-}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java 2010-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -36,6 +36,10 @@
import org.gatein.wsrp.producer.config.ProducerConfiguration;
import org.gatein.wsrp.producer.config.ProducerConfigurationService;
import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.producer.handlers.MarkupHandler;
+import org.gatein.wsrp.producer.handlers.PortletManagementHandler;
+import org.gatein.wsrp.producer.handlers.RegistrationHandler;
+import org.gatein.wsrp.producer.handlers.ServiceDescriptionHandler;
import org.gatein.wsrp.producer.v2.WSRP2Producer;
import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
import org.oasis.wsrp.v2.AccessDenied;
@@ -47,9 +51,6 @@
import org.oasis.wsrp.v2.DestroyPortlets;
import org.oasis.wsrp.v2.DestroyPortletsResponse;
import org.oasis.wsrp.v2.ExportByValueNotSupported;
-import org.oasis.wsrp.v2.ExportPortlets;
-import org.oasis.wsrp.v2.ExportPortletsResponse;
-import org.oasis.wsrp.v2.ExportByValueNotSupported;
import org.oasis.wsrp.v2.ExportNoLongerValid;
import org.oasis.wsrp.v2.ExportPortlets;
import org.oasis.wsrp.v2.ExportPortletsResponse;
@@ -146,8 +147,8 @@
private ProducerConfigurationService configurationService; //todo: make sure it's
multi-thread safe
/** export manager */
- private ExportManager exportManager;
-
+ private ExportManager exportManager;
+
private boolean started = false;
// On-demand class holder Singleton pattern (multi-thread safe)
@@ -175,7 +176,7 @@
portletManagementHandler = new PortletManagementHandler(this);
}
- ProducerRegistrationRequirements getProducerRegistrationRequirements()
+ public ProducerRegistrationRequirements getProducerRegistrationRequirements()
{
return getProducerConfiguration().getRegistrationRequirements();
}
@@ -357,12 +358,12 @@
{
this.exportManager = exportManger;
}
-
+
public ExportManager getExportManager()
{
return exportManager;
}
-
+
public synchronized void start()
{
if (!started)
@@ -420,7 +421,7 @@
this.invoker = invoker;
}
- Portlet getPortletWith(org.gatein.pc.api.PortletContext portletContext, Registration
registration) throws InvalidHandle, PortletInvokerException
+ public Portlet getPortletWith(org.gatein.pc.api.PortletContext portletContext,
Registration registration) throws InvalidHandle, PortletInvokerException
{
Portlet portlet;
try
@@ -445,7 +446,7 @@
return portlet;
}
- Set<Portlet> getRemotablePortlets() throws PortletInvokerException
+ public Set<Portlet> getRemotablePortlets() throws PortletInvokerException
{
log.debug("Retrieving remotable portlets");
Set<Portlet> allPortlets = invoker.getPortlets();
@@ -477,7 +478,7 @@
return serviceDescriptionHandler.getPortletDescription(portlet, locales);
}
- Registration getRegistrationOrFailIfInvalid(RegistrationContext registrationContext)
throws InvalidRegistration, OperationFailed
+ public Registration getRegistrationOrFailIfInvalid(RegistrationContext
registrationContext) throws InvalidRegistration, OperationFailed
{
Registration registration =
registrationHandler.getRegistrationFrom(registrationContext);
registrationHandler.isRegistrationValid(registration, true);
Deleted:
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-08-11
07:30:58 UTC (rev 3803)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPRequestContext.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -1,262 +0,0 @@
-/*
- * 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.apache.commons.fileupload.FileUpload;
-import org.gatein.common.util.ParameterMap;
-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;
-import javax.mail.internet.InternetHeaders;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimeMultipart;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 10337 $
- */
-abstract class WSRPRequestContext implements RequestContext,
org.apache.commons.fileupload.RequestContext
-{
- protected String characterEncoding;
-
- protected WSRPRequestContext(String characterEncoding)
- {
- this.characterEncoding = characterEncoding;
- }
-
- public String getCharacterEncoding()
- {
- return characterEncoding;
- }
-
- public int getContentLength()
- {
- throw new UnsupportedOperationException("Not currently supported");
- }
-
- public BufferedReader getReader() throws IOException
- {
- throw new UnsupportedOperationException("Not currently supported");
- }
-
- public InputStream getInputStream() throws IOException
- {
- throw new UnsupportedOperationException("Not currently supported");
- }
-
- public abstract ParameterMap getForm();
-
- static class WSRPSimpleRequestContext extends WSRPRequestContext
- {
- private ParameterMap formParameters;
- private String contentType;
-
- protected WSRPSimpleRequestContext(String characterEncoding, String contentType,
List<NamedString> formParams)
- {
- super(characterEncoding);
- this.contentType = contentType;
-
- if (formParams != null && !formParams.isEmpty())
- {
- Map<String, String[]> params = new HashMap<String,
String[]>(formParams.size());
- for (NamedString formParam : formParams)
- {
- String paramName = formParam.getName();
- String paramValue = formParam.getValue();
- if (params.containsKey(paramName))
- {
- // handle multi-valued parameters...
- String[] oldValues = 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});
- }
- formParameters = new ParameterMap(params);
- }
- }
- else
- {
- formParameters = new ParameterMap();
- }
-
- }
-
- public ParameterMap getForm()
- {
- return formParameters;
- }
-
- public String getContentType()
- {
- return contentType;
- }
- }
-
- static class WSRPMultiRequestContext extends WSRPRequestContext
- {
- private byte[] content;
- private boolean usingStream;
- private boolean usingReader;
- private String contentType;
-
- protected WSRPMultiRequestContext(String characterEncoding, List<NamedString>
formParams, List<UploadContext> uploadContexts) throws IOException,
MessagingException
- {
- super(characterEncoding);
-
- MimeMultipart parts = new MimeMultipart();
- if (uploadContexts != null && !uploadContexts.isEmpty())
- {
- for (UploadContext uploadContext : uploadContexts)
- {
- InternetHeaders headers = new InternetHeaders();
- headers.addHeader(FileUpload.CONTENT_TYPE, uploadContext.getMimeType());
-
- List<NamedString> attributes = uploadContext.getMimeAttributes();
- if (attributes != null && !attributes.isEmpty())
- {
- for (NamedString attribute : attributes)
- {
- headers.addHeader(attribute.getName(), attribute.getValue());
- }
- }
-
- MimeBodyPart mimeBodyPart = new MimeBodyPart(headers,
uploadContext.getUploadData());
- parts.addBodyPart(mimeBodyPart);
- }
- }
-
- final String paramContentDispositionHeader = FileUpload.FORM_DATA + ";
name=\"";
- if (formParams != null)
- {
- for (NamedString formParam : formParams)
- {
- InternetHeaders headers = new InternetHeaders();
-
- StringBuffer paramContentDisposition = new
StringBuffer(paramContentDispositionHeader);
-
paramContentDisposition.append(formParam.getName()).append("\"");
-
- headers.addHeader(FileUpload.CONTENT_DISPOSITION,
paramContentDisposition.toString());
-
- MimeBodyPart mimeBodyPart = new MimeBodyPart(headers,
formParam.getValue().getBytes());
- parts.addBodyPart(mimeBodyPart);
- }
- }
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- parts.writeTo(baos);
- content = baos.toByteArray();
- contentType = parts.getContentType();
- }
-
- public ParameterMap getForm()
- {
- return new ParameterMap();
- }
-
- public String getContentType()
- {
- return contentType;
- }
-
- public int getContentLength()
- {
- return content.length;
- }
-
- public BufferedReader getReader() throws IOException
- {
- if (usingStream)
- {
- throw new IllegalStateException("getInputStream has already been called
on this ActionContext!");
- }
- usingReader = true;
- return new BufferedReader(new InputStreamReader(getInputStreamFromContent()));
- }
-
- public InputStream getInputStream() throws IOException
- {
- if (usingReader)
- {
- throw new IllegalStateException("getReader has already been called on
this ActionContext!");
- }
- usingStream = true;
- return getInputStreamFromContent();
- }
-
-
- private InputStream getInputStreamFromContent()
- {
- return new ByteArrayInputStream(content);
- }
- }
-
- public static WSRPRequestContext createRequestContext(MarkupRequest markupRequest,
InteractionParams interactionParams)
- {
- 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
- {
- return new WSRPMultiRequestContext(markupRequest.getCharacterSet(),
formParams, uploadContexts);
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("Invalid upload contexts", e);
- }
- }
- else
- {
- return new WSRPSimpleRequestContext(markupRequest.getCharacterSet(),
markupRequest.getMediaType(), formParams);
-
- }
- }
-}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/MarkupHandler.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupHandler.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/MarkupHandler.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/MarkupHandler.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,264 @@
+/*
+ * 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.handlers;
+
+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;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
+import org.gatein.pc.portlet.state.producer.PortletStateChangeRequiredException;
+import org.gatein.wsrp.producer.MarkupInterface;
+import org.gatein.wsrp.producer.Utils;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.producer.handlers.processors.ProcessorFactory;
+import org.gatein.wsrp.producer.handlers.processors.RequestProcessor;
+import org.gatein.wsrp.servlet.ServletAccess;
+import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
+import org.oasis.wsrp.v2.AccessDenied;
+import org.oasis.wsrp.v2.BlockingInteractionResponse;
+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.HandleEventsResponse;
+import org.oasis.wsrp.v2.InconsistentParameters;
+import org.oasis.wsrp.v2.InitCookie;
+import org.oasis.wsrp.v2.InteractionParams;
+import org.oasis.wsrp.v2.InvalidCookie;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.InvalidSession;
+import org.oasis.wsrp.v2.InvalidUserCategory;
+import org.oasis.wsrp.v2.MarkupResponse;
+import org.oasis.wsrp.v2.MissingParameters;
+import org.oasis.wsrp.v2.ModifyRegistrationRequired;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationNotSupported;
+import org.oasis.wsrp.v2.PerformBlockingInteraction;
+import org.oasis.wsrp.v2.PortletStateChangeRequired;
+import org.oasis.wsrp.v2.ReleaseSessions;
+import org.oasis.wsrp.v2.ResourceResponse;
+import org.oasis.wsrp.v2.ResourceSuspended;
+import org.oasis.wsrp.v2.UnsupportedLocale;
+import org.oasis.wsrp.v2.UnsupportedMimeType;
+import org.oasis.wsrp.v2.UnsupportedMode;
+import org.oasis.wsrp.v2.UnsupportedWindowState;
+
+import javax.portlet.PortletModeException;
+import javax.portlet.WindowStateException;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 10090 $
+ * @since 2.4
+ */
+public class MarkupHandler extends ServiceHandler implements MarkupInterface
+{
+ public static final String PBI = "PerformBlockingInteraction";
+ public static final String GET_MARKUP = "GetMarkup";
+ public static final String GET_RESOURCE = "GetResource";
+ public static final String HANDLE_EVENTS = "HandleEvents";
+
+ public MarkupHandler(WSRPProducerImpl producer)
+ {
+ super(producer);
+ }
+
+ // Markup implementation
********************************************************************************************
+
+
+ public MarkupResponse getMarkup(GetMarkup getMarkup)
+ throws AccessDenied, InconsistentParameters, InvalidCookie, InvalidHandle,
InvalidRegistration, InvalidSession,
+ InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, ResourceSuspended,
+ UnsupportedLocale, UnsupportedMimeType, UnsupportedMode, UnsupportedWindowState
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getMarkup, GET_MARKUP);
+
+ RequestProcessor requestProcessor = ProcessorFactory.getProcessorFor(producer,
getMarkup);
+
+ String handle = requestProcessor.getPortletContext().getPortletHandle();
+ PortletInvocationResponse response;
+ try
+ {
+ log.debug("RenderInvocation on portlet '" + handle +
"'");
+ response =
producer.getPortletInvoker().invoke(requestProcessor.getInvocation());
+ log.debug("RenderInvocation done");
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not render portlet '" + handle + "'", e);
+ }
+
+ checkForError(response);
+
+ return (MarkupResponse)requestProcessor.processResponse(response);
+ }
+
+ public ResourceResponse getResource(GetResource getResource)
+ throws AccessDenied, InconsistentParameters, InvalidCookie, InvalidHandle,
InvalidRegistration, InvalidSession,
+ InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, OperationNotSupported,
+ ResourceSuspended, UnsupportedLocale, UnsupportedMimeType, UnsupportedMode,
UnsupportedWindowState
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getResource,
GET_RESOURCE);
+
+ RequestProcessor requestProcessor = ProcessorFactory.getProcessorFor(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 AccessDenied, InconsistentParameters, InvalidCookie, InvalidHandle,
InvalidRegistration, InvalidSession,
+ InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, PortletStateChangeRequired,
+ ResourceSuspended, UnsupportedLocale, UnsupportedMimeType, UnsupportedMode,
UnsupportedWindowState
+ {
+
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(performBlockingInteraction,
PBI);
+ final InteractionParams interactionParams =
performBlockingInteraction.getInteractionParams();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(interactionParams,
"InteractionParams", PBI);
+
+ RequestProcessor requestProcessor = ProcessorFactory.getProcessorFor(producer,
performBlockingInteraction);
+
+ PortletInvocationResponse response;
+ String handle = requestProcessor.getPortletContext().getPortletHandle();
+ try
+ {
+ log.debug("ActionInvocation on portlet '" + handle +
"'");
+ response =
producer.getPortletInvoker().invoke(requestProcessor.getInvocation());
+ log.debug("ActionInvocation done");
+ }
+ catch (PortletStateChangeRequiredException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(PortletStateChangeRequired.class,
e.getLocalizedMessage(), e);
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not perform action on portlet '" + handle + "'", e);
+ }
+
+ checkForError(response);
+
+ return (BlockingInteractionResponse)requestProcessor.processResponse(response);
+ }
+
+ public List<Extension> releaseSessions(ReleaseSessions releaseSessions)
+ throws AccessDenied, InvalidRegistration, MissingParameters,
ModifyRegistrationRequired, OperationFailed,
+ OperationNotSupported, ResourceSuspended
+ {
+ // our producer never sends session ids so a Consumer trying to release sessions is
an error condition
+ Utils.throwOperationFaultOnSessionOperation();
+ return null;
+ }
+
+ public List<Extension> initCookie(InitCookie initCookie)
+ throws AccessDenied, InvalidRegistration, ModifyRegistrationRequired,
OperationFailed, OperationNotSupported,
+ ResourceSuspended
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(initCookie,
"InitCookie");
+ producer.getRegistrationOrFailIfInvalid(initCookie.getRegistrationContext());
+
+ // Force HTTP session creation... this is required for BEA Weblogic version <
9.2.
+ // See
http://jira.jboss.com/jira/browse/JBPORTAL-1220
+ String sessionId = ServletAccess.getRequest().getSession().getId();
+ log.debug("Got init cookie operation, created a session with id " +
sessionId);
+
+ return Collections.emptyList();
+ }
+
+ public HandleEventsResponse handleEvents(HandleEvents handleEvents)
+ throws AccessDenied, InconsistentParameters, InvalidCookie, InvalidHandle,
InvalidRegistration, InvalidSession,
+ InvalidUserCategory, MissingParameters, ModifyRegistrationRequired,
OperationFailed, OperationNotSupported,
+ PortletStateChangeRequired, ResourceSuspended, UnsupportedLocale,
UnsupportedMimeType, UnsupportedMode,
+ UnsupportedWindowState
+ {
+ RequestProcessor requestProcessor = ProcessorFactory.getProcessorFor(producer,
handleEvents);
+
+ PortletInvocationResponse response;
+ String handle = requestProcessor.getPortletContext().getPortletHandle();
+
+ try
+ {
+ log.debug("EventInvocation on portlet '" + handle +
"'");
+ response =
producer.getPortletInvoker().invoke(requestProcessor.getInvocation());
+ log.debug("EventInvocation done");
+ }
+ catch (PortletStateChangeRequiredException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(PortletStateChangeRequired.class,
e.getLocalizedMessage(), e);
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not handle event on portlet '" + handle + "'", e);
+ }
+
+ checkForError(response);
+
+ return (HandleEventsResponse)requestProcessor.processResponse(response);
+ }
+
+ private void checkForError(PortletInvocationResponse response)
+ throws UnsupportedMode, OperationFailed, UnsupportedWindowState
+ {
+ if (response instanceof ErrorResponse)
+ {
+ ErrorResponse errorResult = (ErrorResponse)response;
+ Throwable cause = errorResult.getCause();
+ if (cause instanceof PortletModeException)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(UnsupportedMode.class,
"Unsupported mode: " + ((PortletModeException)cause).getMode(), null);
+ }
+ if (cause instanceof WindowStateException)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(UnsupportedWindowState.class,
"Unsupported window state: " + ((WindowStateException)cause).getState(), null);
+ }
+ // todo: deal with other exceptions
+
+ // we're not sure what happened so throw an OperationFailedFault
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
errorResult.getMessage(), cause);
+
+ }
+ 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);
+ }
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,805 @@
+/*
+ * 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.handlers;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+import org.gatein.common.NotYetImplemented;
+import org.gatein.common.i18n.LocalizedString;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportPortletData;
+import org.gatein.pc.api.InvalidPortletIdException;
+import org.gatein.pc.api.NoSuchPortletException;
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.PortletStateType;
+import org.gatein.pc.api.info.PortletInfo;
+import org.gatein.pc.api.info.PreferenceInfo;
+import org.gatein.pc.api.info.PreferencesInfo;
+import org.gatein.pc.api.state.DestroyCloneFailure;
+import org.gatein.pc.api.state.PropertyChange;
+import org.gatein.pc.api.state.PropertyMap;
+import org.gatein.registration.Registration;
+import org.gatein.registration.RegistrationLocal;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPExceptionFactory;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.producer.PortletManagementInterface;
+import org.gatein.wsrp.producer.Utils;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.spec.v2.ErrorCodes;
+import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
+import org.oasis.wsrp.v2.AccessDenied;
+import org.oasis.wsrp.v2.ClonePortlet;
+import org.oasis.wsrp.v2.CopyPortlets;
+import org.oasis.wsrp.v2.CopyPortletsResponse;
+import org.oasis.wsrp.v2.DestroyPortlets;
+import org.oasis.wsrp.v2.DestroyPortletsResponse;
+import org.oasis.wsrp.v2.ExportByValueNotSupported;
+import org.oasis.wsrp.v2.ExportPortlets;
+import org.oasis.wsrp.v2.ExportPortletsResponse;
+import org.oasis.wsrp.v2.ExportedPortlet;
+import org.oasis.wsrp.v2.Extension;
+import org.oasis.wsrp.v2.FailedPortlets;
+import org.oasis.wsrp.v2.GetPortletDescription;
+import org.oasis.wsrp.v2.GetPortletProperties;
+import org.oasis.wsrp.v2.GetPortletPropertyDescription;
+import org.oasis.wsrp.v2.GetPortletsLifetime;
+import org.oasis.wsrp.v2.GetPortletsLifetimeResponse;
+import org.oasis.wsrp.v2.ImportPortlet;
+import org.oasis.wsrp.v2.ImportPortlets;
+import org.oasis.wsrp.v2.ImportPortletsFailed;
+import org.oasis.wsrp.v2.ImportPortletsResponse;
+import org.oasis.wsrp.v2.ImportedPortlet;
+import org.oasis.wsrp.v2.InconsistentParameters;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.InvalidUserCategory;
+import org.oasis.wsrp.v2.Lifetime;
+import org.oasis.wsrp.v2.MissingParameters;
+import org.oasis.wsrp.v2.ModifyRegistrationRequired;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationFailedFault;
+import org.oasis.wsrp.v2.OperationNotSupported;
+import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.PortletDescription;
+import org.oasis.wsrp.v2.PortletDescriptionResponse;
+import org.oasis.wsrp.v2.PortletPropertyDescriptionResponse;
+import org.oasis.wsrp.v2.Property;
+import org.oasis.wsrp.v2.PropertyDescription;
+import org.oasis.wsrp.v2.PropertyList;
+import org.oasis.wsrp.v2.ReleaseExport;
+import org.oasis.wsrp.v2.ResetProperty;
+import org.oasis.wsrp.v2.ResourceList;
+import org.oasis.wsrp.v2.ResourceSuspended;
+import org.oasis.wsrp.v2.ReturnAny;
+import org.oasis.wsrp.v2.SetExportLifetime;
+import org.oasis.wsrp.v2.SetPortletProperties;
+import org.oasis.wsrp.v2.SetPortletsLifetime;
+import org.oasis.wsrp.v2.SetPortletsLifetimeResponse;
+import org.oasis.wsrp.v2.UserContext;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+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: 11147 $
+ * @since 2.4
+ */
+public class PortletManagementHandler extends ServiceHandler implements
PortletManagementInterface
+{
+ private static final String GET_PORTLET_PROPERTY_DESCRIPTION =
"GetPortletPropertyDescription";
+ private static final String GET_PORTLET_PROPERTIES =
"GetPortletProperties";
+ private static final String PORTLET_CONTEXT = "PortletContext";
+ private static final String GET_PORTLET_DESCRIPTION =
"GetPortletDescription";
+
+ private static final Logger log =
LoggerFactory.getLogger(PortletManagementHandler.class);
+
+ public PortletManagementHandler(WSRPProducerImpl producer)
+ {
+ super(producer);
+ }
+
+ public PortletDescriptionResponse getPortletDescription(GetPortletDescription
getPortletDescription)
+ throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
+ MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getPortletDescription,
GET_PORTLET_DESCRIPTION);
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(getPortletDescription.getRegistrationContext());
+
+ PortletContext portletContext = getPortletDescription.getPortletContext();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext,
PORTLET_CONTEXT, GET_PORTLET_DESCRIPTION);
+
+ UserContext userContext = getPortletDescription.getUserContext();
+ checkUserAuthorization(userContext);
+
+ // RegistrationLocal.setRegistration is called further down the invocation in
ServiceDescriptionHandler.getPortletDescription
+ PortletDescription description = producer.getPortletDescription(portletContext,
getPortletDescription.getDesiredLocales(), registration);
+ return WSRPTypeFactory.createPortletDescriptionResponse(description);
+ }
+
+ public PortletPropertyDescriptionResponse
getPortletPropertyDescription(GetPortletPropertyDescription
getPortletPropertyDescription)
+ throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
+ MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
+ {
+
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getPortletPropertyDescription,
GET_PORTLET_PROPERTY_DESCRIPTION);
+
+ PortletContext portletContext = getPortletPropertyDescription.getPortletContext();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext,
PORTLET_CONTEXT, GET_PORTLET_PROPERTY_DESCRIPTION);
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(getPortletPropertyDescription.getRegistrationContext());
+
+ UserContext userContext = getPortletPropertyDescription.getUserContext();
+ checkUserAuthorization(userContext);
+
+ List<String> desiredLocales =
getPortletPropertyDescription.getDesiredLocales();
+ Portlet portlet = getPortletFrom(portletContext, registration);
+ PortletInfo info = portlet.getInfo();
+ PreferencesInfo prefsInfo = info.getPreferences();
+
+ List<PropertyDescription> descs = Collections.emptyList();
+ if (prefsInfo != null)
+ {
+ Set keySet = prefsInfo.getKeys();
+ descs = new ArrayList<PropertyDescription>(keySet.size());
+ for (Object key : keySet)
+ {
+ PreferenceInfo prefInfo = prefsInfo.getPreference((String)key);
+
+ // WSRP Spec 8.7: return only the portion of the Portlet's persistent
state the user is allowed to modify
+ // if read only status is not determined, we consider it as being read-only
to be safe
+ Boolean readOnly = prefInfo.isReadOnly();
+ if (readOnly != null && !readOnly)
+ {
+ //todo: check what we should use key
+ //todo: right now we only support String properties
+ PropertyDescription desc =
WSRPTypeFactory.createPropertyDescription(prefInfo.getKey(), WSRPConstants.XSD_STRING);
+
desc.setLabel(Utils.convertToWSRPLocalizedString(prefInfo.getDisplayName(),
desiredLocales));
+ desc.setHint(Utils.convertToWSRPLocalizedString(prefInfo.getDescription(),
desiredLocales));
+ descs.add(desc);
+ }
+ }
+ }
+
+ return WSRPTypeFactory.createPortletPropertyDescriptionResponse(descs);
+ }
+
+ public PortletContext clonePortlet(ClonePortlet clonePortlet)
+ throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
+ MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(clonePortlet,
"ClonePortlet");
+
+ PortletContext portletContext = clonePortlet.getPortletContext();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext,
"PortletContext", "ClonePortlet");
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(clonePortlet.getRegistrationContext());
+
+ UserContext userContext = clonePortlet.getUserContext();
+ checkUserAuthorization(userContext);
+
+ org.gatein.pc.api.PortletContext portalPC =
WSRPUtils.convertToPortalPortletContext(portletContext);
+ try
+ {
+ RegistrationLocal.setRegistration(registration);
+ org.gatein.pc.api.PortletContext response =
producer.getPortletInvoker().createClone(PortletStateType.OPAQUE, portalPC);
+ return WSRPUtils.convertToWSRPPortletContext(response);
+ }
+ catch (NoSuchPortletException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(InvalidHandle.class, "Failed
to create clone for portlet '" + portletContext.getPortletHandle(), e);
+ }
+ catch (InvalidPortletIdException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
"Failed to create clone for portlet '" + portletContext.getPortletHandle(),
e);
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Failed
to create clone for portlet '" + portletContext.getPortletHandle(), e);
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+
+ public DestroyPortletsResponse destroyPortlets(DestroyPortlets destroyPortlets)
+ throws InconsistentParameters, InvalidRegistration, MissingParameters,
ModifyRegistrationRequired,
+ OperationFailed, OperationNotSupported, ResourceSuspended
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(destroyPortlets,
"DestroyPortlets");
+
+ List<String> handles = destroyPortlets.getPortletHandles();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(handles, "portlet
handles to be destroyed", "DestroyPortlets");
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(destroyPortlets.getRegistrationContext());
+
+ List<org.gatein.pc.api.PortletContext> portletContexts = new
ArrayList<org.gatein.pc.api.PortletContext>(handles.size());
+ for (String handle : handles)
+ {
+
portletContexts.add(org.gatein.pc.api.PortletContext.createPortletContext(handle));
+ }
+
+ try
+ {
+ RegistrationLocal.setRegistration(registration);
+ List<DestroyCloneFailure> failuresList =
producer.getPortletInvoker().destroyClones(portletContexts);
+ int failuresNumber = failuresList.size();
+ List<FailedPortlets> failedPortlets;
+ if (failuresNumber > 0)
+ {
+ // for each reason of failure, record the associated portlet handles,
expecting one portlet handle per message
+ Multimap<String, String> reasonToHandles =
HashMultimap.create(failuresNumber, 1);
+ for (DestroyCloneFailure failure : failuresList)
+ {
+ reasonToHandles.put(failure.getMessage(), failure.getPortletId());
+ }
+
+ // create a FailedPortlets object for each reason
+ failedPortlets = new
ArrayList<FailedPortlets>(reasonToHandles.size());
+ for (String reason : reasonToHandles.keys())
+ {
+
failedPortlets.add(WSRPTypeFactory.createFailedPortlets(reasonToHandles.get(reason),
ErrorCodes.Codes.OPERATIONFAILED, reason));
+ }
+ }
+ else
+ {
+ failedPortlets = null;
+ }
+
+ return WSRPTypeFactory.createDestroyPortletsResponse(failedPortlets);
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Failed
to destroy clones", e);
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+
+ public GetPortletsLifetimeResponse getPortletsLifetime(GetPortletsLifetime
getPortletsLifetime)
+ throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
ModifyRegistrationRequired,
+ OperationFailed, OperationNotSupported, ResourceSuspended
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class,
"Lifetime operations are not currently supported.", null);
+ }
+
+ public SetPortletsLifetimeResponse setPortletsLifetime(SetPortletsLifetime
setPortletsLifetime)
+ throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
ModifyRegistrationRequired,
+ OperationFailed, OperationNotSupported, ResourceSuspended
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class,
"Lifetime operations are not currently supported.", null);
+ }
+
+ public CopyPortletsResponse copyPortlets(CopyPortlets copyPortlets)
+ throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
+ MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
+ {
+ throw new NotYetImplemented();
+ }
+
+ public PortletContext setPortletProperties(SetPortletProperties setPortletProperties)
+ throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
+ MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(setPortletProperties,
"SetPortletProperties");
+
+ PortletContext portletContext = setPortletProperties.getPortletContext();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext,
"PortletContext", "SetPortletProperties");
+
+ PropertyList propertyList = setPortletProperties.getPropertyList();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(propertyList,
"PropertyList", "SetPortletProperties");
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(setPortletProperties.getRegistrationContext());
+
+ checkUserAuthorization(setPortletProperties.getUserContext());
+
+ List<Property> properties = propertyList.getProperties();
+ List<ResetProperty> resetProperties = propertyList.getResetProperties();
+ int changesCount = 0;
+ if (properties != null)
+ {
+ changesCount += properties.size();
+ }
+ if (resetProperties != null)
+ {
+ changesCount += resetProperties.size();
+ }
+
+ if (changesCount > 0)
+ {
+ List<PropertyChange> changes = new
ArrayList<PropertyChange>(changesCount);
+
+ if (properties != null)
+ {
+ for (Property property : properties)
+ {
+ String value = property.getStringValue();
+
+ // todo: deal with XML values...
+ // List<Object> values = property.getAny();
+ // todo: deal with language?
+ // String lang = property.getLang();
+
+ changes.add(PropertyChange.newUpdate(property.getName().toString(),
value));
+ }
+ }
+
+ if (resetProperties != null)
+ {
+ for (ResetProperty resetProperty : resetProperties)
+ {
+ changes.add(PropertyChange.newReset(resetProperty.getName().toString()));
+ }
+ }
+
+ try
+ {
+ RegistrationLocal.setRegistration(registration);
+ org.gatein.pc.api.PortletContext resultContext =
+
producer.getPortletInvoker().setProperties(WSRPUtils.convertToPortalPortletContext(portletContext),
+ changes.toArray(new PropertyChange[changes.size()]));
+ return WSRPUtils.convertToWSRPPortletContext(resultContext);
+ }
+ catch (NoSuchPortletException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(InvalidHandle.class,
"Failed to set properties for portlet '" + portletContext.getPortletHandle()
+ "'", e);
+ }
+ catch (InvalidPortletIdException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
"Failed to set properties for portlet '" + portletContext.getPortletHandle()
+ "'", e);
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Failed to set properties for portlet '" + portletContext.getPortletHandle()
+ "'", e);
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+
+ return portletContext;
+ }
+
+ public PropertyList getPortletProperties(GetPortletProperties getPortletProperties)
+ throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration,
InvalidUserCategory,
+ MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(getPortletProperties,
GET_PORTLET_PROPERTIES);
+
+ PortletContext portletContext = getPortletProperties.getPortletContext();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext,
PORTLET_CONTEXT, GET_PORTLET_PROPERTIES);
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(getPortletProperties.getRegistrationContext());
+
+ UserContext userContext = getPortletProperties.getUserContext();
+ checkUserAuthorization(userContext);
+
+ List<String> names = getPortletProperties.getNames();
+ Set<String> keys = new HashSet<String>(names);
+
+ try
+ {
+ PropertyMap properties;
+ org.gatein.pc.api.PortletContext jbpContext =
WSRPUtils.convertToPortalPortletContext(portletContext);
+
+ RegistrationLocal.setRegistration(registration);
+ if (keys != null)
+ {
+ properties = producer.getPortletInvoker().getProperties(jbpContext, keys);
+ }
+ else
+ {
+ properties = producer.getPortletInvoker().getProperties(jbpContext);
+ }
+
+ //todo: we need to check that the user can actually modify the properties
+ Portlet portlet = getPortletFrom(portletContext, registration);
+ PortletInfo info = portlet.getInfo();
+
+ PropertyList result = WSRPTypeFactory.createPropertyList();
+ int propertyNb = properties.size();
+
+ if (propertyNb > 0)
+ {
+ PreferenceInfo prefInfo;
+ String key;
+ List<String> values;
+ LocalizedString displayName;
+
+ for (Map.Entry<String, List<String>> entry :
properties.entrySet())
+ {
+ key = entry.getKey();
+ values = entry.getValue();
+ prefInfo = info.getPreferences().getPreference(key);
+ displayName = prefInfo.getDisplayName();
+ String lang = WSRPUtils.toString(displayName.getDefaultLocale());
+
+ // todo: support multi-valued properties
+ if (values.size() != 1)
+ {
+ throw new UnsupportedOperationException("Currently doesn't
support multi-valued properties!");
+ }
+ result.getProperties().add(WSRPTypeFactory.createProperty(key, lang,
values.get(0))); //todo: check what we should use key
+ }
+ }
+
+ return result;
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(InvalidHandle.class, "Could
not retrieve properties for portlet '" + portletContext + "'", e);
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+
+ public ExportPortletsResponse exportPortlets(ExportPortlets exportPortlets) throws
AccessDenied,
+ ExportByValueNotSupported, InconsistentParameters, InvalidHandle,
InvalidRegistration, InvalidUserCategory,
+ MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
+ {
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(exportPortlets,
"ExportPortlets", "ExportPortlets");
+
+ List<PortletContext> portletContexts = exportPortlets.getPortletContext();
+ if (portletContexts == null || portletContexts.isEmpty())
+ {
+ throw WSRP2ExceptionFactory.createWSException(MissingParameters.class,
"Missing required portletContext in ExportPortlets.", null);
+ }
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(exportPortlets.getRegistrationContext());
+
+ UserContext userContext = exportPortlets.getUserContext();
+ checkUserAuthorization(userContext);
+
+ boolean exportByValueRequired;
+ if (exportPortlets.isExportByValueRequired() != null)
+ {
+ exportByValueRequired = exportPortlets.isExportByValueRequired();
+ }
+ else
+ {
+ exportByValueRequired = false;
+ }
+
+
+ //check that the export manager can handle export by value
+ if (exportByValueRequired &&
!producer.getExportManager().supportExportByValue())
+ {
+ //TODO: instead of passing a string here, we should pass a resource so that its
localized
+ WSRP2ExceptionFactory.throwWSException(ExportByValueNotSupported.class,
"The consumer is requesting portlets to be exported by value, but this consumer only
supports export by reference.", null);
+ }
+
+
+ List<ExportedPortlet> exportedPortlets = new
ArrayList<ExportedPortlet>();
+ Map<String, FailedPortlets> failedPortletsMap = new HashMap<String,
FailedPortlets>();
+
+ try
+ {
+ RegistrationLocal.setRegistration(registration);
+
+ //TODO: try catch here?
+ ExportContext exportContext =
producer.getExportManager().createExportContext(exportByValueRequired,
exportPortlets.getLifetime());
+
+ for (PortletContext portletContext : exportPortlets.getPortletContext())
+ {
+ try
+ {
+ byte[] exportData;
+
+ String portletHandle = portletContext.getPortletHandle();
+ byte[] portletState = portletContext.getPortletState();
+
+ if (portletHandle != null)
+ {
+ org.gatein.pc.api.PortletContext portalPC =
WSRPUtils.convertToPortalPortletContext(portletContext);
+
+ producer.getPortletInvoker().getPortlet(portalPC);
+
+ org.gatein.pc.api.PortletContext exportedPortalPC =
producer.getPortletInvoker().exportPortletContext(PortletStateType.OPAQUE, portalPC);
+
+ PortletContext exportedPortalContext =
WSRPUtils.convertToWSRPPortletContext(exportedPortalPC);
+ portletHandle = exportedPortalContext.getPortletHandle();
+ portletState = exportedPortalContext.getPortletState();
+
+ if (exportedPortalPC == null)
+ {
+ WSRP2ExceptionFactory.throwWSException(InvalidHandle.class,
"Could not find a portlet with handle " + portletHandle + " in the
producer", null);
+ }
+ }
+ else
+ {
+ WSRP2ExceptionFactory.throwWSException(InvalidHandle.class, "A
portlet handle cannot be null.", null);
+ }
+
+ //get the exportPortletData
+ ExportPortletData exportPortletData =
producer.getExportManager().createExportPortletData(exportContext, portletHandle,
portletState);
+
+ //Create the exportedPortlet
+ ExportedPortlet exportedPortlet =
WSRPTypeFactory.createExportedPortlet(portletHandle, exportPortletData.encodeAsBytes());
+ exportedPortlets.add(exportedPortlet);
+ }
+
+ catch (Exception e)
+ {
+ if (log.isWarnEnabled())
+ {
+ log.warn("Error occured while trying to export a portlet.",
e);
+ }
+
+ ErrorCodes.Codes errorCode;
+ String reason;
+ if (e instanceof NoSuchPortletException || e instanceof InvalidHandle)
+ {
+ errorCode = ErrorCodes.Codes.INVALIDHANDLE;
+ reason = "The specified portlet handle is invalid";
+ }
+ else // default error message.
+ {
+ errorCode = ErrorCodes.Codes.OPERATIONFAILED;
+ reason = "Error preparing portlet for export";
+ }
+
+ if (!failedPortletsMap.containsKey(errorCode.name()))
+ {
+ List<String> portletHandles = new ArrayList<String>();
+ portletHandles.add(portletContext.getPortletHandle());
+
+ FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, errorCode, reason);
+ failedPortletsMap.put(errorCode.name(), failedPortlets);
+ }
+ else
+ {
+ FailedPortlets failedPortlets =
failedPortletsMap.get(errorCode.name());
+
failedPortlets.getPortletHandles().add(portletContext.getPortletHandle());
+ }
+ }
+ }
+
+ //TODO: handle resourceLists better (should be using for things like errors)
+ ResourceList resourceList = null;
+
+ return
WSRPTypeFactory.createExportPortletsResponse(exportContext.encodeAsBytes(),
exportedPortlets, new ArrayList<FailedPortlets>(failedPortletsMap.values()),
exportContext.getLifeTime(), resourceList);
+ }
+ catch (Exception e)//TODO ADD PROPER EXCEPTION HANDLING
+ {
+ e.printStackTrace();
+ throw new OperationFailed("TODO: add proper error handling", new
OperationFailedFault());
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+
+ public ImportPortletsResponse importPortlets(ImportPortlets importPortlets) throws
OperationFailed, InvalidRegistration, MissingParameters
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(importPortlets,
"ImportPortlets");
+
+ List<ImportPortlet> importPortletList = importPortlets.getImportPortlet();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(importPortletList,
"ImportPortlet", "ImportPortlets");
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(importPortlets.getRegistrationContext());
+
+ // check if we have a valid userContext or not
+ UserContext userContext = importPortlets.getUserContext();
+ checkUserAuthorization(userContext);
+
+ try
+ {
+ RegistrationLocal.setRegistration(registration);
+
+ byte[] importContext = importPortlets.getImportContext();
+
+ Lifetime lifeTime = importPortlets.getLifetime();
+
+ List<ImportedPortlet> importedPortlets = new
ArrayList<ImportedPortlet>();
+ Map<String, ImportPortletsFailed> failedPortletsMap = new
HashMap<String, ImportPortletsFailed>();
+
+ ExportContext exportContext;
+ try
+ {
+ exportContext =
producer.getExportManager().createExportContext(importContext);
+ }
+ catch (Exception e)
+ {
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class,
"Invalid ImportContext.", e);
+ }
+
+ for (ImportPortlet importPortlet : importPortletList)
+ {
+ try
+ {
+ byte[] portletData = importPortlet.getExportData();
+
+ ExportPortletData exportPortletData =
producer.getExportManager().createExportPortletData(exportContext, lifeTime,
portletData);
+
+ String portletHandle = exportPortletData.getPortletHandle();
+ byte[] portletState = exportPortletData.getPortletState();
+
+ PortletContext pc = WSRPTypeFactory.createPortletContext(portletHandle,
portletState);
+ org.gatein.pc.api.PortletContext pcPortletContext =
WSRPUtils.convertToPortalPortletContext(pc);
+
+ org.gatein.pc.api.PortletContext cpc =
producer.getPortletInvoker().importPortletContext(PortletStateType.OPAQUE,
pcPortletContext);
+ PortletContext wpc = WSRPUtils.convertToWSRPPortletContext(cpc);
+
+ ImportedPortlet importedPortlet =
WSRPTypeFactory.createImportedPortlet(importPortlet.getImportID(), wpc);
+
+ importedPortlets.add(importedPortlet);
+ }
+ catch (Exception e)
+ {
+ if (log.isWarnEnabled())
+ {
+ log.warn("Error occured while trying to import a portlet.",
e);
+ }
+
+ ErrorCodes.Codes errorCode;
+ String reason;
+ if (e instanceof NoSuchPortletException || e instanceof InvalidHandle)
+ {
+ errorCode = ErrorCodes.Codes.INVALIDHANDLE;
+ reason = "The specified portlet handle is invalid";
+ }
+ else if (e instanceof OperationFailed)
+ {
+ errorCode = ErrorCodes.Codes.OPERATIONFAILED;
+ reason = e.getMessage();
+ }
+ else if (e instanceof PortletInvokerException || e instanceof
UnsupportedOperationException || e instanceof IllegalArgumentException)
+ {
+ errorCode = ErrorCodes.Codes.OPERATIONFAILED;
+ reason = "Error trying to create imported portlet.";
+ }
+ else // default error message.
+ {
+ errorCode = ErrorCodes.Codes.OPERATIONFAILED;
+ reason = "Error preparing portlet for export";
+ }
+
+ if (!failedPortletsMap.containsKey(errorCode.name()))
+ {
+ List<String> portleIDs = new ArrayList<String>();
+ portleIDs.add(importPortlet.getImportID());
+
+ ImportPortletsFailed failedPortlets =
WSRPTypeFactory.createImportPortletsFailed(portleIDs, errorCode, reason);
+ failedPortletsMap.put(errorCode.name(), failedPortlets);
+ }
+ else
+ {
+ ImportPortletsFailed failedPortlets =
failedPortletsMap.get(errorCode.name());
+ failedPortlets.getImportID().add(importPortlet.getImportID());
+ }
+ }
+ }
+
+ ResourceList resourceList = null; //TODO: figure out what exactly should be
stored in the resource list here
+
+ return WSRPTypeFactory.createImportPortletsResponse(importedPortlets, new
ArrayList<ImportPortletsFailed>(failedPortletsMap.values()), resourceList);
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+
+ public List<Extension> releaseExport(ReleaseExport releaseExport)
+ {
+ try
+ {
+ if (releaseExport != null)
+ {
+ ExportContext exportContext =
producer.getExportManager().createExportContext(releaseExport.getExportContext());
+ producer.getExportManager().releaseExport(exportContext);
+ }
+ }
+ catch (Exception e)
+ {
+ if (log.isWarnEnabled())
+ {
+ log.warn("Error occured while trying to perform a ReleaseExport",
e);
+ }
+ }
+
+ //this method shouldn't return anything
+ return new ReturnAny().getExtensions();
+ }
+
+ public Lifetime setExportLifetime(SetExportLifetime setExportLifetime) throws
OperationFailed, InvalidRegistration
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(setExportLifetime,
"setExportLifetimePortlets");
+
+ byte[] exportContextBytes = setExportLifetime.getExportContext();
+ //NOTE: we can't throw a MissingParameterException since its not allowed as
part of the spec
+ if (exportContextBytes == null)
+ {
+ WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot call
setExportLifetime with an empty ExportContext.", null);
+ }
+
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(setExportLifetime.getRegistrationContext());
+
+ // check if we have a valid userContext or not
+ UserContext userContext = setExportLifetime.getUserContext();
+ checkUserAuthorization(userContext);
+
+ try
+ {
+ RegistrationLocal.setRegistration(registration);
+
+ ExportContext exportContext =
producer.getExportManager().createExportContext(exportContextBytes);
+
+ return producer.getExportManager().setExportLifetime(exportContext,
setExportLifetime.getLifetime());
+
+ }
+ catch (Exception e)
+ {
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class,
"Operation Failed while trying to setExportLifetime.", e);
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+
+ private void checkUserAuthorization(UserContext userContext)
+ {
+ //todo: implement
+ if (userContext != null)
+ {
+
+ }
+ }
+
+ private Portlet getPortletFrom(PortletContext portletContext, Registration
registration) throws InvalidHandle
+ {
+ Portlet portlet;
+ try
+ {
+ RegistrationLocal.setRegistration(registration);
+ portlet =
producer.getPortletInvoker().getPortlet(WSRPUtils.convertToPortalPortletContext(portletContext));
+ return portlet;
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(InvalidHandle.class, "Could
not retrieve portlet '" + portletContext.getPortletHandle() + "'",
e);
+ }
+ finally
+ {
+ RegistrationLocal.setRegistration(null);
+ }
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/RegistrationHandler.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/RegistrationHandler.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/RegistrationHandler.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,408 @@
+/*
+ * 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.handlers;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.Mode;
+import org.gatein.pc.api.WindowState;
+import org.gatein.registration.Consumer;
+import org.gatein.registration.ConsumerCapabilities;
+import org.gatein.registration.NoSuchRegistrationException;
+import org.gatein.registration.Registration;
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.RegistrationStatus;
+import org.gatein.registration.RegistrationUtils;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.producer.RegistrationInterface;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
+import org.oasis.wsrp.v2.AccessDenied;
+import org.oasis.wsrp.v2.Extension;
+import org.oasis.wsrp.v2.GetRegistrationLifetime;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.Lifetime;
+import org.oasis.wsrp.v2.MissingParameters;
+import org.oasis.wsrp.v2.ModifyRegistration;
+import org.oasis.wsrp.v2.ModifyRegistrationRequired;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationNotSupported;
+import org.oasis.wsrp.v2.Property;
+import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.RegistrationData;
+import org.oasis.wsrp.v2.RegistrationState;
+import org.oasis.wsrp.v2.ResourceSuspended;
+import org.oasis.wsrp.v2.SetRegistrationLifetime;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 13202 $
+ * @since 2.4
+ */
+public class RegistrationHandler extends ServiceHandler implements RegistrationInterface
+{
+ public RegistrationHandler(WSRPProducerImpl producer)
+ {
+ super(producer);
+ }
+
+ public RegistrationContext register(RegistrationData registrationData)
+ throws MissingParameters, OperationFailed, OperationNotSupported
+ {
+ ProducerRegistrationRequirements registrationRequirements =
producer.getProducerRegistrationRequirements();
+ if (registrationRequirements.isRegistrationRequired())
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(registrationData,
"RegistrationData");
+ String consumerName = registrationData.getConsumerName();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(consumerName,
"consumer name", "RegistrationData");
+
+ String consumerAgent = registrationData.getConsumerAgent();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(consumerAgent,
"consumer agent", "RegistrationData");
+
+ Registration registration;
+ try
+ {
+ log.debug("Attempting to register consumer named '" +
consumerName + "', agent '" + consumerAgent + "'.");
+
+ // check that the consumer agent is valid before trying to register
+ RegistrationUtils.validateConsumerAgent(consumerAgent);
+
+ registration =
producer.getRegistrationManager().addRegistrationTo(consumerName,
createRegistrationProperties(registrationData),
registrationRequirements.getRegistrationProperties(), true);
+ updateRegistrationInformation(registration, registrationData);
+ }
+ catch (Exception e)
+ {
+ String msg = "Could not register consumer named '" +
consumerName + "'";
+ log.debug(msg, e);
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, msg, e);
+ }
+
+ RegistrationContext registrationContext =
WSRPTypeFactory.createRegistrationContext(registration.getRegistrationHandle());
+ log.debug("Registration completed without error.");
+ return registrationContext;
+ }
+
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Registration shouldn't be attempted if registration is not required",
null);
+ }
+
+ private void updateRegistrationInformation(Registration registration, RegistrationData
registrationData)
+ {
+ registration.setStatus(RegistrationStatus.VALID);
+ Consumer consumer = registration.getConsumer();
+ consumer.setConsumerAgent(registrationData.getConsumerAgent());
+ ConsumerCapabilities capabilities = consumer.getCapabilities();
+
+ List<String> modeStrings = registrationData.getConsumerModes();
+ int modesNb = modeStrings.size();
+ if (modesNb > 0)
+ {
+ List<Mode> modes = new ArrayList<Mode>(modesNb);
+ for (String modeString : modeStrings)
+ {
+ modes.add(WSRPUtils.getJSR168PortletModeFromWSRPName(modeString));
+ }
+ capabilities.setSupportedModes(modes);
+ }
+
+ List<String> wsStrings = registrationData.getConsumerWindowStates();
+ int wsNb = wsStrings.size();
+ if (wsNb > 0)
+ {
+ List<WindowState> windowStates = new ArrayList<WindowState>(wsNb);
+ for (String wsString : wsStrings)
+ {
+ windowStates.add(WSRPUtils.getJSR168WindowStateFromWSRPName(wsString));
+ }
+ capabilities.setSupportedWindowStates(windowStates);
+ }
+
+ capabilities.setSupportedUserScopes(registrationData.getConsumerUserScopes());
+ capabilities.setSupportsGetMethod(registrationData.isMethodGetSupported());
+
+ producer.getRegistrationManager().getPersistenceManager().saveChangesTo(consumer);
+ }
+
+ public List<Extension> deregister(RegistrationContext deregister)
+ throws InvalidRegistration, OperationFailed, OperationNotSupported,
ResourceSuspended
+ {
+ if (producer.getProducerRegistrationRequirements().isRegistrationRequired())
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(deregister,
"RegistrationContext");
+
+ String registrationHandle = deregister.getRegistrationHandle();
+ if (ParameterValidation.isNullOrEmpty(registrationHandle))
+ {
+ throwInvalidRegistrationFault("Null or empty registration
handle");
+ }
+
+ log.debug("Attempting to deregister registration with handle '" +
registrationHandle + "'");
+
+ String msg = "Could not deregister registration with handle '" +
registrationHandle + "'";
+ try
+ {
+ producer.getRegistrationManager().removeRegistration(registrationHandle);
+ }
+ catch (NoSuchRegistrationException e)
+ {
+ log.debug(msg, e);
+ throwInvalidRegistrationFault(e.getLocalizedMessage());
+ }
+ catch (RegistrationException e)
+ {
+ log.debug(msg, e);
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, msg, e);
+ }
+
+ return Collections.emptyList();
+ }
+
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Deregistration shouldn't be attempted if registration is not required",
null);
+ }
+
+ public RegistrationState modifyRegistration(ModifyRegistration modifyRegistration)
+ throws InvalidRegistration, MissingParameters, OperationFailed,
OperationNotSupported, ResourceSuspended
+ {
+ if (producer.getProducerRegistrationRequirements().isRegistrationRequired())
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(modifyRegistration,
"ModifyRegistration");
+
+ RegistrationContext registrationContext =
modifyRegistration.getRegistrationContext();
+
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(registrationContext,
"RegistrationContext", "ModifyRegistration");
+ String registrationHandle = registrationContext.getRegistrationHandle();
+ if (ParameterValidation.isNullOrEmpty(registrationHandle))
+ {
+ throwInvalidRegistrationFault("Null or empty registration
handle");
+ }
+
+ RegistrationData registrationData = modifyRegistration.getRegistrationData();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(registrationData,
"RegistrationData", "ModifyRegistration");
+
+ String consumerName = registrationData.getConsumerName();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(consumerName,
"consumer name", "RegistrationData");
+
+ String consumerAgent = registrationData.getConsumerAgent();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(consumerAgent,
"consumer agent", "RegistrationData");
+
+ log.debug("Attempting to modify registration with handle '" +
registrationHandle + "'");
+ String msg = "Could not modify registration with handle '" +
registrationHandle + "'";
+ try
+ {
+ Registration registration =
producer.getRegistrationManager().getRegistration(registrationHandle);
+
+ Map<QName, Object> properties =
createRegistrationProperties(registrationData);
+
+ // check that the given registration properties are acceptable according to
expectations and policy
+ ProducerRegistrationRequirements req =
producer.getProducerRegistrationRequirements();
+ req.getPolicy().validateRegistrationDataFor(properties, consumerName,
req.getRegistrationProperties(), producer.getRegistrationManager());
+
+ registration.updateProperties(properties);
+ updateRegistrationInformation(registration, registrationData);
+ }
+ catch (NoSuchRegistrationException e)
+ {
+ log.debug(msg, e);
+ throwInvalidRegistrationFault(e.getLocalizedMessage());
+ }
+ catch (RegistrationException e)
+ {
+ log.debug(msg, e);
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, msg, e);
+ }
+
+
+ log.debug("Modified registration with handle '" +
registrationHandle + "'");
+ return null;
+ }
+
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Modifying
a registration shouldn't be attempted if registration is not required", null);
+ }
+
+ public Lifetime getRegistrationLifetime(GetRegistrationLifetime
getRegistrationLifetime)
+ throws AccessDenied, InvalidHandle, InvalidRegistration,
ModifyRegistrationRequired, OperationFailed,
+ OperationNotSupported, ResourceSuspended
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class,
"Lifetime operations are not currently supported.", null);
+ }
+
+ public Lifetime setRegistrationLifetime(SetRegistrationLifetime
setRegistrationLifetime)
+ throws AccessDenied, InvalidHandle, InvalidRegistration,
ModifyRegistrationRequired, OperationFailed,
+ OperationNotSupported, ResourceSuspended
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class,
"Lifetime operations are not currently supported.", null);
+ }
+
+ /**
+ * @param reg
+ * @param throwExceptionIfInvalid
+ * @return
+ * @since 2.6.2
+ */
+ public boolean isRegistrationValid(Registration reg, boolean throwExceptionIfInvalid)
throws InvalidRegistration, OperationFailed
+ {
+ if (reg == null)
+ {
+ if (producer.getProducerRegistrationRequirements().isRegistrationRequired())
+ {
+ log.debug("Registration is required yet no RegistrationContext was
provided: registration invalid!");
+ if (throwExceptionIfInvalid)
+ {
+ throwInvalidRegistrationFault("registration is required yet no
RegistrationContext was provided!");
+ }
+ return false;
+ }
+
+ log.debug("Registration not required, no registration: registration
valid!");
+ return true;
+ }
+ else
+ {
+ boolean isValid = RegistrationStatus.VALID.equals(reg.getStatus());
+ boolean isPending = RegistrationStatus.PENDING.equals(reg.getStatus());
+ log.debug("Registration required: registration is " + (isValid ?
"valid!" : (isPending ? "pending!" : "invalid!")));
+
+ if (throwExceptionIfInvalid)
+ {
+ if (isPending)
+ {
+ throwOperationFailedFault("Registration with handle '" +
reg.getRegistrationHandle()
+ + "' is pending. Consumer needs to call
modifyRegistration().", null);
+ }
+ else
+ {
+ if (!isValid)
+ {
+ throwInvalidRegistrationFault("registration with handle
'" + reg.getRegistrationHandle() + "' is not valid!");
+ }
+ }
+ }
+
+ return isValid;
+ }
+ }
+
+ /**
+ * @param registrationContext
+ * @return
+ * @since 2.6.2
+ */
+ public Registration getRegistrationFrom(RegistrationContext registrationContext)
throws InvalidRegistration, OperationFailed
+ {
+ if (producer.getProducerRegistrationRequirements().isRegistrationRequired())
+ {
+ if (registrationContext == null)
+ {
+ throwInvalidRegistrationFault("registration context is missing but
registration is required");
+ }
+
+ String regHandle = registrationContext.getRegistrationHandle();
+ if (regHandle == null)
+ {
+ throwInvalidRegistrationFault("registration handle is missing but
registration is required");
+ }
+
+ try
+ {
+ Registration registration =
producer.getRegistrationManager().getRegistration(regHandle);
+ if (registration == null)
+ {
+ throwInvalidRegistrationFault("provided registration handle
'" + regHandle + "' is not registered with this producer");
+ }
+ return registration;
+ }
+ catch (RegistrationException e)
+ {
+ throwOperationFailedFault("Failed to retrieve registration information
associated with handle " + regHandle, e);
+ return null;
+ }
+ }
+ else
+ {
+ if (registrationContext != null)
+ {
+ throwInvalidRegistrationFault("no registration necessary yet one was
provided!");
+ }
+ return null;
+ }
+ }
+
+ private void throwOperationFailedFault(String message, RegistrationException e) throws
OperationFailed
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, message, e);
+ }
+
+ boolean throwInvalidRegistrationFault(String message) throws InvalidRegistration
+ {
+ throw WSRP2ExceptionFactory.throwWSException(InvalidRegistration.class,
"Invalid registration: " + message, null);
+ }
+
+ private Map<QName, Object> createRegistrationProperties(RegistrationData
registrationData)
+ {
+ List<Property> regProperties = registrationData.getRegistrationProperties();
+ Map<QName, Object> properties;
+ if (regProperties != null && !regProperties.isEmpty())
+ {
+ properties = new HashMap<QName, Object>(regProperties.size());
+ for (Property property : regProperties)
+ {
+ // todo: should be more detailed here... use the language, allow other value
types...
+ QName propName = property.getName();
+ String propValue = property.getStringValue();
+ if (producer.getProducerRegistrationRequirements().acceptValueFor(propName,
propValue))
+ {
+ properties.put(propName, propValue);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Registration properties named
'" + propName + "' with value '"
+ + propValue + "' was rejected by the WSRP producer.");
+ }
+ }
+ }
+ else
+ {
+ properties = Collections.emptyMap();
+ }
+
+ return properties;
+ }
+
+ private List getListFromArray(String[] array, boolean useEmptyForNull)
+ {
+ if (array == null)
+ {
+ return useEmptyForNull ? Collections.EMPTY_LIST : null;
+ }
+ return Arrays.asList(array);
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceDescriptionHandler.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceDescriptionHandler.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceDescriptionHandler.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,505 @@
+/*
+ * 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.handlers;
+
+import org.gatein.common.net.media.MediaType;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.TransportGuarantee;
+import org.gatein.pc.api.info.CapabilitiesInfo;
+import org.gatein.pc.api.info.EventInfo;
+import org.gatein.pc.api.info.EventingInfo;
+import org.gatein.pc.api.info.MetaInfo;
+import org.gatein.pc.api.info.ModeInfo;
+import org.gatein.pc.api.info.NavigationInfo;
+import org.gatein.pc.api.info.ParameterInfo;
+import org.gatein.pc.api.info.PortletInfo;
+import org.gatein.pc.api.info.SecurityInfo;
+import org.gatein.pc.api.info.WindowStateInfo;
+import org.gatein.registration.Registration;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.producer.ServiceDescriptionInterface;
+import org.gatein.wsrp.producer.Utils;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.gatein.wsrp.spec.v2.WSRP2Constants;
+import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
+import org.oasis.wsrp.v2.CookieProtocol;
+import org.oasis.wsrp.v2.EventDescription;
+import org.oasis.wsrp.v2.GetServiceDescription;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.MarkupType;
+import org.oasis.wsrp.v2.ModelDescription;
+import org.oasis.wsrp.v2.ModifyRegistrationRequired;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.ParameterDescription;
+import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.PortletDescription;
+import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.ResourceSuspended;
+import org.oasis.wsrp.v2.ServiceDescription;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+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>
+ * @version $Revision: 12017 $
+ * @since 2.4
+ */
+public class ServiceDescriptionHandler extends ServiceHandler implements
ServiceDescriptionInterface
+{
+ // JBPORTAL-1220: force call to initCookie... Required so that BEA version < 9.2
will behave properly as a Consumer
+ private static final CookieProtocol BEA_8_CONSUMER_FIX = CookieProtocol.PER_USER;
+ private ServiceDescriptionInfo serviceDescription;
+
+ public ServiceDescriptionHandler(WSRPProducerImpl producer)
+ {
+ super(producer);
+ serviceDescription = new ServiceDescriptionInfo(producer);
+ }
+
+ public ServiceDescription getServiceDescription(GetServiceDescription gs)
+ throws InvalidRegistration, ModifyRegistrationRequired, OperationFailed,
ResourceSuspended
+ {
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(gs,
"GetServiceDescription");
+
+ RegistrationContext registrationContext = gs.getRegistrationContext();
+
+ // if a RegistrationContext is provided, we need to validate the registration
information
+ Registration registration = null;
+ if (registrationContext != null)
+ {
+ registration = producer.getRegistrationOrFailIfInvalid(registrationContext);
+ }
+
+ ProducerRegistrationRequirements requirements =
producer.getProducerRegistrationRequirements();
+
+ //update the registration properties with the registration requirements
+ serviceDescription.updateRegistrationProperties(requirements);
+
+ // if we don't have registration information but a registration is required,
send registration props information
+ boolean needsRegistrationProperties = registration == null &&
requirements.isRegistrationRequired();
+
+ // if we allow sending portlet descriptions even when not registered
+ boolean needsPortletDescriptions = !(registration == null &&
requirements.isRegistrationRequired()
+ && requirements.isRegistrationRequiredForFullDescription());
+ if (needsPortletDescriptions)
+ {
+ Set<Portlet> portlets;
+ try
+ {
+ portlets = producer.getRemotablePortlets();
+ }
+ catch (PortletInvokerException e)
+ {
+ log.warn("Could not retrieve portlets. Reason:\n\t" +
e.getLocalizedMessage());
+ portlets = Collections.emptySet();
+ }
+ serviceDescription.updatePortletDescriptions(portlets, gs.getDesiredLocales(),
registration);
+ }
+
+ return serviceDescription.getServiceDescription(needsRegistrationProperties,
needsPortletDescriptions);
+ }
+
+ public PortletDescription getPortletDescription(PortletContext portletContext,
List<String> desiredLocales, Registration registration) throws InvalidHandle,
OperationFailed
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "portlet
context");
+ Portlet portlet;
+ try
+ {
+ portlet =
producer.getPortletWith(WSRPUtils.convertToPortalPortletContext(portletContext),
registration);
+ return getPortletDescription(portlet, desiredLocales);
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not retrieve portlet '" + portletContext + "'", e);
+ }
+ }
+
+ /**
+ * Creates a PortletDescription based on the user desired locales (ordered according
to user preferences) for the
+ * specified component.
+ *
+ * @param portlet
+ * @param desiredLocales the user desired locales (ordered according to user
preferences) to use for the description
+ * @return a PortletDescription describing the specified portlet
+ */
+ public static PortletDescription getPortletDescription(Portlet portlet,
List<String> desiredLocales)
+ {
+ return getPortletDescription(portlet, desiredLocales, null);
+ }
+
+ /**
+ * Creates a PortletDescription based on the user desired locales (ordered according
to user preferences) for the
+ * specified component.
+ *
+ * @param portlet
+ * @param desiredLocales the user desired locales (ordered according to user
preferences) to use for the description
+ * @return a PortletDescription describing the specified portlet
+ */
+ static PortletDescription getPortletDescription(Portlet portlet, List<String>
desiredLocales, ServiceDescriptionInfo sdi)
+ {
+ org.gatein.pc.api.PortletContext context = portlet.getContext();
+ PortletInfo info = portlet.getInfo();
+ String handle = context.getId();
+ if (log.isDebugEnabled())
+ {
+ log.debug("Constructing portlet description for: " + handle);
+ }
+
+ CapabilitiesInfo capInfo = info.getCapabilities();
+ Collection<MediaType> allMediaTypes = capInfo.getMediaTypes();
+ List<MarkupType> markupTypes = new
ArrayList<MarkupType>(allMediaTypes.size());
+ for (MediaType mediaType : allMediaTypes)
+ {
+ MarkupType markupType = WSRPTypeFactory.createMarkupType(mediaType.getValue(),
+ getModeNamesFrom(capInfo.getModes(mediaType)),
getWindowStateNamesFrom(capInfo.getWindowStates(mediaType)),
+ getLocaleNamesFrom(capInfo.getLocales(mediaType)));
+ markupTypes.add(markupType);
+ }
+
+ PortletDescription desc = WSRPTypeFactory.createPortletDescription(handle,
markupTypes);
+
+ // group ID
+ desc.setGroupID(info.getApplicationName());
+
+ MetaInfo metaInfo = info.getMeta();
+
+ // description
+
desc.setDescription(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.DESCRIPTION),
desiredLocales));
+
+ // short title
+
desc.setShortTitle(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.SHORT_TITLE),
desiredLocales));
+
+ // title
+
desc.setTitle(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.TITLE),
desiredLocales));
+
+ // display name
+
desc.setDisplayName(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME),
desiredLocales));
+
+ // keywords
+ // metaInfo contains comma-separated keywords: we need to extract them into a list
+ org.oasis.wsrp.v2.LocalizedString concatenatedKeywords =
+ Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.KEYWORDS),
desiredLocales);
+ if (concatenatedKeywords != null)
+ {
+ String commaSeparatedKeywords = concatenatedKeywords.getValue();
+ if (commaSeparatedKeywords != null && commaSeparatedKeywords.length()
> 0)
+ {
+ String lang = concatenatedKeywords.getLang();
+ String[] keywordArray = commaSeparatedKeywords.split(",");
+ for (String keyword : keywordArray)
+ {
+ // todo: fix resource name
+ desc.getKeywords().add(WSRPTypeFactory.createLocalizedString(lang,
concatenatedKeywords.getResourceName(), keyword.trim()));
+ }
+ }
+ }
+
+ // events
+ EventingInfo eventsInfo = info.getEventing();
+ if (eventsInfo != null)
+ {
+ Map<QName, ? extends EventInfo> producedEvents =
eventsInfo.getProducedEvents();
+ if (ParameterValidation.existsAndIsNotEmpty(producedEvents))
+ {
+ List<QName> publishedEvents = desc.getPublishedEvents();
+ for (Map.Entry<QName, ? extends EventInfo> entry :
producedEvents.entrySet())
+ {
+ publishedEvents.add(entry.getKey());
+
+ // record event info in ServiceDescriptionInfo
+ if (sdi != null)
+ {
+ sdi.addEventInfo(entry.getValue(), desiredLocales);
+ }
+ }
+ }
+ Map<QName, ? extends EventInfo> consumedEvents =
eventsInfo.getConsumedEvents();
+ if (ParameterValidation.existsAndIsNotEmpty(consumedEvents))
+ {
+ List<QName> handledEvents = desc.getHandledEvents();
+ for (Map.Entry<QName, ? extends EventInfo> entry :
consumedEvents.entrySet())
+ {
+ handledEvents.add(entry.getKey());
+
+ // record event info in ServiceDescriptionInfo
+ if (sdi != null)
+ {
+ sdi.addEventInfo(entry.getValue(), desiredLocales);
+ }
+ }
+ }
+ }
+
+ // public parameters
+ NavigationInfo navigationInfo = info.getNavigation();
+ if (navigationInfo != null)
+ {
+ Collection<? extends ParameterInfo> parameterInfos =
navigationInfo.getPublicParameters();
+ if (ParameterValidation.existsAndIsNotEmpty(parameterInfos))
+ {
+ List<ParameterDescription> publicValueDescriptions =
desc.getNavigationalPublicValueDescriptions();
+ for (ParameterInfo parameterInfo : parameterInfos)
+ {
+ String id = parameterInfo.getId();
+ ParameterDescription paramDesc =
WSRPTypeFactory.createParameterDescription(id);
+
paramDesc.setDescription(Utils.convertToWSRPLocalizedString(parameterInfo.getDescription(),
desiredLocales));
+ paramDesc.setLabel(WSRPTypeFactory.createLocalizedString(id));
+ List<QName> names = paramDesc.getNames();
+ names.add(parameterInfo.getName());
+ Collection<QName> aliases = parameterInfo.getAliases();
+ if (ParameterValidation.existsAndIsNotEmpty(aliases))
+ {
+ names.addAll(aliases);
+ }
+
+ publicValueDescriptions.add(paramDesc);
+ }
+ }
+ }
+
+ // security
+ SecurityInfo secInfo = info.getSecurity();
+ if (secInfo.containsTransportGuarantee(TransportGuarantee.INTEGRAL)
+ || secInfo.containsTransportGuarantee(TransportGuarantee.CONFIDENTIAL))
+ {
+ desc.setOnlySecure(true);
+ }
+
+ /* todo:
+ * [O] ID portletID
+ * [O] string userCategories[]
+ * [O] string userProfileItems[]
+ * [O] string portletManagedModes[]
+ * [O] boolean usesMethodGet
+ * [O] boolean defaultMarkupSecure
+ * [O] boolean userContextStoredInSession
+ * [O] boolean templatesStoredInSession
+ * [O] boolean hasUserSpecificState
+ * [O] boolean doesUrlTemplateProcessing
+ * [O] boolean mayReturnPortletState
+ * [O] Extension extensions[]
+ */
+ return desc;
+ }
+
+ private static List<String> getLocaleNamesFrom(Collection<Locale>
locales)
+ {
+ if (locales == null || locales.isEmpty())
+ {
+ return null;
+ }
+
+ List<String> localeNames = new ArrayList<String>(locales.size());
+ for (Locale locale : locales)
+ {
+ localeNames.add(WSRPUtils.toString(locale));
+ }
+ return localeNames;
+ }
+
+ private static List<String>
getWindowStateNamesFrom(Collection<WindowStateInfo> windowStates)
+ {
+ List<String> result = new ArrayList<String>(windowStates.size());
+ for (WindowStateInfo windowStateInfo : windowStates)
+ {
+
result.add(WSRPUtils.convertJSR168WindowStateNameToWSRPName(windowStateInfo.getWindowStateName()));
+ }
+ return result;
+ }
+
+ private static List<String> getModeNamesFrom(Collection<ModeInfo> modes)
+ {
+ List<String> result = new ArrayList<String>(modes.size());
+ for (ModeInfo modeInfo : modes)
+ {
+
result.add(WSRPUtils.convertJSR168PortletModeNameToWSRPName(modeInfo.getModeName()));
+ }
+ return result;
+ }
+
+ private static class ServiceDescriptionInfo
+ {
+ /** Empty service description: no registration properties, no offered portlets */
+ private ServiceDescription noRegistrationNoPortletsServiceDescription;
+ /** No registration properties, offered portles */
+ private ServiceDescription noRegistrationPortletsServiceDescription;
+ /** Registration properties, no offered portlets */
+ private ServiceDescription registrationNoPortletsServiceDescription;
+ /** Registration properties, offered portlets */
+ private ServiceDescription registrationPortletsServiceDescription;
+
+ private long lastGenerated;
+ private Map<QName, EventDescription> eventDescriptions;
+
+ private static final List<String> OPTIONS = new ArrayList<String>(5);
+
+ static
+ {
+ OPTIONS.add(WSRP2Constants.OPTIONS_EVENTS);
+ OPTIONS.add(WSRP2Constants.OPTIONS_IMPORT);
+ OPTIONS.add(WSRP2Constants.OPTIONS_EXPORT);
+ }
+
+ private ServiceDescriptionInfo(WSRPProducerImpl producer)
+ {
+ noRegistrationNoPortletsServiceDescription =
WSRPTypeFactory.createServiceDescription(false);
+
noRegistrationNoPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
+
noRegistrationNoPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
+
noRegistrationNoPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
+
+ noRegistrationPortletsServiceDescription =
WSRPTypeFactory.createServiceDescription(false);
+
noRegistrationPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
+
noRegistrationPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
+ noRegistrationPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
+
+ registrationNoPortletsServiceDescription =
WSRPTypeFactory.createServiceDescription(false);
+
registrationNoPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
+
registrationNoPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
+ registrationNoPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
+
+ registrationPortletsServiceDescription =
WSRPTypeFactory.createServiceDescription(false);
+
registrationPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
+
registrationPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
+ registrationPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
+ }
+
+ private void updateRegistrationProperties(ProducerRegistrationRequirements
requirements)
+ {
+ long lastModified = requirements.getLastModified();
+ if (lastModified > lastGenerated)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Re-generating registration properties information for
service description.");
+ }
+
+ // do not create a ModelDescription if there is no registration properties
+ Map<QName, RegistrationPropertyDescription> info =
requirements.getRegistrationProperties();
+ ModelDescription registrationProperties = null;
+ if (ParameterValidation.existsAndIsNotEmpty(info))
+ {
+ registrationProperties =
Utils.convertRegistrationPropertiesToModelDescription(info);
+ }
+
registrationNoPortletsServiceDescription.setRegistrationPropertyDescription(registrationProperties);
+
registrationPortletsServiceDescription.setRegistrationPropertyDescription(registrationProperties);
+
+ // update need to register
+
noRegistrationNoPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
+
noRegistrationPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
+
registrationNoPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
+
registrationPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
+
+ lastGenerated = System.nanoTime();
+ }
+ }
+
+ private void updatePortletDescriptions(Set<Portlet> portlets,
List<String> desiredLocales, Registration registration)
+ {
+ if (ParameterValidation.existsAndIsNotEmpty(portlets))
+ {
+ Collection<PortletDescription> offeredPortletDescriptions = new
ArrayList<PortletDescription>(portlets.size());
+
+ // reset event descriptions as they will be repopulated when we build the
portlet descriptions
+ eventDescriptions = new HashMap<QName,
EventDescription>(portlets.size());
+
+ for (Portlet portlet : portlets)
+ {
+ PortletDescription desc = getPortletDescription(portlet, desiredLocales,
this);
+ offeredPortletDescriptions.add(desc);
+ }
+
+ // events
+ Collection<EventDescription> events = eventDescriptions.values();
+ List<EventDescription> eventDescriptions =
registrationPortletsServiceDescription.getEventDescriptions();
+ eventDescriptions.clear();
+ eventDescriptions.addAll(events);
+
+ eventDescriptions =
registrationNoPortletsServiceDescription.getEventDescriptions();
+ eventDescriptions.clear();
+ eventDescriptions.addAll(events);
+
+ eventDescriptions =
noRegistrationPortletsServiceDescription.getEventDescriptions();
+ eventDescriptions.clear();
+ eventDescriptions.addAll(events);
+
+ eventDescriptions =
noRegistrationNoPortletsServiceDescription.getEventDescriptions();
+ eventDescriptions.clear();
+ eventDescriptions.addAll(events);
+
+ // portlets
+ List<PortletDescription> offeredPortlets =
registrationPortletsServiceDescription.getOfferedPortlets();
+ offeredPortlets.clear();
+ offeredPortlets.addAll(offeredPortletDescriptions);
+
+ offeredPortlets =
noRegistrationPortletsServiceDescription.getOfferedPortlets();
+ offeredPortlets.clear();
+ offeredPortlets.addAll(offeredPortletDescriptions);
+ }
+ }
+
+ private ServiceDescription getServiceDescription(boolean
needsRegistrationProperties, boolean needsPortletDescriptions)
+ {
+ if (needsRegistrationProperties)
+ {
+ return needsPortletDescriptions ? registrationPortletsServiceDescription :
registrationNoPortletsServiceDescription;
+ }
+ else
+ {
+ return needsPortletDescriptions ? noRegistrationPortletsServiceDescription :
noRegistrationNoPortletsServiceDescription;
+ }
+ }
+
+ public void addEventInfo(EventInfo info, List<String> desiredLocales)
+ {
+ QName name = info.getName();
+ if (!eventDescriptions.containsKey(name))
+ {
+ EventDescription desc = WSRPTypeFactory.createEventDescription(name);
+ desc.setDescription(Utils.convertToWSRPLocalizedString(info.getDescription(),
desiredLocales));
+ desc.setLabel(Utils.convertToWSRPLocalizedString(info.getDisplayName(),
desiredLocales));
+ Collection<QName> aliases = info.getAliases();
+ if (ParameterValidation.existsAndIsNotEmpty(aliases))
+ {
+ desc.getAliases().addAll(aliases);
+ }
+ // todo: deal with type info...
+ eventDescriptions.put(name, desc);
+ }
+ }
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceHandler.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceHandler.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceHandler.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceHandler.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.wsrp.producer.handlers;
+
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.4
+ */
+class ServiceHandler
+{
+ protected WSRPProducerImpl producer;
+ protected static final Logger log = LoggerFactory.getLogger(ServiceHandler.class);
+
+ ServiceHandler(WSRPProducerImpl producer)
+ {
+ this.producer = producer;
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ActionRequestProcessor.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ActionRequestProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,144 @@
+/*
+ * 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.handlers.processors;
+
+import org.gatein.pc.api.StateString;
+import org.gatein.pc.api.invocation.ActionInvocation;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.pc.api.invocation.response.HTTPRedirectionResponse;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
+import org.gatein.pc.api.state.AccessMode;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.producer.handlers.MarkupHandler;
+import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
+import org.oasis.wsrp.v2.InteractionParams;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.MimeRequest;
+import org.oasis.wsrp.v2.MissingParameters;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PerformBlockingInteraction;
+import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.RuntimeContext;
+import org.oasis.wsrp.v2.StateChange;
+import org.oasis.wsrp.v2.UnsupportedMimeType;
+import org.oasis.wsrp.v2.UnsupportedMode;
+import org.oasis.wsrp.v2.UnsupportedWindowState;
+import org.oasis.wsrp.v2.UpdateResponse;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 13121 $
+ * @since 2.6
+ */
+class ActionRequestProcessor extends UpdateNavigationalStateResponseProcessor
+{
+ private final PerformBlockingInteraction performBlockingInteraction;
+
+ ActionRequestProcessor(WSRPProducerImpl producer, PerformBlockingInteraction
performBlockingInteraction)
+ throws UnsupportedMimeType, UnsupportedWindowState, InvalidHandle, UnsupportedMode,
MissingParameters,
+ InvalidRegistration, OperationFailed
+ {
+ super(producer);
+ this.performBlockingInteraction = performBlockingInteraction;
+ prepareInvocation();
+ }
+
+ RegistrationContext getRegistrationContext()
+ {
+ return performBlockingInteraction.getRegistrationContext();
+ }
+
+ RuntimeContext getRuntimeContext()
+ {
+ return performBlockingInteraction.getRuntimeContext();
+ }
+
+ MimeRequest getParams()
+ {
+ return performBlockingInteraction.getMarkupParams();
+ }
+
+ public PortletContext getPortletContext()
+ {
+ return performBlockingInteraction.getPortletContext();
+ }
+
+ org.oasis.wsrp.v2.UserContext getUserContext()
+ {
+ return performBlockingInteraction.getUserContext();
+ }
+
+ String getContextName()
+ {
+ return MarkupHandler.PBI;
+ }
+
+ AccessMode getAccessMode() throws MissingParameters
+ {
+ StateChange stateChange =
performBlockingInteraction.getInteractionParams().getPortletStateChange();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(stateChange,
"portletStateChange", "InteractionParams");
+ return WSRPUtils.getAccessModeFromStateChange(stateChange);
+ }
+
+ PortletInvocation initInvocation(WSRPPortletInvocationContext context)
+ {
+ ActionInvocation invocation = new ActionInvocation(context);
+ InteractionParams interactionParams =
performBlockingInteraction.getInteractionParams();
+
+ // Request context
+ WSRPRequestContext requestContext =
WSRPRequestContext.createRequestContext(markupRequest, interactionParams);
+ invocation.setRequestContext(requestContext);
+
+ // Interaction state, navigational state is already taken care of in
RequestProcessor.prepareInvocation
+ StateString interactionState =
createNavigationalState(interactionParams.getInteractionState());
+ invocation.setInteractionState(interactionState);
+
+ // Form parameters
+ invocation.setForm(requestContext.getForm());
+
+ return invocation;
+ }
+
+ public Object processResponse(PortletInvocationResponse response)
+ {
+ if (response instanceof UpdateNavigationalStateResponse)
+ {
+ UpdateNavigationalStateResponse stateResponse =
(UpdateNavigationalStateResponse)response;
+ UpdateResponse updateResponse = createUpdateResponse(stateResponse);
+
+ return WSRPTypeFactory.createBlockingInteractionResponse(updateResponse);
+ }
+ else
+ {
+ // result should be HTTPRedirectionResult
+ HTTPRedirectionResponse redirectionResult = (HTTPRedirectionResponse)response;
+ return
WSRPTypeFactory.createBlockingInteractionResponse(redirectionResult.getLocation());
+ }
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/EventRequestProcessor.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/EventRequestProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,179 @@
+/*
+ * 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.handlers.processors;
+
+import org.gatein.common.NotYetImplemented;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.invocation.EventInvocation;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
+import org.gatein.pc.api.state.AccessMode;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.payload.PayloadUtils;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.producer.handlers.MarkupHandler;
+import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
+import org.oasis.wsrp.v2.Event;
+import org.oasis.wsrp.v2.EventParams;
+import org.oasis.wsrp.v2.EventPayload;
+import org.oasis.wsrp.v2.HandleEvents;
+import org.oasis.wsrp.v2.HandleEventsResponse;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.MimeRequest;
+import org.oasis.wsrp.v2.MissingParameters;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationNotSupported;
+import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.RuntimeContext;
+import org.oasis.wsrp.v2.StateChange;
+import org.oasis.wsrp.v2.UnsupportedMimeType;
+import org.oasis.wsrp.v2.UnsupportedMode;
+import org.oasis.wsrp.v2.UnsupportedWindowState;
+import org.oasis.wsrp.v2.UpdateResponse;
+import org.oasis.wsrp.v2.UserContext;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+class EventRequestProcessor extends UpdateNavigationalStateResponseProcessor
+{
+ private HandleEvents handleEvents;
+
+ public EventRequestProcessor(WSRPProducerImpl producer, HandleEvents handleEvents)
throws OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters,
UnsupportedMimeType, UnsupportedWindowState, InvalidRegistration, OperationNotSupported
+ {
+ super(producer);
+ this.handleEvents = handleEvents;
+
+ // validate request parameters
+ EventParams eventParams = handleEvents.getEventParams();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(eventParams,
"event params", getContextName());
+
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(eventParams.getPortletStateChange(),
"portletStateChange", "EventParams");
+ List<Event> events = eventParams.getEvents();
+ if (!ParameterValidation.existsAndIsNotEmpty(events))
+ {
+ throw WSRP2ExceptionFactory.createWSException(MissingParameters.class,
+ "EventParams must provide at least one event to process", null);
+ }
+
+ if (events.size() > 1)
+ {
+ throw WSRP2ExceptionFactory.createWSException(OperationNotSupported.class,
+ "GateIn currently doesn't support sending multiple events to process
at once.", null);
+ }
+ prepareInvocation();
+ }
+
+ @Override
+ RegistrationContext getRegistrationContext()
+ {
+ return handleEvents.getRegistrationContext();
+ }
+
+ @Override
+ RuntimeContext getRuntimeContext()
+ {
+ return handleEvents.getRuntimeContext();
+ }
+
+ @Override
+ MimeRequest getParams()
+ {
+ return handleEvents.getMarkupParams();
+ }
+
+ @Override
+ public PortletContext getPortletContext()
+ {
+ return handleEvents.getPortletContext();
+ }
+
+ @Override
+ UserContext getUserContext()
+ {
+ return handleEvents.getUserContext();
+ }
+
+ @Override
+ String getContextName()
+ {
+ return MarkupHandler.HANDLE_EVENTS;
+ }
+
+ @Override
+ AccessMode getAccessMode() throws MissingParameters
+ {
+ StateChange stateChange = handleEvents.getEventParams().getPortletStateChange();
+
+ return WSRPUtils.getAccessModeFromStateChange(stateChange);
+ }
+
+ @Override
+ PortletInvocation initInvocation(WSRPPortletInvocationContext context)
+ {
+ EventInvocation eventInvocation = new EventInvocation(context);
+
+ List<Event> events = handleEvents.getEventParams().getEvents();
+
+ if (events.size() > 1)
+ {
+ throw new NotYetImplemented("Need to support multiple events at
once...");
+ }
+
+ // since we currently don't support sending multiple events to process at once,
assume there's only one
+ Event event = events.get(0);
+
+ eventInvocation.setName(event.getName());
+ EventPayload payload = event.getPayload();
+
+ eventInvocation.setPayload(PayloadUtils.getPayloadAsSerializable(event.getType(),
payload));
+
+ return eventInvocation;
+ }
+
+ @Override
+ public Object processResponse(PortletInvocationResponse response)
+ {
+ if (response instanceof UpdateNavigationalStateResponse)
+ {
+ UpdateNavigationalStateResponse unsResponse =
(UpdateNavigationalStateResponse)response;
+ HandleEventsResponse eventsResponse =
WSRPTypeFactory.createHandleEventsReponse();
+
+ UpdateResponse updateResponse = createUpdateResponse(unsResponse);
+ eventsResponse.setUpdateResponse(updateResponse);
+
+ return eventsResponse;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot process response: " +
response);
+ }
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MarkupRequest.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MarkupRequest.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MarkupRequest.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MarkupRequest.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,130 @@
+/*
+ * 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.handlers.processors;
+
+import org.gatein.pc.api.Mode;
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.WindowState;
+import org.gatein.wsrp.WSRPUtils;
+import org.oasis.wsrp.v2.MarkupType;
+
+import java.util.HashSet;
+import java.util.List;
+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 getMediaTypeWithCharset()
+ {
+ return getMediaType() + CHARSET_SEPARATOR + getCharacterSet();
+ }
+
+ public String getMediaType()
+ {
+ return markupType.getMimeType();
+ }
+
+ public String getLocale()
+ {
+ List<String> locales = markupType.getLocales();
+ if (locales != null && !locales.isEmpty())
+ {
+ return locales.get(0);
+ }
+ else
+ {
+ return WSRPUtils.toString(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<Mode> getSupportedModes()
+ {
+ List<String> modes = markupType.getModes();
+ Set<Mode> result = new HashSet<Mode>(modes.size());
+ for (String mode : modes)
+ {
+ result.add(WSRPUtils.getJSR168PortletModeFromWSRPName(mode));
+ }
+ return result;
+ }
+
+ public Set<WindowState> getSupportedWindowStates()
+ {
+ List<String> states = markupType.getWindowStates();
+ Set<WindowState> result = new HashSet<WindowState>(states.size());
+ for (String state : states)
+ {
+ result.add(WSRPUtils.getJSR168WindowStateFromWSRPName(state));
+ }
+ return result;
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/MimeResponseProcessor.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,127 @@
+/*
+ * 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.handlers.processors;
+
+import org.gatein.common.net.URLTools;
+import org.gatein.pc.api.invocation.response.ContentResponse;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPRewritingConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.servlet.ServletAccess;
+import org.oasis.wsrp.v2.MimeResponse;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+abstract class MimeResponseProcessor<LocalMimeResponse extends MimeResponse>
extends RequestProcessor
+{
+ protected String namespace;
+ private static final String EMPTY = "";
+
+ protected MimeResponseProcessor(WSRPProducerImpl producer)
+ {
+ super(producer);
+ }
+
+ /**
+ * Process String returned from RenderResult to add rewriting token if necessary,
replacing namespaces by the WSRP
+ * rewrite token. fix-me: need to check for producer rewriting
+ *
+ * @param renderString the String to be processed for rewriting marking
+ * @return a String processed to add rewriting tokens as necessary
+ */
+ protected String processFragmentString(String renderString)
+ {
+ String result = renderString.replaceAll(namespace,
WSRPRewritingConstants.WSRP_REWRITE_TOKEN);
+
+ result = URLTools.replaceURLsBy(result, new
WSRPUtils.AbsoluteURLReplacementGenerator(ServletAccess.getRequest()));
+ return result;
+ }
+
+ public Object processResponse(PortletInvocationResponse response)
+ {
+ ContentResponse content = (ContentResponse)response;
+ String itemString = null;
+ byte[] itemBinary = null;
+ String contentType = content.getContentType();
+ switch (content.getType())
+ {
+ case ContentResponse.TYPE_CHARS:
+ itemString = processFragmentString(content.getChars());
+ break;
+ case ContentResponse.TYPE_BYTES:
+ itemBinary = content.getBytes(); // fix-me: might need to convert to Base64?
+ break;
+ case ContentResponse.TYPE_EMPTY:
+ itemString = EMPTY;
+ contentType = markupRequest.getMediaType(); // assume we got what we asked
for :)
+ break;
+ }
+
+ LocalMimeResponse mimeResponse = WSRPTypeFactory.createMimeResponse(contentType,
itemString, itemBinary, getReifiedClass());
+
+ mimeResponse.setLocale(markupRequest.getLocale());
+
+ //TODO: figure out requiresRewriting and useCachedItem
+ Boolean requiresRewriting = true;
+ Boolean useCachedItem = false;
+ mimeResponse.setRequiresRewriting(requiresRewriting);
+ mimeResponse.setUseCachedItem(useCachedItem);
+
+ //TODO: check if anything actually uses the ccpp profile warning
+ String ccppProfileWarning = null;
+ mimeResponse.setCcppProfileWarning(ccppProfileWarning);
+
+ // cache information
+ int expires = content.getCacheControl().getExpirationSecs();
+ // only create a CacheControl if expiration time is not 0
+ if (expires != 0)
+ {
+ // if expires is negative, replace by -1 to make sure
+ if (expires < 0)
+ {
+ expires = -1;
+ }
+
+ mimeResponse.setCacheControl(WSRPTypeFactory.createCacheControl(expires,
WSRPConstants.CACHE_PER_USER));
+ }
+
+ additionallyProcessIfNeeded(mimeResponse, response);
+
+ return createResponse(mimeResponse);
+ }
+
+ protected abstract Object createResponse(LocalMimeResponse mimeResponse);
+
+ protected abstract Class<LocalMimeResponse> getReifiedClass();
+
+ protected void additionallyProcessIfNeeded(LocalMimeResponse mimeResponse,
PortletInvocationResponse response)
+ {
+ // default implementation does nothing
+ }
+}
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProcessorFactory.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,83 @@
+/*
+ * 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.handlers.processors;
+
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
+import org.oasis.wsrp.v2.GetMarkup;
+import org.oasis.wsrp.v2.GetResource;
+import org.oasis.wsrp.v2.HandleEvents;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.MissingParameters;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationNotSupported;
+import org.oasis.wsrp.v2.PerformBlockingInteraction;
+import org.oasis.wsrp.v2.UnsupportedMimeType;
+import org.oasis.wsrp.v2.UnsupportedMode;
+import org.oasis.wsrp.v2.UnsupportedWindowState;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class ProcessorFactory
+{
+ public static RequestProcessor getProcessorFor(WSRPProducerImpl producer, Object
request)
+ throws OperationFailed, UnsupportedMode, InvalidHandle, MissingParameters,
UnsupportedMimeType,
+ UnsupportedWindowState, InvalidRegistration
+ {
+ if (request instanceof GetMarkup)
+ {
+ return new RenderRequestProcessor(producer, (GetMarkup)request);
+ }
+ else if (request instanceof PerformBlockingInteraction)
+ {
+ PerformBlockingInteraction performBlockingInteraction =
(PerformBlockingInteraction)request;
+ return new ActionRequestProcessor(producer, performBlockingInteraction);
+ }
+ else if (request instanceof HandleEvents)
+ {
+ HandleEvents handleEvents = (HandleEvents)request;
+ try
+ {
+ return new EventRequestProcessor(producer, handleEvents);
+ }
+ catch (OperationNotSupported operationNotSupported)
+ {
+ throw WSRP2ExceptionFactory.createWSException(OperationFailed.class,
+ "Couldn't initiate EventRequestProcessor",
operationNotSupported);
+ }
+ }
+ else if (request instanceof GetResource)
+ {
+ GetResource getResource = (GetResource)request;
+ return new ResourceRequestProcessor(producer, getResource);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown request type: " +
request.getClass().getSimpleName());
+ }
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RenderRequestProcessor.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RenderRequestProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.wsrp.producer.handlers.processors;
+
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.pc.api.invocation.RenderInvocation;
+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.WSRPTypeFactory;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.producer.handlers.MarkupHandler;
+import org.oasis.wsrp.v2.GetMarkup;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.MarkupContext;
+import org.oasis.wsrp.v2.MimeRequest;
+import org.oasis.wsrp.v2.MissingParameters;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.RuntimeContext;
+import org.oasis.wsrp.v2.UnsupportedMimeType;
+import org.oasis.wsrp.v2.UnsupportedMode;
+import org.oasis.wsrp.v2.UnsupportedWindowState;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 13121 $
+ * @since 2.6
+ */
+class RenderRequestProcessor extends MimeResponseProcessor<MarkupContext>
+{
+ private final GetMarkup getMarkup;
+
+ public RenderRequestProcessor(WSRPProducerImpl producer, GetMarkup getMarkup) throws
UnsupportedMimeType,
+ UnsupportedWindowState, InvalidHandle, UnsupportedMode, MissingParameters,
InvalidRegistration, OperationFailed
+ {
+ super(producer);
+ this.getMarkup = getMarkup;
+ prepareInvocation();
+ }
+
+ RegistrationContext getRegistrationContext()
+ {
+ return getMarkup.getRegistrationContext();
+ }
+
+ RuntimeContext getRuntimeContext()
+ {
+ return getMarkup.getRuntimeContext();
+ }
+
+ MimeRequest getParams()
+ {
+ return getMarkup.getMarkupParams();
+ }
+
+ public PortletContext getPortletContext()
+ {
+ return getMarkup.getPortletContext();
+ }
+
+ org.oasis.wsrp.v2.UserContext getUserContext()
+ {
+ return getMarkup.getUserContext();
+ }
+
+ String getContextName()
+ {
+ return MarkupHandler.GET_MARKUP;
+ }
+
+ AccessMode getAccessMode()
+ {
+ return AccessMode.READ_ONLY;
+ }
+
+ @Override
+ PortletInvocation initInvocation(WSRPPortletInvocationContext context)
+ {
+ // MUST match namespace generation used in PortletResponseImpl.getNamespace in
portlet module...
+ namespace =
PortletUtils.generateNamespaceFrom(context.getWindowContext().getId());
+
+ return new RenderInvocation(context);
+ }
+
+ @Override
+ protected Object createResponse(MarkupContext mimeResponse)
+ {
+ return WSRPTypeFactory.createMarkupResponse(mimeResponse);
+ }
+
+ @Override
+ protected Class<MarkupContext> getReifiedClass()
+ {
+ return MarkupContext.class;
+ }
+
+ @Override
+ protected void additionallyProcessIfNeeded(MarkupContext markupContext,
PortletInvocationResponse response)
+ {
+ markupContext.setPreferredTitle(portletDescription.getTitle().getValue());
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RequestProcessor.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/RequestProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,518 @@
+/*
+ * 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.handlers.processors;
+
+import org.gatein.common.net.media.MediaType;
+import org.gatein.common.util.MarkupInfo;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.Mode;
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.StateString;
+import org.gatein.pc.api.WindowState;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.pc.api.spi.PortalContext;
+import org.gatein.pc.api.spi.SecurityContext;
+import org.gatein.pc.api.spi.UserContext;
+import org.gatein.pc.api.spi.WindowContext;
+import org.gatein.pc.api.state.AccessMode;
+import org.gatein.registration.Registration;
+import org.gatein.wsrp.UserContextConverter;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.producer.Utils;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.spec.v2.WSRP2ExceptionFactory;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+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;
+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.RuntimeContext;
+import org.oasis.wsrp.v2.SessionParams;
+import org.oasis.wsrp.v2.UnsupportedMimeType;
+import org.oasis.wsrp.v2.UnsupportedMode;
+import org.oasis.wsrp.v2.UnsupportedWindowState;
+
+import java.security.Principal;
+import java.util.ArrayList;
+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: 13121 $
+ * @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 InvalidRegistration, OperationFailed, InvalidHandle,
+ UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode, MissingParameters
+ {
+ Registration registration =
producer.getRegistrationOrFailIfInvalid(getRegistrationContext());
+
+ // get session information and deal with it
+ final RuntimeContext runtimeContext = getRuntimeContext();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(runtimeContext,
"RuntimeContext", getContextName());
+
+ checkForSessionIDs(runtimeContext);
+
+ // get parameters
+ final MimeRequest params = getParams();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(params,
"MarkupParams", getContextName());
+
+ // get portlet handle
+ PortletContext wsrpPC = getPortletContext();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(wsrpPC,
"PortletContext", getContextName());
+ org.gatein.pc.api.PortletContext portletContext =
WSRPUtils.convertToPortalPortletContext(wsrpPC);
+
+ // retrieve the portlet
+ try
+ {
+ // calls RegistrationLocal.setRegistration so no need to here
+ portlet = producer.getPortletWith(portletContext, registration);
+ }
+ catch (PortletInvokerException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could
not retrieve portlet '" + portletContext + "'", e);
+ }
+
+ // get portlet description for the desired portlet...
+ final List<String> desiredLocales = params.getLocales();
+ portletDescription = producer.getPortletDescription(portlet, desiredLocales);
+ if (Boolean.TRUE.equals(portletDescription.isUsesMethodGet()))
+ {
+ throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Portlets using GET method in forms are not currently supported.", null);
+ }
+
+ List<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
+ final org.oasis.wsrp.v2.UserContext wsrpUserContext = getUserContext();
+ checkUserContext(wsrpUserContext);
+
+ SecurityContext securityContext = createSecurityContext(params, runtimeContext,
wsrpUserContext);
+ MarkupInfo streamInfo = createStreamInfo(markupRequest);
+ PortalContext portalContext = createPortalContext(params, markupRequest);
+ UserContext userContext = createUserContext(wsrpUserContext,
markupRequest.getLocale(), desiredLocales);
+ instanceContext = createInstanceContext(portletContext, getAccessMode(),
runtimeContext.getPortletInstanceKey());
+ WindowContext windowContext = createWindowContext(portletContext.getId(),
runtimeContext);
+
+ // prepare the invocation
+ WSRPPortletInvocationContext context = new WSRPPortletInvocationContext(streamInfo,
securityContext, portalContext, userContext, instanceContext, windowContext);
+ PortletInvocation invocation = initInvocation(context);
+
+ invocation.setTarget(portlet.getContext());
+
invocation.setWindowState(WSRPUtils.getJSR168WindowStateFromWSRPName(markupRequest.getWindowState()));
+
invocation.setMode(WSRPUtils.getJSR168PortletModeFromWSRPName(markupRequest.getMode()));
+
+ NavigationalContext navigationalContext = params.getNavigationalContext();
+ if (navigationalContext != null)
+ {
+ StateString navigationalState =
createNavigationalState(navigationalContext.getOpaqueValue());
+ invocation.setNavigationalState(navigationalState);
+
+ List<NamedString> publicParams = navigationalContext.getPublicValues();
+ if (ParameterValidation.existsAndIsNotEmpty(publicParams))
+ {
+ Map<String, String[]> publicNS =
WSRPUtils.createPublicNSFrom(publicParams);
+ invocation.setPublicNavigationalState(publicNS);
+ }
+ }
+
+ context.contextualize(invocation);
+ setInvocation(invocation);
+ }
+
+ abstract RegistrationContext getRegistrationContext();
+
+ abstract RuntimeContext getRuntimeContext();
+
+ abstract MimeRequest getParams();
+
+ public abstract PortletContext getPortletContext();
+
+ abstract org.oasis.wsrp.v2.UserContext getUserContext();
+
+ abstract String getContextName();
+
+ abstract AccessMode getAccessMode() throws MissingParameters;
+
+ abstract PortletInvocation initInvocation(WSRPPortletInvocationContext context);
+
+ public 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(List<MarkupType> markupTypes,
MimeRequest params, Portlet portlet)
+ throws UnsupportedMimeType, UnsupportedMode, UnsupportedWindowState
+ {
+ List<String> desiredMIMETypes = params.getMimeTypes();
+ MarkupType markupType = null;
+
+ // Get the MIME type to use
+ for (String desiredMIMEType : desiredMIMETypes)
+ {
+ for (MarkupType type : markupTypes)
+ {
+ if (desiredMIMEType.equals(type.getMimeType()))
+ {
+ markupType = type;
+ break;
+ }
+ }
+ }
+
+ // no MIME type was found: error!
+ if (markupType == null)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(UnsupportedMimeType.class,
"None of the specified MIME types are supported by portlet '" +
portlet.getContext().getId() + "'", null);
+ }
+
+ // use user-desired locales
+ List<String> locales = params.getLocales();
+ List<String> supportedLocales = new
ArrayList<String>(markupType.getLocales());
+ if (supportedLocales != null)
+ {
+ // reset markup type locales
+ markupType.getLocales().clear();
+ boolean found = false;
+
+ // find the best match
+ for (String locale : locales)
+ {
+ for (String supportedLocale : supportedLocales)
+ {
+ if (locale.equals(supportedLocale))
+ {
+ markupType.getLocales().add(locale);
+ found = true;
+ break;
+ }
+ }
+
+ if (found)
+ {
+ break;
+ }
+ }
+
+ // if no best match was found, use whatever the user gave us
+ if (!found)
+ {
+ markupType.getLocales().addAll(locales);
+ }
+ }
+ else
+ {
+ markupType.getLocales().addAll(locales);
+ }
+
+ // get the mode
+ String mode;
+ try
+ {
+ mode = getMatchingOrFailFrom(markupType.getModes(), params.getMode(),
PORTLET_MODE);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(UnsupportedMode.class,
"Unsupported mode '" + params.getMode() + "'", e);
+ }
+
+ // get the window state
+ String windowState;
+ try
+ {
+ windowState = getMatchingOrFailFrom(markupType.getWindowStates(),
params.getWindowState(), WINDOW_STATE);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(UnsupportedWindowState.class,
"Unsupported window state '" + params.getWindowState() + "'",
e);
+ }
+
+ // get the character set
+ String characterSet =
getMatchingOrDefaultFrom(Collections.<String>emptyList(),
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(List<String> possibleValues, String
desired, String valueType) throws IllegalArgumentException
+ {
+ if (possibleValues.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(List<String> possibleValues,
List<String> preferredValues, String defaultValue)
+ {
+ if (preferredValues != null && possibleValues != null)
+ {
+ for (String preferredValue : preferredValues)
+ {
+ if (possibleValues.contains(preferredValue))
+ {
+ return preferredValue;
+ }
+ }
+ }
+
+ return defaultValue;
+ }
+
+ private void checkUserContext(org.oasis.wsrp.v2.UserContext wsrpUserContext) throws
MissingParameters
+ {
+ if (wsrpUserContext != null)
+ {
+
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(wsrpUserContext.getUserContextKey(),
"User Context Key", "UserContext");
+ }
+ }
+
+
+ private void checkForSessionIDs(RuntimeContext runtimeContext) throws OperationFailed
+ {
+ SessionParams sessionParams = runtimeContext.getSessionParams();
+ if (sessionParams != null && sessionParams.getSessionID() != null)
+ {
+ Utils.throwOperationFaultOnSessionOperation();
+ }
+ }
+
+ protected StateString createNavigationalState(String navigationalState)
+ {
+ if (navigationalState == null)
+ {
+ return null;
+ }
+ else
+ {
+ return StateString.create(navigationalState);
+ }
+ }
+
+ private WSRPInstanceContext createInstanceContext(org.gatein.pc.api.PortletContext
portletContext, final AccessMode accessMode, String instanceId)
+ {
+ return new WSRPInstanceContext(portletContext, accessMode, instanceId);
+ }
+
+ 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.oasis.wsrp.v2.UserContext
userContext,
+ String preferredLocale, final List<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 MimeRequest params, final
MarkupRequest markupRequest)
+ {
+ return new PortalContext()
+ {
+
+ public String getInfo()
+ {
+ return PortalContext.VERSION.toString();
+ }
+
+ public Set<WindowState> getWindowStates()
+ {
+ List<String> validNewWindowStates = params.getValidNewWindowStates();
+ if (ParameterValidation.existsAndIsNotEmpty(validNewWindowStates))
+ {
+ Set<WindowState> states = new
HashSet<WindowState>(validNewWindowStates.size());
+ for (String state : validNewWindowStates)
+ {
+ states.add(WSRPUtils.getJSR168WindowStateFromWSRPName(state));
+ }
+ return states;
+ }
+ return markupRequest.getSupportedWindowStates();
+ }
+
+ public Set<Mode> getModes()
+ {
+ List<String> validNewModes = params.getValidNewModes();
+ if (ParameterValidation.existsAndIsNotEmpty(validNewModes))
+ {
+ Set<Mode> modes = new HashSet<Mode>(validNewModes.size());
+ for (String mode : validNewModes)
+ {
+ modes.add(WSRPUtils.getJSR168PortletModeFromWSRPName(mode));
+ }
+ return modes;
+ }
+ return markupRequest.getSupportedModes();
+ }
+
+ public Map<String, String> getProperties()
+ {
+ return Collections.emptyMap();
+ }
+ };
+ }
+
+ private MarkupInfo createStreamInfo(MarkupRequest markupRequest) throws
UnsupportedMimeType
+ {
+ MarkupInfo markupInfo;
+ try
+ {
+ markupInfo = new MarkupInfo(MediaType.create(markupRequest.getMediaType()),
markupRequest.getCharacterSet());
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw WSRP2ExceptionFactory.throwWSException(UnsupportedMimeType.class,
e.getLocalizedMessage(), e);
+ }
+ return markupInfo;
+ }
+
+ // fix-me: check that the correct semantics is used.
+
+ private SecurityContext createSecurityContext(final MimeRequest params, final
RuntimeContext runtimeContext,
+ final org.oasis.wsrp.v2.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)
+ {
+ return wsrpUserContext != null &&
wsrpUserContext.getUserCategories().contains(roleName);
+ }
+
+ public boolean isAuthenticated()
+ {
+ return wsrpUserContext != null;
+ }
+ };
+ }
+
+ public PortletInvocation getInvocation()
+ {
+ return invocation;
+ }
+
+ public void setInvocation(PortletInvocation invocation)
+ {
+ this.invocation = invocation;
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ResourceRequestProcessor.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ResourceRequestProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,160 @@
+/*
+ * 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.handlers.processors;
+
+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.state.AccessMode;
+import org.gatein.pc.portlet.impl.jsr168.PortletUtils;
+import org.gatein.wsrp.WSRPResourceURL;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.gatein.wsrp.producer.handlers.MarkupHandler;
+import org.oasis.wsrp.v2.GetResource;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+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.RegistrationContext;
+import org.oasis.wsrp.v2.ResourceContext;
+import org.oasis.wsrp.v2.ResourceParams;
+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$
+ */
+class ResourceRequestProcessor extends MimeResponseProcessor<ResourceContext>
+{
+ private final GetResource getResource;
+
+ public ResourceRequestProcessor(WSRPProducerImpl producer, GetResource getResource)
throws InvalidRegistration, OperationFailed, MissingParameters, InvalidHandle,
UnsupportedMimeType, UnsupportedWindowState, UnsupportedMode
+ {
+ super(producer);
+ this.getResource = getResource;
+ prepareInvocation();
+ }
+
+ public PortletContext getPortletContext()
+ {
+ return getResource.getPortletContext();
+ }
+
+ @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();
+
+ // only set the resource id if it's different from the place holder we use if
the portlet doesn't set one
+ String id = this.getResource.getResourceParams().getResourceID();
+ if (!WSRPResourceURL.DEFAULT_RESOURCE_ID.equals(id))
+ {
+ resourceInvocation.setResourceId(id);
+ }
+
+ 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()));
+
+ String resourceCacheability = resourceParams.getResourceCacheability();
+ if (resourceCacheability != null)
+ {
+ CacheLevel cacheLevel =
WSRPUtils.getCacheLevelFromResourceCacheability(resourceParams.getResourceCacheability());
+ resourceInvocation.setCacheLevel(cacheLevel);
+ }
+ else
+ {
+ // according to JSR 286, cache level must default to ResourceURL.PAGE
+ resourceInvocation.setCacheLevel(CacheLevel.PAGE);
+ }
+
+ return resourceInvocation;
+ }
+
+ @Override
+ protected Object createResponse(ResourceContext resourceContext)
+ {
+ return WSRPTypeFactory.createResourceResponse(resourceContext);
+ }
+
+ @Override
+ protected Class<ResourceContext> getReifiedClass()
+ {
+ return ResourceContext.class;
+ }
+}
+
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/UpdateNavigationalStateResponseProcessor.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/UpdateNavigationalStateResponseProcessor.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,83 @@
+/*
+ * 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.handlers.processors;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
+import org.oasis.wsrp.v2.NavigationalContext;
+import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.UpdateResponse;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+abstract class UpdateNavigationalStateResponseProcessor extends RequestProcessor
+{
+ public UpdateNavigationalStateResponseProcessor(WSRPProducerImpl producer)
+ {
+ super(producer);
+ }
+
+ protected String getNewStateOrNull(UpdateNavigationalStateResponse renderResult,
boolean forMode)
+ {
+ Object state = forMode ? renderResult.getMode() : renderResult.getWindowState();
+ return state != null ? state.toString() : null;
+ }
+
+ protected UpdateResponse createUpdateResponse(UpdateNavigationalStateResponse
stateResponse)
+ {
+ UpdateResponse updateResponse = WSRPTypeFactory.createUpdateResponse();
+
updateResponse.setNewMode(WSRPUtils.convertJSR168PortletModeNameToWSRPName(getNewStateOrNull(stateResponse,
true)));
+
updateResponse.setNewWindowState(WSRPUtils.convertJSR168WindowStateNameToWSRPName(getNewStateOrNull(stateResponse,
false)));
+ NavigationalContext navigationalContext =
WSRPTypeFactory.createNavigationalContextOrNull(
+ stateResponse.getNavigationalState(),
+ stateResponse.getPublicNavigationalStateUpdates()
+ );
+ updateResponse.setNavigationalContext(navigationalContext);
+
+ // events
+ List<UpdateNavigationalStateResponse.Event> events =
stateResponse.getEvents();
+ if (ParameterValidation.existsAndIsNotEmpty(events))
+ {
+ for (UpdateNavigationalStateResponse.Event event : events)
+ {
+ updateResponse.getEvents().add(WSRPTypeFactory.createEvent(event.getName(),
event.getPayload()));
+ }
+ }
+
+ // deal with implicit cloning and state modification
+ if (instanceContext.wasModified())
+ {
+ PortletContext updatedPortletContext =
WSRPUtils.convertToWSRPPortletContext(instanceContext.getPortletContext());
+ updateResponse.setPortletContext(updatedPortletContext);
+ }
+ return updateResponse;
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPInstanceContext.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPInstanceContext.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPInstanceContext.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPInstanceContext.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.wsrp.producer.handlers.processors;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletStateType;
+import org.gatein.pc.api.StateEvent;
+import org.gatein.pc.api.StatefulPortletContext;
+import org.gatein.pc.api.spi.InstanceContext;
+import org.gatein.pc.api.state.AccessMode;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+class WSRPInstanceContext implements InstanceContext
+{
+ private PortletContext context;
+ private String instanceId;
+ private final AccessMode accessMode;
+ private boolean wasModified = false;
+
+ public WSRPInstanceContext(PortletContext portletContext, AccessMode accessMode,
String instanceId)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "portlet
context");
+ ParameterValidation.throwIllegalArgExceptionIfNull(accessMode,
"AccessMode");
+
+ this.context = portletContext;
+ this.accessMode = accessMode;
+
+ if (instanceId != null && instanceId.length() > 0)
+ {
+ this.instanceId = instanceId;
+ }
+ else
+ {
+ this.instanceId = portletContext.getId();
+ }
+ }
+
+ public String getId()
+ {
+ return instanceId;
+ }
+
+ public AccessMode getAccessMode()
+ {
+ return accessMode;
+ }
+
+ public void onStateEvent(StateEvent event)
+ {
+ PortletContext portletContext = event.getPortletContext();
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletContext,
"PortletContext");
+ wasModified = true;
+ context = portletContext;
+ }
+
+ public boolean wasModified()
+ {
+ return wasModified;
+ }
+
+ PortletContext getPortletContext()
+ {
+ return context;
+ }
+
+ public PortletStateType<?> getStateType()
+ {
+ if (context instanceof StatefulPortletContext)
+ {
+ StatefulPortletContext spc = (StatefulPortletContext)context;
+ return spc.getType();
+ }
+ else
+ {
+ return PortletStateType.OPAQUE;
+ }
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPPortletInvocationContext.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPPortletInvocationContext.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPPortletInvocationContext.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPPortletInvocationContext.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,156 @@
+/*
+ * 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.handlers.processors;
+
+import org.gatein.common.net.URLTools;
+import org.gatein.common.util.MarkupInfo;
+import org.gatein.pc.api.ContainerURL;
+import org.gatein.pc.api.URLFormat;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.pc.api.spi.PortalContext;
+import org.gatein.pc.api.spi.PortletInvocationContext;
+import org.gatein.pc.api.spi.SecurityContext;
+import org.gatein.pc.api.spi.UserContext;
+import org.gatein.pc.api.spi.WindowContext;
+import org.gatein.pc.portlet.impl.spi.AbstractClientContext;
+import org.gatein.pc.portlet.impl.spi.AbstractPortletInvocationContext;
+import org.gatein.pc.portlet.impl.spi.AbstractServerContext;
+import org.gatein.wsrp.WSRPPortletURL;
+import org.gatein.wsrp.WSRPRewritingConstants;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.servlet.ServletAccess;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 13121 $
+ */
+class WSRPPortletInvocationContext extends AbstractPortletInvocationContext implements
PortletInvocationContext
+{
+ private SecurityContext securityContext;
+ private PortalContext portalContext;
+ private UserContext userContext;
+ private WSRPInstanceContext instanceContext;
+ private WindowContext windowContext;
+
+ private static final String EQ = "=";
+ private static final String AMP = "&";
+ private static final String EQ_TRUE = "=true";
+ private HttpServletRequest request;
+ private HttpServletResponse response;
+
+ public WSRPPortletInvocationContext(MarkupInfo markupInfo, SecurityContext
securityContext, PortalContext portalContext, UserContext userContext,
+ WSRPInstanceContext instanceContext, WindowContext
windowContext)
+ {
+ super(markupInfo);
+
+ this.securityContext = securityContext;
+ this.portalContext = portalContext;
+ this.userContext = userContext;
+ this.instanceContext = instanceContext;
+ this.windowContext = windowContext;
+
+ request = ServletAccess.getRequest();
+ response = ServletAccess.getResponse();
+ }
+
+ public HttpServletRequest getClientRequest()
+ {
+ return request;
+ }
+
+ public HttpServletResponse getClientResponse()
+ {
+ return response;
+ }
+
+ /** Override the default behavior in order to avoid to encode when it is producer
written URL. */
+ public String encodeResourceURL(String url)
+ {
+ if (url != null &&
!url.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE))
+ {
+ // make root relative URLs absolute. Optimization: we don't recheck the
presence of the WSRP token.
+ url = WSRPUtils.getAbsoluteURLFor(url, false,
URLTools.getServerAddressFrom(getClientRequest()));
+
+ // properly encode the URL
+ url = URLTools.encodeXWWWFormURL(url);
+
+ // build the WSRP resource URL with rewrite tokens
+ StringBuffer sb = new StringBuffer(url.length() * 2);
+
sb.append(WSRPRewritingConstants.BEGIN_WSRP_REWRITE).append(WSRPRewritingConstants.URL_TYPE_NAME)
+ .append(EQ).append(WSRPRewritingConstants.URL_TYPE_RESOURCE).append(AMP)
+ .append(WSRPRewritingConstants.RESOURCE_URL).append(EQ).append(url)
+ .append(AMP).append(WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE)
+ .append(EQ_TRUE).append(WSRPRewritingConstants.END_WSRP_REWRITE);
+ return sb.toString();
+ }
+
+ return url;
+ }
+
+ /**
+ * <p>URL to be re-written are of the form:
<code>wsrp_rewrite?wsrp-urlType=value&amp;name1=value1&amp;name2=value2
+ * .../wsrp_rewrite</code> </p> <ul>Examples: <li>Load a
resource
http://test.com/images/test.gif: <br/>
+ *
<code>wsrp_rewrite?wsrp-urlType=resource&amp;wsrp-url=http%3A%2F%2Ftest.com%2Fimages%2Ftest.gif&amp;wsrp-requiresRewrite=true/wsrp_rewrite</code></li>
+ * <li>Declare a secure interaction back to the Portlet:<br/>
<code>wsrp_rewrite?wsrp-urlType=blockingAction&amp;wsrp-secureURL=true&amp;wsrp-navigationalState=a8h4K5JD9&amp;wsrp-interactionState=fg4h923mdk/wsrp_rewrite</code></li>
+ * <li>Request the Consumer render the Portlet in a different mode and window
state:
+ *
<code>wsrp_rewrite?wsrp-urlType=render&amp;wsrp-mode=help&amp;wsrp-windowState=maximized/wsrp_rewrite</code></li>
+ * </ul>
+ *
+ * @param containerURL
+ * @param urlFormat
+ * @return
+ */
+ public String renderURL(ContainerURL containerURL, URLFormat urlFormat)
+ {
+ if (containerURL != null)
+ {
+ Boolean wantSecureBool = urlFormat.getWantSecure();
+ boolean wantSecure = (wantSecureBool != null ? wantSecureBool : false);
+ WSRPPortletURL url = WSRPPortletURL.create(containerURL, wantSecure);
+ return url.toString();
+ }
+ return null;
+ }
+
+ public void contextualize(PortletInvocation invocation)
+ {
+ invocation.setClientContext(new AbstractClientContext(request));
+ invocation.setServerContext(new AbstractServerContext(request, response));
+
+ invocation.setSecurityContext(securityContext);
+ invocation.setInstanceContext(instanceContext);
+ invocation.setWindowContext(windowContext);
+ invocation.setPortalContext(portalContext);
+ invocation.setUserContext(userContext);
+ }
+
+ WindowContext getWindowContext()
+ {
+ return windowContext;
+ }
+}
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPRequestContext.java
(from rev 3803,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPRequestContext.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPRequestContext.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/WSRPRequestContext.java 2010-08-11
13:15:34 UTC (rev 3804)
@@ -0,0 +1,262 @@
+/*
+ * 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.handlers.processors;
+
+import org.apache.commons.fileupload.FileUpload;
+import org.gatein.common.util.ParameterMap;
+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;
+import javax.mail.internet.InternetHeaders;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMultipart;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 10337 $
+ */
+abstract class WSRPRequestContext implements RequestContext,
org.apache.commons.fileupload.RequestContext
+{
+ protected String characterEncoding;
+
+ protected WSRPRequestContext(String characterEncoding)
+ {
+ this.characterEncoding = characterEncoding;
+ }
+
+ public String getCharacterEncoding()
+ {
+ return characterEncoding;
+ }
+
+ public int getContentLength()
+ {
+ throw new UnsupportedOperationException("Not currently supported");
+ }
+
+ public BufferedReader getReader() throws IOException
+ {
+ throw new UnsupportedOperationException("Not currently supported");
+ }
+
+ public InputStream getInputStream() throws IOException
+ {
+ throw new UnsupportedOperationException("Not currently supported");
+ }
+
+ public abstract ParameterMap getForm();
+
+ static class WSRPSimpleRequestContext extends WSRPRequestContext
+ {
+ private ParameterMap formParameters;
+ private String contentType;
+
+ protected WSRPSimpleRequestContext(String characterEncoding, String contentType,
List<NamedString> formParams)
+ {
+ super(characterEncoding);
+ this.contentType = contentType;
+
+ if (formParams != null && !formParams.isEmpty())
+ {
+ Map<String, String[]> params = new HashMap<String,
String[]>(formParams.size());
+ for (NamedString formParam : formParams)
+ {
+ String paramName = formParam.getName();
+ String paramValue = formParam.getValue();
+ if (params.containsKey(paramName))
+ {
+ // handle multi-valued parameters...
+ String[] oldValues = 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});
+ }
+ formParameters = new ParameterMap(params);
+ }
+ }
+ else
+ {
+ formParameters = new ParameterMap();
+ }
+
+ }
+
+ public ParameterMap getForm()
+ {
+ return formParameters;
+ }
+
+ public String getContentType()
+ {
+ return contentType;
+ }
+ }
+
+ static class WSRPMultiRequestContext extends WSRPRequestContext
+ {
+ private byte[] content;
+ private boolean usingStream;
+ private boolean usingReader;
+ private String contentType;
+
+ protected WSRPMultiRequestContext(String characterEncoding, List<NamedString>
formParams, List<UploadContext> uploadContexts) throws IOException,
MessagingException
+ {
+ super(characterEncoding);
+
+ MimeMultipart parts = new MimeMultipart();
+ if (uploadContexts != null && !uploadContexts.isEmpty())
+ {
+ for (UploadContext uploadContext : uploadContexts)
+ {
+ InternetHeaders headers = new InternetHeaders();
+ headers.addHeader(FileUpload.CONTENT_TYPE, uploadContext.getMimeType());
+
+ List<NamedString> attributes = uploadContext.getMimeAttributes();
+ if (attributes != null && !attributes.isEmpty())
+ {
+ for (NamedString attribute : attributes)
+ {
+ headers.addHeader(attribute.getName(), attribute.getValue());
+ }
+ }
+
+ MimeBodyPart mimeBodyPart = new MimeBodyPart(headers,
uploadContext.getUploadData());
+ parts.addBodyPart(mimeBodyPart);
+ }
+ }
+
+ final String paramContentDispositionHeader = FileUpload.FORM_DATA + ";
name=\"";
+ if (formParams != null)
+ {
+ for (NamedString formParam : formParams)
+ {
+ InternetHeaders headers = new InternetHeaders();
+
+ StringBuffer paramContentDisposition = new
StringBuffer(paramContentDispositionHeader);
+
paramContentDisposition.append(formParam.getName()).append("\"");
+
+ headers.addHeader(FileUpload.CONTENT_DISPOSITION,
paramContentDisposition.toString());
+
+ MimeBodyPart mimeBodyPart = new MimeBodyPart(headers,
formParam.getValue().getBytes());
+ parts.addBodyPart(mimeBodyPart);
+ }
+ }
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ parts.writeTo(baos);
+ content = baos.toByteArray();
+ contentType = parts.getContentType();
+ }
+
+ public ParameterMap getForm()
+ {
+ return new ParameterMap();
+ }
+
+ public String getContentType()
+ {
+ return contentType;
+ }
+
+ public int getContentLength()
+ {
+ return content.length;
+ }
+
+ public BufferedReader getReader() throws IOException
+ {
+ if (usingStream)
+ {
+ throw new IllegalStateException("getInputStream has already been called
on this ActionContext!");
+ }
+ usingReader = true;
+ return new BufferedReader(new InputStreamReader(getInputStreamFromContent()));
+ }
+
+ public InputStream getInputStream() throws IOException
+ {
+ if (usingReader)
+ {
+ throw new IllegalStateException("getReader has already been called on
this ActionContext!");
+ }
+ usingStream = true;
+ return getInputStreamFromContent();
+ }
+
+
+ private InputStream getInputStreamFromContent()
+ {
+ return new ByteArrayInputStream(content);
+ }
+ }
+
+ public static WSRPRequestContext createRequestContext(MarkupRequest markupRequest,
InteractionParams interactionParams)
+ {
+ 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
+ {
+ return new WSRPMultiRequestContext(markupRequest.getCharacterSet(),
formParams, uploadContexts);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Invalid upload contexts", e);
+ }
+ }
+ else
+ {
+ return new WSRPSimpleRequestContext(markupRequest.getCharacterSet(),
markupRequest.getMediaType(), formParams);
+
+ }
+ }
+}