Author: chris.laprun(a)jboss.com
Date: 2011-10-21 07:37:12 -0400 (Fri, 21 Oct 2011)
New Revision: 7824
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/DuplicateRegistrationException.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/AbstractRegistrationPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java
Log:
- GTNWSRP-251: now return the existing Registration if a consumer attempts to register
with the same set of properties (more forgiving).
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/DuplicateRegistrationException.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/DuplicateRegistrationException.java 2011-10-21
11:35:13 UTC (rev 7823)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/DuplicateRegistrationException.java 2011-10-21
11:37:12 UTC (rev 7824)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2011, 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.
@@ -29,22 +29,39 @@
*/
public class DuplicateRegistrationException extends RegistrationException
{
+ private final Registration registration;
+
public DuplicateRegistrationException()
{
+ registration = null;
}
public DuplicateRegistrationException(String message)
{
super(message);
+ registration = null;
}
public DuplicateRegistrationException(String message, Throwable cause)
{
super(message, cause);
+ registration = null;
}
public DuplicateRegistrationException(Throwable cause)
{
super(cause);
+ registration = null;
}
+
+ public DuplicateRegistrationException(String message, Throwable cause, Registration
registration)
+ {
+ super(message, cause);
+ this.registration = registration;
+ }
+
+ public Registration getExistingRegistration()
+ {
+ return registration;
+ }
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java 2011-10-21
11:35:13 UTC (rev 7823)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java 2011-10-21
11:37:12 UTC (rev 7824)
@@ -23,6 +23,7 @@
package org.gatein.registration;
+import org.gatein.registration.spi.ConsumerSPI;
import org.gatein.registration.spi.RegistrationSPI;
import javax.xml.namespace.QName;
@@ -94,6 +95,8 @@
RegistrationSPI addRegistrationFor(String consumerId, Map<QName, Object>
registrationProperties) throws RegistrationException;
+ RegistrationSPI addRegistrationFor(ConsumerSPI consumer, Map<QName, Object>
registrationProperties) throws RegistrationException;
+
Collection<? extends ConsumerGroup> getConsumerGroups() throws
RegistrationException;
Registration getRegistration(String registrationId) throws RegistrationException;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/AbstractRegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/AbstractRegistrationPersistenceManager.java 2011-10-21
11:35:13 UTC (rev 7823)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/AbstractRegistrationPersistenceManager.java 2011-10-21
11:37:12 UTC (rev 7824)
@@ -148,6 +148,14 @@
+ "' to add a Registration to...");
}
+ return addRegistrationFor(consumer, registrationProperties);
+ }
+
+ public RegistrationSPI addRegistrationFor(ConsumerSPI consumer, Map<QName,
Object> registrationProperties) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(consumer,
"Consumer");
+ ParameterValidation.throwIllegalArgExceptionIfNull(registrationProperties,
"Registration properties");
+
RegistrationSPI registration = internalCreateRegistration(consumer,
registrationProperties);
consumer.addRegistration(registration);
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java 2011-10-21
11:35:13 UTC (rev 7823)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java 2011-10-21
11:37:12 UTC (rev 7824)
@@ -26,6 +26,7 @@
import org.gatein.common.util.ParameterValidation;
import org.gatein.registration.Consumer;
import org.gatein.registration.ConsumerGroup;
+import org.gatein.registration.DuplicateRegistrationException;
import org.gatein.registration.InvalidConsumerDataException;
import org.gatein.registration.NoSuchRegistrationException;
import org.gatein.registration.Registration;
@@ -35,6 +36,7 @@
import org.gatein.registration.RegistrationPersistenceManager;
import org.gatein.registration.RegistrationPolicy;
import org.gatein.registration.RegistrationStatus;
+import org.gatein.registration.spi.ConsumerSPI;
import org.gatein.registration.spi.RegistrationSPI;
import org.gatein.wsrp.registration.PropertyDescription;
import org.slf4j.Logger;
@@ -115,12 +117,31 @@
String identity = policy.getConsumerIdFrom(consumerName, registrationProperties);
// validate the registration information
- policy.validateRegistrationDataFor(registrationProperties, identity, expectations,
this);
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, identity,
expectations, this);
+ }
+ catch (DuplicateRegistrationException e)
+ {
+ log.info("Consumer '" + consumerName + "' was already
registered with the same set of registration properties.");
+ // check if the policy set the existing registration to be returned
+ final Registration existingRegistration = e.getExistingRegistration();
+ if (existingRegistration != null)
+ {
+ return existingRegistration;
+ }
+ else
+ {
+ // if we didn't get a registration to return, just throw the exception
+ throw e;
+ }
+ }
+
Consumer consumer = getOrCreateConsumer(identity, createConsumerIfNeeded,
consumerName);
// create the actual registration
- RegistrationSPI registration = persistenceManager.addRegistrationFor(identity,
registrationProperties);
+ RegistrationSPI registration =
persistenceManager.addRegistrationFor((ConsumerSPI)consumer, registrationProperties);
// let the policy decide what the handle should be
String handle =
policy.createRegistrationHandleFor(registration.getPersistentKey());
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java 2011-10-21
11:35:13 UTC (rev 7823)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java 2011-10-21
11:37:12 UTC (rev 7824)
@@ -170,7 +170,7 @@
if (registration.hasEqualProperties(registrationProperties))
{
throw new DuplicateRegistrationException("Consumer named '"
+ consumer.getName()
- + "' has already been registered with the same set of
registration properties. Registration rejected!");
+ + "' has already been registered with the same set of
registration properties. Registration rejected!", null, registration);
}
}
}