Author: mwringe
Date: 2010-09-23 16:17:25 -0400 (Thu, 23 Sep 2010)
New Revision: 4363
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/RegistrationHandler.java
Log:
GTNWSRP-74: removed creation of the nonregisted consumer and registration from
RegistrationHandler and create getNonregisteredRegistration to the RegistraionManager
instead.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationManager.java 2010-09-23
16:23:08 UTC (rev 4362)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationManager.java 2010-09-23
20:17:25 UTC (rev 4363)
@@ -66,6 +66,8 @@
Registration getRegistration(String registrationHandle) throws RegistrationException;
+ Registration getNonregisteredRegistration() throws RegistrationException;
+
void removeRegistration(String registrationHandle) throws RegistrationException,
NoSuchRegistrationException;
void removeRegistration(Registration registration) throws RegistrationException,
NoSuchRegistrationException;
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 2010-09-23
16:23:08 UTC (rev 4362)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java 2010-09-23
20:17:25 UTC (rev 4363)
@@ -42,6 +42,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -218,6 +219,24 @@
return (Registration)getConsumerOrRegistration(registrationHandle, false);
}
+ public Registration getNonregisteredRegistration() throws RegistrationException
+ {
+ //TODO: this might be better to place somewhere else and use the
RegistrationHandler.register instead of
+ // doing basically the same thing below.
+ String NonRegisteredDConsumer = "NONREGISTERED";
+ Consumer unregConsumer = getConsumerByIdentity(NonRegisteredDConsumer);
+ if (unregConsumer == null)
+ {
+ unregConsumer = createConsumer(NonRegisteredDConsumer);
+ Registration registration = addRegistrationTo(NonRegisteredDConsumer, new
HashMap<QName, Object>(), null, false);
+ registration.setStatus(RegistrationStatus.VALID);
+ getPersistenceManager().saveChangesTo(unregConsumer);
+ }
+ //The unregistered consumer should only ever have one registration, return that
+ Registration registration = unregConsumer.getRegistrations().iterator().next();
+ return registration;
+ }
+
public void removeRegistration(String registrationHandle) throws
RegistrationException, NoSuchRegistrationException
{
Registration registration = getRegistration(registrationHandle);
Modified:
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/RegistrationHandler.java 2010-09-23
16:23:08 UTC (rev 4362)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/RegistrationHandler.java 2010-09-23
20:17:25 UTC (rev 4363)
@@ -77,43 +77,38 @@
super(producer);
}
- public RegistrationContext register(RegistrationData registrationData)
- throws MissingParameters, OperationFailed, OperationNotSupported
+ 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");
+ WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(registrationData,
"RegistrationData");
+ String consumerName = registrationData.getConsumerName();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(consumerName,
"consumer name", "RegistrationData");
- Registration registration;
- try
- {
- log.debug("Attempting to register consumer named '" +
consumerName + "', agent '" + consumerAgent + "'.");
+ String consumerAgent = registrationData.getConsumerAgent();
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(consumerAgent,
"consumer agent", "RegistrationData");
- // check that the consumer agent is valid before trying to register
- RegistrationUtils.validateConsumerAgent(consumerAgent);
+ Registration registration;
+ try
+ {
+ log.debug("Attempting to register consumer named '" + consumerName
+ "', agent '" + 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);
- }
+ // check that the consumer agent is valid before trying to register
+ RegistrationUtils.validateConsumerAgent(consumerAgent);
- RegistrationContext registrationContext =
WSRPTypeFactory.createRegistrationContext(registration.getRegistrationHandle());
- log.debug("Registration completed without error.");
- return registrationContext;
+ 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);
+ }
- //throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class,
"Registration shouldn't be attempted if registration is not required",
null);
+ RegistrationContext registrationContext =
WSRPTypeFactory.createRegistrationContext(registration.getRegistrationHandle());
+ log.debug("Registration completed without error.");
+ return registrationContext;
}
private void updateRegistrationInformation(Registration registration, RegistrationData
registrationData)
@@ -353,33 +348,18 @@
{
try
{
- //TODO: fix this giant hack,
- String unregisteredConsumer = "UNREGISTEREDCONSUMER";
- Consumer consumer =
producer.getRegistrationManager().getConsumerByIdentity(unregisteredConsumer);
- if (consumer == null)
+ Registration registration =
producer.getRegistrationManager().getNonregisteredRegistration();
+ if (registration == null)
{
- consumer =
producer.getRegistrationManager().createConsumer(unregisteredConsumer);
+ throwInvalidRegistrationFault("Could not acquire the nonregistered
registration from the RegistrationManager");
}
-
- if (consumer.getRegistrations().isEmpty())
- {
- Registration registration =
producer.getRegistrationManager().addRegistrationTo(unregisteredConsumer, new HashMap(),
null, false);
- registration.setStatus(RegistrationStatus.VALID);
- return registration;
- }
- else
- {
- Registration registration =
consumer.getRegistrations().iterator().next();
- registration.setStatus(RegistrationStatus.VALID);
- return registration;
- }
+ return registration;
}
catch (RegistrationException e)
{
- throwOperationFailedFault("Failed to create a virtual registration with
a unregistered consumer", e);
+ throwOperationFailedFault("Failed to retrieve registration information
associated with the nonregistered consumer", e);
return null;
}
- // return null;
}
}