Author: chris.laprun(a)jboss.com
Date: 2010-06-15 18:34:17 -0400 (Tue, 15 Jun 2010)
New Revision: 3344
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java
Log:
- GTNWSRP-45: Started re-implementing service description handling so that we can cache
data. Right now, only registration properties are cached as caching portlet information
will require PC-level support. NOT TESTED.
- GTNWSRP-38, GTNWSRP-39: Started adding PRP and event information in portlet and service
descriptions. NOT TESTED.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-06-15
22:29:02 UTC (rev 3343)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-06-15
22:34:17 UTC (rev 3344)
@@ -45,6 +45,7 @@
import org.oasis.wsrp.v2.ClonePortlet;
import org.oasis.wsrp.v2.DestroyPortlets;
import org.oasis.wsrp.v2.DestroyPortletsResponse;
+import org.oasis.wsrp.v2.EventDescription;
import org.oasis.wsrp.v2.FailedPortlets;
import org.oasis.wsrp.v2.GetMarkup;
import org.oasis.wsrp.v2.GetPortletDescription;
@@ -62,6 +63,7 @@
import org.oasis.wsrp.v2.ModifyRegistration;
import org.oasis.wsrp.v2.NamedString;
import org.oasis.wsrp.v2.NavigationalContext;
+import org.oasis.wsrp.v2.ParameterDescription;
import org.oasis.wsrp.v2.PerformBlockingInteraction;
import org.oasis.wsrp.v2.PortletContext;
import org.oasis.wsrp.v2.PortletDescription;
@@ -264,7 +266,7 @@
/** ====== WSRP Response objects ====== * */
public static BlockingInteractionResponse
createBlockingInteractionResponse(UpdateResponse updateResponse)
- {
+ {
if (updateResponse == null)
{
throw new IllegalArgumentException("BlockingInteractionResponse requires
either an UpdateResponse or a redirect URL.");
@@ -290,23 +292,6 @@
return new UpdateResponse();
}
- public static PortletDescription
createPortletDescription(org.gatein.pc.api.PortletContext portletContext,
List<MarkupType> markupTypes)
- {
- PortletContext context = WSRPUtils.convertToWSRPPortletContext(portletContext);
-
- ParameterValidation.throwIllegalArgExceptionIfNull(markupTypes,
"MarkupType");
- if (markupTypes.isEmpty())
- {
- throw new IllegalArgumentException("Cannot create a PortletDescription with
an empty list of MarkupTypes!");
- }
-
- PortletDescription portletDescription = new PortletDescription();
- portletDescription.setPortletHandle(context.getPortletHandle());
- portletDescription.getMarkupTypes().addAll(markupTypes);
-
- return portletDescription;
- }
-
public static PortletDescription createPortletDescription(String portletHandle,
List<MarkupType> markupTypes)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletHandle,
"portlet handle", null);
@@ -1155,4 +1140,20 @@
return null;
}
+
+ public static ParameterDescription createParameterDescription(String identifier)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(identifier,
"Parameter identifier", null);
+ ParameterDescription desc = new ParameterDescription();
+ desc.setIdentifier(identifier);
+ return desc;
+ }
+
+ public static EventDescription createEventDescription(QName name)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(name, "name");
+ EventDescription desc = new EventDescription();
+ desc.setName(name);
+ return desc;
+ }
}
Modified:
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-06-15
22:29:02 UTC (rev 3343)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java 2010-06-15
22:34:17 UTC (rev 3344)
@@ -27,24 +27,33 @@
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.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;
@@ -54,7 +63,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -65,29 +73,24 @@
* @version $Revision: 12017 $
* @since 2.4
*/
-class
- ServiceDescriptionHandler extends ServiceHandler implements
ServiceDescriptionInterface
+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 final CookieProtocol BEA_8_CONSUMER_FIX = CookieProtocol.PER_USER;
+ 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, OperationFailed
+ public ServiceDescription getServiceDescription(GetServiceDescription gs) throws
InvalidRegistration, OperationFailed
{
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(gs,
"GetServiceDescription");
RegistrationContext registrationContext = gs.getRegistrationContext();
- ProducerRegistrationRequirements requirements =
producer.getProducerRegistrationRequirements();
- ServiceDescription serviceDescription =
WSRPTypeFactory.createServiceDescription(requirements.isRegistrationRequired());
- serviceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
- serviceDescription.getLocales().addAll(producer.getSupportedLocales());
-
// if a RegistrationContext is provided, we need to validate the registration
information
Registration registration = null;
if (registrationContext != null)
@@ -95,57 +98,35 @@
registration = producer.getRegistrationOrFailIfInvalid(registrationContext);
}
- // get the portlet descriptions based on registration information
- List<PortletDescription> offeredPortlets =
getPortletDescriptions(gs.getDesiredLocales(), registration);
- if (offeredPortlets != null)
+ ProducerRegistrationRequirements requirements =
producer.getProducerRegistrationRequirements();
+
+ // if we don't have registration information but a registration is required,
send registration props information
+ boolean needsRegistrationProperties = registration == null &&
requirements.isRegistrationRequired();
+ if (needsRegistrationProperties)
{
- serviceDescription.getOfferedPortlets().addAll(offeredPortlets);
+ serviceDescription.updateRegistrationProperties(requirements);
}
- // if we don't have registration information but a registration is required,
send registration props information
- if (registration == null && requirements.isRegistrationRequired())
+ boolean needsPortletDescriptions = registration == null &&
requirements.isRegistrationRequired()
+ && requirements.isRegistrationRequiredForFullDescription();
+ if (needsPortletDescriptions)
{
- log.debug("Unregistered consumer while registration is required. Sending
registration information.");
-
- // do not create a ModelDescription if there is no registration properties
- Map<QName, RegistrationPropertyDescription> info =
requirements.getRegistrationProperties();
- ModelDescription description = null;
- if (info != null && !info.isEmpty())
+ Set<Portlet> portlets;
+ try
{
- description = Utils.convertRegistrationPropertiesToModelDescription(info);
+ portlets = producer.getRemotablePortlets();
}
-
- serviceDescription.setRegistrationPropertyDescription(description);
+ 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;
+ return serviceDescription.getServiceDescription(needsRegistrationProperties,
needsPortletDescriptions);
}
-
- private Set<PortletDescription> getOfferedPortletDescriptions(List<String>
desiredLocales)
- {
- Set<Portlet> portlets;
- try
- {
- portlets = producer.getRemotablePortlets();
- }
- catch (PortletInvokerException e)
- {
- log.warn("Could not retrieve portlets. Reason:\n\t" +
e.getLocalizedMessage());
- return Collections.emptySet();
- }
-
- Set<PortletDescription> offeredPortletDescriptions = new
HashSet<PortletDescription>(portlets.size());
-
- for (Portlet portlet : portlets)
- {
- PortletDescription desc = getPortletDescription(portlet, desiredLocales);
- offeredPortletDescriptions.add(desc);
- }
-
- return offeredPortletDescriptions;
- }
-
public PortletDescription getPortletDescription(PortletContext portletContext,
List<String> desiredLocales, Registration registration) throws InvalidHandle,
OperationFailed
{
ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "portlet
context");
@@ -162,22 +143,16 @@
}
/**
- * @param desiredLocales the locales in which the portlet descriptions must be
provided (best effort)
- * @param registration used to filter offered portlet lists
- * @return an array of portlet descriptions offered by this producer (which could be
filtered based on the
- * registration information) or <code>null</code> if no
registration is provided and the producer requires
- * registration to access the full service description.
+ * 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
*/
- private List<PortletDescription> getPortletDescriptions(List<String>
desiredLocales, Registration registration)
+ static PortletDescription getPortletDescription(Portlet portlet, List<String>
desiredLocales)
{
- ProducerRegistrationRequirements registrationReq =
producer.getProducerRegistrationRequirements();
- if (registration == null && registrationReq.isRegistrationRequired()
&& registrationReq.isRegistrationRequiredForFullDescription())
- {
- return null;
- }
-
- Set<PortletDescription> descriptions =
getOfferedPortletDescriptions(desiredLocales);
- return new ArrayList<PortletDescription>(descriptions);
+ return getPortletDescription(portlet, desiredLocales, null);
}
/**
@@ -188,11 +163,15 @@
* @param desiredLocales the user desired locales (ordered according to user
preferences) to use for the description
* @return a PortletDescription describing the specified portlet
*/
- PortletDescription getPortletDescription(Portlet portlet, List<String>
desiredLocales)
+ static PortletDescription getPortletDescription(Portlet portlet, List<String>
desiredLocales, ServiceDescriptionInfo sdi)
{
org.gatein.pc.api.PortletContext context = portlet.getContext();
PortletInfo info = portlet.getInfo();
- log.debug("Constructing portlet description for: " + context.getId());
+ String handle = context.getId();
+ if (log.isDebugEnabled())
+ {
+ log.debug("Constructing portlet description for: " + handle);
+ }
CapabilitiesInfo capInfo = info.getCapabilities();
Collection<MediaType> allMediaTypes = capInfo.getMediaTypes();
@@ -205,7 +184,7 @@
markupTypes.add(markupType);
}
- PortletDescription desc = WSRPTypeFactory.createPortletDescription(context,
markupTypes);
+ PortletDescription desc = WSRPTypeFactory.createPortletDescription(handle,
markupTypes);
// group ID
desc.setGroupID(info.getApplicationName());
@@ -243,22 +222,95 @@
}
}
+ // 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 onlySecure
* [O] boolean userContextStoredInSession
* [O] boolean templatesStoredInSession
* [O] boolean hasUserSpecificState
* [O] boolean doesUrlTemplateProcessing
- * [O] Extension extensions
+ * [O] boolean mayReturnPortletState
+ * [O] Extension extensions[]
*/
return desc;
}
- private List<String> getLocaleNamesFrom(Collection<Locale> locales)
+ private static List<String> getLocaleNamesFrom(Collection<Locale>
locales)
{
if (locales == null || locales.isEmpty())
{
@@ -273,7 +325,7 @@
return localeNames;
}
- private List<String> getWindowStateNamesFrom(Collection<WindowStateInfo>
windowStates)
+ private static List<String>
getWindowStateNamesFrom(Collection<WindowStateInfo> windowStates)
{
List<String> result = new ArrayList<String>(windowStates.size());
for (WindowStateInfo windowStateInfo : windowStates)
@@ -283,7 +335,7 @@
return result;
}
- private List<String> getModeNamesFrom(Collection<ModeInfo> modes)
+ private static List<String> getModeNamesFrom(Collection<ModeInfo> modes)
{
List<String> result = new ArrayList<String>(modes.size());
for (ModeInfo modeInfo : modes)
@@ -292,4 +344,132 @@
}
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 List<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);
+
+ lastGenerated = System.currentTimeMillis();
+ }
+ }
+
+ 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 ArrayList<EventDescription>(portlets.size());
+
+ for (Portlet portlet : portlets)
+ {
+ PortletDescription desc = getPortletDescription(portlet, desiredLocales);
+ offeredPortletDescriptions.add(desc);
+ }
+
+ // events
+
registrationPortletsServiceDescription.getEventDescriptions().addAll(eventDescriptions);
+
registrationNoPortletsServiceDescription.getEventDescriptions().addAll(eventDescriptions);
+
noRegistrationPortletsServiceDescription.getEventDescriptions().addAll(eventDescriptions);
+
noRegistrationNoPortletsServiceDescription.getEventDescriptions().addAll(eventDescriptions);
+
+ 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)
+ {
+ EventDescription desc = WSRPTypeFactory.createEventDescription(info.getName());
+ 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.add(desc);
+ }
+ }
}