Author: chris.laprun(a)jboss.com
Date: 2006-12-15 18:19:29 -0500 (Fri, 15 Dec 2006)
New Revision: 5877
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java
Log:
- Consumer now try to register if needed before getting the service description instead of
waiting for it to fail and then retry. This should improve response time. Code is also
cleaner.
- Fixed an NPE in RegistrationHandler.createRegistrationProperties.
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2006-12-15
22:41:27 UTC (rev 5876)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2006-12-15
23:19:29 UTC (rev 5877)
@@ -23,6 +23,7 @@
package org.jboss.portal.wsrp.consumer;
import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import org.jboss.portal.portlet.InvokerUnavailableException;
import org.jboss.portal.portlet.NoSuchPortletException;
@@ -44,6 +45,7 @@
import org.jboss.portal.wsrp.consumer.portlet.WSRPPortlet;
import org.jboss.portal.wsrp.consumer.portlet.info.WSRPPortletInfo;
import org.jboss.portal.wsrp.core.GetServiceDescription;
+import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
import org.jboss.portal.wsrp.core.LocalizedString;
import org.jboss.portal.wsrp.core.ModelDescription;
import org.jboss.portal.wsrp.core.PortletDescription;
@@ -152,19 +154,13 @@
public Portlet getPortlet(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException
{
- if (portletContext == null)
- {
- throw new IllegalArgumentException("No null portlet context
accepted");
- }
+ ParameterValidation.throwIllegalArgExceptionIfNull(portletContext,
"PortletContext");
return getPortlet(portletContext.getId());
}
private Portlet getPortlet(String portletId) throws PortletInvokerException
{
- if (portletId == null)
- {
- throw new IllegalArgumentException("No null portlet id accepted");
- }
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletId, "portlet
id", "PortletContext");
Map portlets;
try
@@ -514,59 +510,23 @@
{
GetServiceDescription request = getServiceDescriptionRequest();
+ // try initial registration if needed
+ registerIfNeeded();
+ request.setRegistrationContext(registrationContext);
+
final String producerId = getProducerId();
+
+ ServiceDescription serviceDescription;
try
{
- ServiceDescription serviceDescription =
getServiceDescriptionService().getServiceDescription(request);
+ serviceDescription =
getServiceDescriptionService().getServiceDescription(request);
if (serviceDescription != null)
{
- if (serviceDescription.isRequiresRegistration())
+ boolean shouldRetry = informUserIfMissingRegistrationInfo(serviceDescription,
producerId);
+ if (shouldRetry)
{
- // try to register with the registration data provided at deployment time
- if (registrationData != null)
- {
- RegistrationContext registrationContext =
getRegistrationService().register(registrationData);
-
- // if we reach this point, registration was successful so remember the
returned registration context
- this.registrationContext = registrationContext;
-
- // add it to the request and try to get the service description again!
- request.setRegistrationContext(registrationContext);
- serviceDescription =
getServiceDescriptionService().getServiceDescription(request);
- }
- else
- {
- ModelDescription registrationProperties =
serviceDescription.getRegistrationPropertyDescription();
- StringBuffer message = new StringBuffer("Producer
'").append(producerId)
- .append("' requires registration yet configuration of this
producer does not provide any ")
- .append("registration data. Please refer to the documentation
on how to configure a remote producer.");
- log.info(message);
-
- if (registrationProperties != null)
- {
- PropertyDescription[] propertyDescriptions =
registrationProperties.getPropertyDescriptions();
- if (propertyDescriptions != null)
- {
- message.append("\nAdditionally, the producer required the
following registration information: ");
- for (int i = 0; i < propertyDescriptions.length; i++)
- {
- PropertyDescription propertyDescription =
propertyDescriptions[i];
- String name = propertyDescription.getName();
- String type = propertyDescription.getType().toString();
- LocalizedString nillableLabel =
propertyDescription.getLabel();
- String label = nillableLabel == null ? null :
nillableLabel.getValue();
- LocalizedString nillableHint = propertyDescription.getHint();
- String hint = nillableHint == null ? null :
nillableHint.getValue();
- message.append("propertyDescription =\n-
name:\t").append(name).append("\n- type:\t")
- .append(type).append("\n-
label:\t").append(label).append("\n- hint:\t").append(hint)
- .append("\n");
- }
- }
- }
- throw new ServiceDescriptionUnavailableException(message.toString(),
null);
- }
-
+ serviceDescription = getServiceDescriptionAndRegisterIfNeeded();
}
// do we need to call initCookie or not?
@@ -582,19 +542,109 @@
throw new NullPointerException("null service description: deal with
it!");
}
}
- catch (ServiceDescriptionUnavailableException e)
+ catch (InvalidRegistrationFault e)
{
- throw e;
+ // our registration was not accepted, invalidate our registration data and
retrieve registration data from producer
+ registrationContext = null;
+ registrationData = null;
+ request.setRegistrationContext(null);
+
+ // try again
+ serviceDescription = getServiceDescriptionAndRegisterIfNeeded();
}
catch (Exception e)
{
- log.debug(e);
+ log.debug("Caught Exception in
getServiceDescriptionAndRegisterIfNeeded:\n", e);
Throwable cause = e.getCause();
throw new ServiceDescriptionUnavailableException("Problem getting service
description for producer "
+ producerId, cause == null ? e : cause);
}
+
+ return serviceDescription;
}
+ /**
+ * Extract required registration information from the service description and informs
the user if we are not
+ * registered and the Producer requires registration. This can happen if we
haven't registered yet or after a retry
+ * if our initial registration information was rejected.
+ *
+ * @param serviceDescription
+ * @param producerId
+ * @return <code>true</code> if we should retry to get the service
description, <code>false</code> otherwise
+ * @throws ServiceDescriptionUnavailableException
+ * if we need to inform the user of missing required registration data
+ * @since 2.6
+ */
+ private boolean informUserIfMissingRegistrationInfo(ServiceDescription
serviceDescription, String producerId)
+ throws ServiceDescriptionUnavailableException
+ {
+ if (serviceDescription.isRequiresRegistration() && registrationContext ==
null)
+ {
+ StringBuffer message = new StringBuffer("Producer
'").append(producerId)
+ .append("' requires registration. Configuration for this producer
might need to be updated to register.");
+ log.info(message);
+
+ ModelDescription registrationProperties =
serviceDescription.getRegistrationPropertyDescription();
+ if (registrationProperties != null)
+ {
+ PropertyDescription[] propertyDescriptions =
registrationProperties.getPropertyDescriptions();
+ if (propertyDescriptions != null)
+ {
+ message.append("\nThe producer required the following registration
information: ");
+ for (int i = 0; i < propertyDescriptions.length; i++)
+ {
+ PropertyDescription propertyDescription = propertyDescriptions[i];
+ String name = propertyDescription.getName();
+ String type = propertyDescription.getType().toString();
+ LocalizedString nillableLabel = propertyDescription.getLabel();
+ String label = nillableLabel == null ? null :
nillableLabel.getValue();
+ LocalizedString nillableHint = propertyDescription.getHint();
+ String hint = nillableHint == null ? null : nillableHint.getValue();
+ message.append("propertyDescription =\n-
name:\t").append(name).append("\n- type:\t")
+ .append(type).append("\n-
label:\t").append(label).append("\n- hint:\t").append(hint)
+ .append("\n");
+ }
+ }
+ throw new ServiceDescriptionUnavailableException(message.toString(), null);
+ }
+ else
+ {
+ log.info("The producer didn't require any specific registration
properties. Attempting to register with minimal information.");
+ registrationData = WSRPTypeFactory.createDefaultRegistrationData();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Attempts to register if our producer configuration provides registration data and
we don't have a valid
+ * RegistrationContext yet.
+ *
+ * @throws ServiceDescriptionUnavailableException
+ *
+ */
+ private void registerIfNeeded() throws ServiceDescriptionUnavailableException
+ {
+ // producer configuration with registration data + no registrationContext = we need
to register!
+ if (registrationData != null && registrationContext == null)
+ {
+ RegistrationContext registrationContext;
+ try
+ {
+ registrationContext = getRegistrationService().register(registrationData);
+ }
+ catch (Exception e)
+ {
+ throw new ServiceDescriptionUnavailableException("Couldn't register
with producer '" + getProducerId() + "'", e);
+ }
+
+ // if we reach this point, registration was successful so remember the returned
registration context
+ log.info("Successfully registered with handle: '" +
registrationContext.getRegistrationHandle() + "'");
+ this.registrationContext = registrationContext;
+ }
+ }
+
private void setServiceDescriptionRequest(GetServiceDescription request)
{
serviceDescriptionRequest = request;
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java 2006-12-15
22:41:27 UTC (rev 5876)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java 2006-12-15
23:19:29 UTC (rev 5877)
@@ -267,14 +267,21 @@
private Map createRegistrationProperties(RegistrationData registrationData)
{
Property[] regProperties = registrationData.getRegistrationProperties();
- Map properties = new HashMap(regProperties.length);
-
- for (int i = 0; i < regProperties.length; i++)
+ Map properties;
+ if (regProperties != null)
{
- Property property = regProperties[i];
- // todo: should be more detailed here... use the language, allow other value
types...
- properties.put(new QName(property.getName()), property.getStringValue());
+ properties = new HashMap(regProperties.length);
+ for (int i = 0; i < regProperties.length; i++)
+ {
+ Property property = regProperties[i];
+ // todo: should be more detailed here... use the language, allow other value
types...
+ properties.put(new QName(property.getName()), property.getStringValue());
+ }
}
+ else
+ {
+ properties = Collections.EMPTY_MAP;
+ }
return properties;
}
Show replies by date