Author: chris.laprun(a)jboss.com
Date: 2011-06-23 12:57:11 -0400 (Thu, 23 Jun 2011)
New Revision: 6726
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationService.java
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationServiceTestCase.java
Log:
- GTNPORTAL-1938: Added ability to configure consumers from an InputStream similarly to
what's being done in JCRProducerConfigurationService.
- Renamed JCRProducerConfigurationService.setDefaultConfigurationIS to setConfigurationIS
and removed deprecation since it's currently needed.
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java 2011-06-23
14:49:20 UTC (rev 6725)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java 2011-06-23
16:57:11 UTC (rev 6726)
@@ -50,9 +50,15 @@
/** . */
private static final String defaultWSRPLocation =
"conf/wsrp-consumers-config.xml";
+ private InputStream configurationIS;
private EntityResolver entityResolver;
+ public XMLConsumerRegistry(InputStream configurationInputStream)
+ {
+ configurationIS = configurationInputStream;
+ }
+
public EntityResolver getEntityResolver()
{
return entityResolver;
@@ -65,51 +71,51 @@
public void reloadConsumers()
{
- URL defaultWSRPURL =
Thread.currentThread().getContextClassLoader().getResource(defaultWSRPLocation);
- if (defaultWSRPURL != null)
+
+ if (configurationIS == null)
{
- InputStream inputStream;
+ URL defaultWSRPURL =
Thread.currentThread().getContextClassLoader().getResource(defaultWSRPLocation);
try
{
- inputStream = defaultWSRPURL.openStream();
+ configurationIS = defaultWSRPURL.openStream();
}
catch (IOException e)
{
throw new RuntimeException("Couldn't open default XML WSRP Consumer
configuration file", e);
}
+ }
- Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
- ObjectModelFactory factory = new XMLWSRPConsumerFactory(this);
- if (entityResolver == null)
- {
- log.debug("Could not obtain entity resolver for
XMLConsumerRegistry");
- entityResolver = new NullEntityResolver();
- }
+ Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+ ObjectModelFactory factory = new XMLWSRPConsumerFactory(this);
+ if (entityResolver == null)
+ {
+ log.debug("Could not obtain entity resolver for
XMLConsumerRegistry");
+ entityResolver = new NullEntityResolver();
+ }
+ try
+ {
+ unmarshaller.setEntityResolver(entityResolver);
+ initConsumers((SortedMap<String,
WSRPConsumer>)unmarshaller.unmarshal(configurationIS, factory, null));
+ }
+ catch (JBossXBException e)
+ {
+ throw new RuntimeException("Couldn't set unmarshall WSRP Consumers
configuration", e);
+ }
+
+ for (WSRPConsumer consumer : getConsumers())
+ {
+
+ ProducerInfo producerInfo = consumer.getProducerInfo();
try
{
- unmarshaller.setEntityResolver(entityResolver);
- initConsumers((SortedMap<String,
WSRPConsumer>)unmarshaller.unmarshal(inputStream, factory, null));
+ // try to activate the consumer
+ activateConsumer(consumer);
}
- catch (JBossXBException e)
+ catch (Exception e)
{
- throw new RuntimeException("Couldn't set unmarshall WSRP Consumers
configuration", e);
+ producerInfo.setActive(false);
+ updateProducerInfo(producerInfo);
}
-
- for (WSRPConsumer consumer : getConsumers())
- {
-
- ProducerInfo producerInfo = consumer.getProducerInfo();
- try
- {
- // try to activate the consumer
- activateConsumer(consumer);
- }
- catch (Exception e)
- {
- producerInfo.setActive(false);
- updateProducerInfo(producerInfo);
- }
- }
}
}
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java 2011-06-23
14:49:20 UTC (rev 6725)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java 2011-06-23
16:57:11 UTC (rev 6726)
@@ -37,6 +37,7 @@
import org.gatein.wsrp.jcr.StoresByPathManager;
import org.gatein.wsrp.registration.mapping.RegistrationPropertyDescriptionMapping;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -54,6 +55,7 @@
private static final String PRODUCER_INFOS_PATH = ProducerInfosMapping.NODE_NAME;
public static final List<Class> mappingClasses = new ArrayList<Class>(6);
+ private InputStream configurationIS;
static
{
@@ -73,6 +75,12 @@
this.loadFromXMLIfNeeded = loadFromXMLIfNeeded;
}
+ /** @param is */
+ public void setConfigurationIS(InputStream is)
+ {
+ this.configurationIS = is;
+ }
+
@Override
protected void save(ProducerInfo info, String messageOnError)
{
@@ -173,7 +181,7 @@
if (loadFromXMLIfNeeded)
{
// Load from XML
- XMLConsumerRegistry fromXML = new XMLConsumerRegistry();
+ XMLConsumerRegistry fromXML = new XMLConsumerRegistry(configurationIS);
fromXML.reloadConsumers();
// Save to JCR
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationService.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationService.java 2011-06-23
14:49:20 UTC (rev 6725)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationService.java 2011-06-23
16:57:11 UTC (rev 6726)
@@ -62,13 +62,8 @@
this.persister = persister;
}
- /**
- * todo: remove
- *
- * @param is
- * @deprecated this should be removed when a better initialization of default is
setup
- */
- public void setDefaultConfigurationIS(InputStream is)
+ /** @param is */
+ public void setConfigurationIS(InputStream is)
{
this.defaultConfigurationIS = is;
}
Modified:
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationServiceTestCase.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationServiceTestCase.java 2011-06-23
14:49:20 UTC (rev 6725)
+++
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationServiceTestCase.java 2011-06-23
16:57:11 UTC (rev 6726)
@@ -56,7 +56,7 @@
@Override
protected ProducerConfiguration getProducerConfiguration(URL location) throws
Exception
{
- service.setDefaultConfigurationIS(location.openStream());
+ service.setConfigurationIS(location.openStream());
service.loadConfiguration();
return service.getConfiguration();
}
Show replies by date