Author: chris.laprun(a)jboss.com
Date: 2009-09-30 23:25:02 -0400 (Wed, 30 Sep 2009)
New Revision: 219
Added:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/
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/XMLWSRPConsumerFactory.java
components/wsrp/trunk/consumer/src/main/resources/
components/wsrp/trunk/consumer/src/main/resources/conf/
components/wsrp/trunk/consumer/src/main/resources/conf/wsrp-consumers-config.xml
Removed:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ConsumerRegistryService.java
Modified:
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ConsumerBean.java
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ConsumerManagerBean.java
components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/faces-config.xml
components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/jboss-portlet.xml
components/wsrp/trunk/consumer/pom.xml
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
Log:
- Moved ConsumerRegistry to new registry package.
- Re-factored ConsumerRegistryService (now renamed AbstractConsumerRegistry) to support
multiple implementations.
- Re-added loading of consumers from XML as a read-only, XML-backed implementation of
ConsumerRegistry.
- Hibernate-backed implementation of ConsumerRegistry is lacking configuration and will
probably be either removed or extracted in a different module.
Modified:
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ConsumerBean.java
===================================================================
---
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ConsumerBean.java 2009-09-30
19:51:35 UTC (rev 218)
+++
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ConsumerBean.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -24,11 +24,11 @@
package org.gatein.wsrp.admin.ui;
import org.gatein.wsrp.WSRPConsumer;
-import org.gatein.wsrp.consumer.ConsumerRegistry;
import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.RegistrationInfo;
import org.gatein.wsrp.consumer.RegistrationProperty;
+import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
Modified:
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ConsumerManagerBean.java
===================================================================
---
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ConsumerManagerBean.java 2009-09-30
19:51:35 UTC (rev 218)
+++
components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ConsumerManagerBean.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -24,11 +24,11 @@
package org.gatein.wsrp.admin.ui;
import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.PortletInvokerException;
import org.gatein.wsrp.WSRPConsumer;
-import org.gatein.wsrp.consumer.ConsumerRegistry;
import org.gatein.wsrp.consumer.RefreshResult;
import org.gatein.wsrp.consumer.RegistrationInfo;
-import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
Modified: components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/faces-config.xml 2009-09-30
19:51:35 UTC (rev 218)
+++ components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/faces-config.xml 2009-10-01
03:25:02 UTC (rev 219)
@@ -63,7 +63,7 @@
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>registry</property-name>
-
<property-class>org.gatein.wsrp.consumer.ConsumerRegistry</property-class>
+
<property-class>org.gatein.wsrp.consumer.registry.ConsumerRegistry</property-class>
<value>#{applicationScope.ConsumerRegistry}</value>
</managed-property>
<managed-property>
@@ -83,7 +83,7 @@
</managed-property>
<managed-property>
<property-name>registry</property-name>
-
<property-class>org.gatein.wsrp.consumer.ConsumerRegistry</property-class>
+
<property-class>org.gatein.wsrp.consumer.registry.ConsumerRegistry</property-class>
<value>#{applicationScope.ConsumerRegistry}</value>
</managed-property>
<managed-property>
Modified: components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/jboss-portlet.xml
===================================================================
--- components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/jboss-portlet.xml 2009-09-30
19:51:35 UTC (rev 218)
+++ components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/jboss-portlet.xml 2009-10-01
03:25:02 UTC (rev 219)
@@ -34,7 +34,7 @@
</portlet>
<service>
<service-name>ConsumerRegistry</service-name>
-
<service-class>org.gatein.wsrp.consumer.ConsumerRegistry</service-class>
+
<service-class>org.gatein.wsrp.consumer.registry.ConsumerRegistry</service-class>
<service-ref>portal.wsrp:service=ConsumerRegistry</service-ref>
</service>
<service>
Modified: components/wsrp/trunk/consumer/pom.xml
===================================================================
--- components/wsrp/trunk/consumer/pom.xml 2009-09-30 19:51:35 UTC (rev 218)
+++ components/wsrp/trunk/consumer/pom.xml 2009-10-01 03:25:02 UTC (rev 219)
@@ -107,8 +107,6 @@
</dependencies>
<build>
- <finalName>wsrp-consumer</finalName>
-
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Deleted:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ConsumerRegistry.java 2009-09-30
19:51:35 UTC (rev 218)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ConsumerRegistry.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -1,66 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2009, 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.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.gatein.wsrp.consumer;
-
-import org.gatein.pc.federation.FederatingPortletInvoker;
-import org.gatein.wsrp.WSRPConsumer;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 12693 $
- * @since 2.6
- */
-public interface ConsumerRegistry
-{
- List<WSRPConsumer> getConfiguredConsumers();
-
- WSRPConsumer getConsumer(String id);
-
- FederatingPortletInvoker getFederatingPortletInvoker();
-
- WSRPConsumer createConsumer(String id, Integer expirationCacheSeconds) throws
ConsumerException;
-
- void persistConsumer(WSRPConsumer consumer) throws ConsumerException;
-
- /**
- * Activates the consumer associated with the specified identifier if and only if
access to the remote producer is
- * properly setup (i.e. the associated service factory MUST be available).
- *
- * @param id the identifier of the consumer to be activated
- * @throws ConsumerException
- */
- void activateConsumerWith(String id) throws ConsumerException;
-
- void updateProducerInfo(ProducerInfo producerInfo) throws ConsumerException;
-
- void deactivateConsumerWith(String id) throws ConsumerException;
-
- void registerOrDeregisterConsumerWith(String id, boolean register) throws
ConsumerException;
-
- void destroyConsumer(String id) throws ConsumerException;
-
- void reloadConsumers();
-}
\ No newline at end of file
Deleted:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ConsumerRegistryService.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ConsumerRegistryService.java 2009-09-30
19:51:35 UTC (rev 218)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ConsumerRegistryService.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -1,434 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2009, 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.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.gatein.wsrp.consumer;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.gatein.common.util.ParameterValidation;
-import org.gatein.pc.api.PortletInvoker;
-import org.gatein.pc.api.PortletInvokerException;
-import org.gatein.pc.federation.FederatedPortletInvoker;
-import org.gatein.pc.federation.FederatingPortletInvoker;
-import org.gatein.wsrp.WSRPConsumer;
-import org.gatein.wsrp.api.SessionEventBroadcaster;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.naming.InitialContext;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-/**
- * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision: 12693 $
- * @since 2.6
- */
-public class ConsumerRegistryService implements ConsumerRegistry
-{
- /** Gives access to the Portal's portlet invokers */
- private FederatingPortletInvoker federatingPortletInvoker;
-
- private SortedMap<String, WSRPConsumer> consumers;
-
- private SessionFactory sessionFactory;
-
- private String sessionFactoryJNDIName;
-
- private SessionEventBroadcaster sessionEventBroadcaster;
-
- private static final String CONSUMER_WITH_ID = "Consumer with id '";
- private static final String RELEASE_SESSIONS_LISTENER =
"release_sessions_listener_";
-
- private static final Logger log =
LoggerFactory.getLogger(ConsumerRegistryService.class);
-
- public FederatingPortletInvoker getFederatingPortletInvoker()
- {
- return federatingPortletInvoker;
- }
-
- public void setSessionEventBroadcaster(SessionEventBroadcaster
sessionEventBroadcaster)
- {
- this.sessionEventBroadcaster = sessionEventBroadcaster;
- }
-
- public WSRPConsumer createConsumer(String id, Integer expirationCacheSeconds)
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Creating a Consumer");
-
- if (getConsumer(id) != null)
- {
- throw new ConsumerException(CONSUMER_WITH_ID + id + "' already
exists!");
- }
-
-
- ProducerInfo info = new ProducerInfo();
- info.setId(id);
- info.setRegistry(this);
- info.setExpirationCacheSeconds(expirationCacheSeconds);
-
- try
- {
- Session session = sessionFactory.getCurrentSession();
-
- session.persist(info);
- }
- catch (HibernateException e)
- {
- throw new ConsumerException("Couldn't create Consumer '" + id
+ "'", e);
- }
-
- log.info(CONSUMER_WITH_ID + id + "' created");
- return createConsumerFrom(info);
- }
-
- public void destroyConsumer(String id)
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Destroying a Consumer");
-
- WSRPConsumer consumer = getConsumer(id);
- if (consumer != null)
- {
- ProducerInfo info = consumer.getProducerInfo();
-
- try
- {
- consumer.releaseSessions();
- }
- catch (PortletInvokerException e)
- {
- log.debug("releaseSessions failed when attempting to destroy " +
CONSUMER_WITH_ID + id + "'");
- }
-
- // if the consumer is registered, deregister it
- if (info.isRegistered())
- {
- registerOrDeregisterConsumerWith(id, false);
- }
-
- deactivateConsumerWith(id);
- consumers.remove(id);
-
- Session session = sessionFactory.getCurrentSession();
-
- session.delete(info);
- }
- else
- {
- throw new ConsumerException(CONSUMER_WITH_ID + id + "' doesn't
exist!");
- }
-
- log.info(CONSUMER_WITH_ID + id + "' destroyed");
- }
-
- public void persistConsumer(WSRPConsumer consumer)
- {
- ParameterValidation.throwIllegalArgExceptionIfNull(consumer,
"Consumer");
-
- ProducerInfo info = consumer.getProducerInfo();
-
- try
- {
- Session session = sessionFactory.getCurrentSession();
- session.persist(info);
- }
- catch (HibernateException e)
- {
- throw new ConsumerException(CONSUMER_WITH_ID + info.getId() + "'
couldn't be persisted!");
- }
-
- createConsumerFrom(info);
- }
-
- public void setFederatingPortletInvoker(FederatingPortletInvoker
federatingPortletInvoker)
- {
- this.federatingPortletInvoker = federatingPortletInvoker;
- }
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
- private WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
- {
- WSRPConsumer consumer = new WSRPConsumerImpl(producerInfo);
- consumers.put(producerInfo.getId(), consumer);
-
- return consumer;
- }
-
- public void activateConsumerWith(String id) throws ConsumerException
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Activating a Consumer");
-
- // if the consumer associated with the given id is already registered, don't do
anything
- if (federatingPortletInvoker.getFederatedInvoker(id) == null)
- {
- startOrStopConsumer(id, true);
- }
- else
- {
- // todo: fix-me federated portlet invoker gets desynchronized...
- WSRPConsumer consumer = getConsumer(id);
- if (consumer != null && !consumer.isActive())
- {
- federatingPortletInvoker.unregisterInvoker(id);
- startOrStopConsumer(id, true);
- }
- }
- }
-
- public void deactivateConsumerWith(String id) throws ConsumerException
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Deactivating a Consumer");
-
- // only process if there is a registered Consumer with the specified id
- if (federatingPortletInvoker.getFederatedInvoker(id) != null)
- {
- startOrStopConsumer(id, false);
- }
- else
- {
- // todo: fix-me federated portlet invoker gets desynchronized...
- WSRPConsumer consumer = getConsumer(id);
- if (consumer != null && consumer.isActive())
- {
- federatingPortletInvoker.registerInvoker(id, consumer);
- startOrStopConsumer(id, false);
- }
- }
- }
-
- public void updateProducerInfo(ProducerInfo producerInfo)
- {
- ParameterValidation.throwIllegalArgExceptionIfNull(producerInfo,
"ProducerInfo");
-
- Session session = sessionFactory.getCurrentSession();
- try
- {
-
- // Retrieve the previous id of the given ProducerInfo to update local consumers
map if needed
- String oldId = (String)session.createQuery("select pi.persistentId from
ProducerInfo pi where pi.id = :key")
- .setParameter("key", producerInfo.getKey()).uniqueResult();
- if (producerInfo.getId().equals(oldId))
- {
- oldId = null; // reset oldId as the ProducerInfo's id hasn't been
modified
- }
-
- // merge old producer info with new data
- session.update(producerInfo);
-
- // if we updated and oldId is not null, we need to update the local consumers
map
- if (oldId != null)
- {
- WSRPConsumer consumer = consumers.remove(oldId);
- consumers.put(producerInfo.getId(), consumer);
- }
- }
- catch (HibernateException e)
- {
- throw new ConsumerException("Couldn't update ProducerInfo for Consumer
'" + producerInfo.getId() + "'", e);
- }
- }
-
- protected void startService() throws Exception
- {
- InitialContext initialContext = new InitialContext();
- sessionFactory = (SessionFactory)initialContext.lookup(sessionFactoryJNDIName);
- reloadConsumers();
- }
-
- public void reloadConsumers()
- {
- // load the configured consumers
- consumers = new TreeMap<String, WSRPConsumer>();
-
- Session session = sessionFactory.getCurrentSession();
-
- Iterator producerInfos = session.createQuery("from ProducerInfo pi order by
pi.persistentId").iterate();
-
- // load the configured producers
- ProducerInfo producerInfo;
- while (producerInfos.hasNext())
- {
- producerInfo = (ProducerInfo)producerInfos.next();
-
- // need to set the registry after loading from DB since registry is not
persisted.
- producerInfo.setRegistry(this);
-
- createConsumerFrom(producerInfo);
-
- try
- {
- // if the producer is marked as active, activate it fo' real! :)
- if (producerInfo.isActive())
- {
- activateConsumerWith(producerInfo.getId());
- }
- }
- catch (Exception e)
- {
- producerInfo.setActive(false);
- updateProducerInfo(producerInfo);
- }
-
- }
- }
-
- protected void stopService() throws Exception
- {
- sessionFactory = null;
-
- for (WSRPConsumer consumer : consumers.values())
- {
- // if producer is not active, it shouldn't be registered with the federating
portlet invoker, hence do not
- // unregister it.
- if (consumer.getProducerInfo().isActive())
- {
- federatingPortletInvoker.unregisterInvoker(consumer.getProducerId());
- }
-
- try
- {
- consumer.stop();
- }
- catch (Exception e)
- {
- // ignore and continue
- }
- }
-
- consumers.clear();
- consumers = null;
- }
-
- public List<WSRPConsumer> getConfiguredConsumers()
- {
- return new ArrayList<WSRPConsumer>(consumers.values());
- }
-
- public WSRPConsumer getConsumer(String id)
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "consumer
id", null);
- return consumers.get(id);
- }
-
- public void registerOrDeregisterConsumerWith(String id, boolean register)
- {
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Registering or deregistering a Consumer");
-
- WSRPConsumer consumer = getConsumer(id);
-
- if (consumer == null)
- {
- throw new ConsumerException(CONSUMER_WITH_ID + id + "' doesn't
exist!");
- }
-
- try
- {
- if (register)
- {
- consumer.getProducerInfo().register();
- }
- else
- {
- consumer.getProducerInfo().deregister();
- }
- }
- catch (Exception e)
- {
- // unexpected exception: deactivate the consumer
- deactivateConsumerWith(id);
- Throwable cause = e.getCause();
- throw new ConsumerException("Couldn't " + (register ?
"register" : "deregister") + CONSUMER_WITH_ID + id +
"'",
- cause != null ? cause : e);
- }
- }
-
- private void startOrStopConsumer(String id, boolean start)
- {
- WSRPConsumer consumer;
-
- try
- {
- if (start)
- {
- consumer = getConsumer(id);
-
- if (consumer == null)
- {
- throw new IllegalArgumentException(CONSUMER_WITH_ID + id + "'
doesn't exist!");
- }
-
- consumer.activate();
- federatingPortletInvoker.registerInvoker(id, consumer);
- sessionEventBroadcaster.registerListener(getListenerIdFrom(id), consumer);
- }
- else
- {
- FederatedPortletInvoker fedInvoker =
federatingPortletInvoker.getFederatedInvoker(id);
- if (fedInvoker != null)
- {
- PortletInvoker invoker = fedInvoker.getPortletInvoker();
- if (invoker instanceof WSRPConsumer)
- {
- consumer = (WSRPConsumer)invoker;
- consumer.deactivate();
- federatingPortletInvoker.unregisterInvoker(id);
- sessionEventBroadcaster.unregisterListener(getListenerIdFrom(id));
- }
- else
- {
- throw new IllegalArgumentException("PortletInvoker with id
'" + id + "' is not a WSRPConsumer!");
- }
- }
- else
- {
- throw new IllegalArgumentException("There is no registered
PortletInvoker with id '" + id + "'");
- }
- }
- }
- catch (Exception e)
- {
- throw new ConsumerException("Couldn't " + (start ?
"start" : "stop") + " Consumer service '" + id +
"'", e);
- }
-
- // update ProducerInfo
- updateProducerInfo(consumer.getProducerInfo());
- }
-
- private String getListenerIdFrom(String id)
- {
- return RELEASE_SESSIONS_LISTENER + id;
- }
-}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java 2009-09-30
19:51:35 UTC (rev 218)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -34,6 +34,7 @@
import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.consumer.portlet.WSRPPortlet;
import org.gatein.wsrp.consumer.portlet.info.WSRPPortletInfo;
+import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
import org.gatein.wsrp.servlet.UserAccess;
import org.oasis.wsrp.v1.CookieProtocol;
import org.oasis.wsrp.v1.Extension;
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2009-09-30
19:51:35 UTC (rev 218)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -31,9 +31,9 @@
import org.gatein.pc.api.PortletInvokerException;
import org.gatein.pc.api.PortletStateType;
import org.gatein.pc.api.invocation.ActionInvocation;
+import org.gatein.pc.api.invocation.InvocationException;
import org.gatein.pc.api.invocation.PortletInvocation;
import org.gatein.pc.api.invocation.RenderInvocation;
-import org.gatein.pc.api.invocation.InvocationException;
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
import org.gatein.pc.api.spi.UserContext;
import org.gatein.pc.api.state.DestroyCloneFailure;
@@ -121,7 +121,7 @@
this(new ProducerInfo());
}
- WSRPConsumerImpl(ProducerInfo info)
+ public WSRPConsumerImpl(ProducerInfo info)
{
ParameterValidation.throwIllegalArgExceptionIfNull(info,
"ProducerInfo");
@@ -196,7 +196,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(portletContext,
"PortletContext");
- if(!PortletStateType.OPAQUE.equals(stateType))
+ if (!PortletStateType.OPAQUE.equals(stateType))
{
throw new IllegalArgumentException("This PortletInvoker cannot deal with
PortletStateTypes other than PortletStateType.OPAQUE. Given: " + stateType);
}
Copied:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
(from rev 212,
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ConsumerRegistryService.java)
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -0,0 +1,384 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, 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.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.wsrp.consumer.registry;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.PortletInvoker;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.federation.FederatedPortletInvoker;
+import org.gatein.pc.federation.FederatingPortletInvoker;
+import org.gatein.wsrp.WSRPConsumer;
+import org.gatein.wsrp.api.SessionEventBroadcaster;
+import org.gatein.wsrp.consumer.ConsumerException;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 12693 $
+ * @since 2.6
+ */
+public abstract class AbstractConsumerRegistry implements ConsumerRegistry
+{
+ /** Gives access to the Portal's portlet invokers */
+ private FederatingPortletInvoker federatingPortletInvoker;
+
+ protected SortedMap<String, WSRPConsumer> consumers;
+
+ private SessionEventBroadcaster sessionEventBroadcaster;
+
+ private static final String CONSUMER_WITH_ID = "Consumer with id '";
+ private static final String RELEASE_SESSIONS_LISTENER =
"release_sessions_listener_";
+
+ private static final Logger log =
LoggerFactory.getLogger(AbstractConsumerRegistry.class);
+
+ public FederatingPortletInvoker getFederatingPortletInvoker()
+ {
+ return federatingPortletInvoker;
+ }
+
+ public void setSessionEventBroadcaster(SessionEventBroadcaster
sessionEventBroadcaster)
+ {
+ this.sessionEventBroadcaster = sessionEventBroadcaster;
+ }
+
+ public WSRPConsumer createConsumer(String id, Integer expirationCacheSeconds)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Creating a Consumer");
+
+ if (getConsumer(id) != null)
+ {
+ throw new ConsumerException(CONSUMER_WITH_ID + id + "' already
exists!");
+ }
+
+
+ ProducerInfo info = new ProducerInfo();
+ info.setId(id);
+ info.setRegistry(this);
+ info.setExpirationCacheSeconds(expirationCacheSeconds);
+
+ save(info, "Couldn't create Consumer '" + id +
"'");
+
+ log.info(CONSUMER_WITH_ID + id + "' created");
+ return createConsumerFrom(info);
+ }
+
+ public void destroyConsumer(String id)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Destroying a Consumer");
+
+ WSRPConsumer consumer = getConsumer(id);
+ if (consumer != null)
+ {
+ ProducerInfo info = consumer.getProducerInfo();
+
+ try
+ {
+ consumer.releaseSessions();
+ }
+ catch (PortletInvokerException e)
+ {
+ log.debug("releaseSessions failed when attempting to destroy " +
CONSUMER_WITH_ID + id + "'");
+ }
+
+ // if the consumer is registered, deregister it
+ if (info.isRegistered())
+ {
+ registerOrDeregisterConsumerWith(id, false);
+ }
+
+ deactivateConsumerWith(id);
+ consumers.remove(id);
+
+ delete(info);
+ }
+ else
+ {
+ throw new ConsumerException(CONSUMER_WITH_ID + id + "' doesn't
exist!");
+ }
+
+ log.info(CONSUMER_WITH_ID + id + "' destroyed");
+ }
+
+ public void persistConsumer(WSRPConsumer consumer)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(consumer,
"Consumer");
+
+ ProducerInfo info = consumer.getProducerInfo();
+
+ save(info, CONSUMER_WITH_ID + info.getId() + "' couldn't be
persisted!");
+
+ createConsumerFrom(info);
+ }
+
+ public void setFederatingPortletInvoker(FederatingPortletInvoker
federatingPortletInvoker)
+ {
+ this.federatingPortletInvoker = federatingPortletInvoker;
+ }
+
+ private WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
+ {
+ WSRPConsumer consumer = new WSRPConsumerImpl(producerInfo);
+ consumers.put(producerInfo.getId(), consumer);
+
+ return consumer;
+ }
+
+ public void activateConsumerWith(String id) throws ConsumerException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Activating a Consumer");
+
+ // if the consumer associated with the given id is already registered, don't do
anything
+ if (federatingPortletInvoker.getFederatedInvoker(id) == null)
+ {
+ startOrStopConsumer(id, true);
+ }
+ else
+ {
+ // todo: fix-me federated portlet invoker gets desynchronized...
+ WSRPConsumer consumer = getConsumer(id);
+ if (consumer != null && !consumer.isActive())
+ {
+ federatingPortletInvoker.unregisterInvoker(id);
+ startOrStopConsumer(id, true);
+ }
+ }
+ }
+
+ public void deactivateConsumerWith(String id) throws ConsumerException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Deactivating a Consumer");
+
+ // only process if there is a registered Consumer with the specified id
+ if (federatingPortletInvoker.getFederatedInvoker(id) != null)
+ {
+ startOrStopConsumer(id, false);
+ }
+ else
+ {
+ // todo: fix-me federated portlet invoker gets desynchronized...
+ WSRPConsumer consumer = getConsumer(id);
+ if (consumer != null && consumer.isActive())
+ {
+ federatingPortletInvoker.registerInvoker(id, consumer);
+ startOrStopConsumer(id, false);
+ }
+ }
+ }
+
+ public void updateProducerInfo(ProducerInfo producerInfo)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(producerInfo,
"ProducerInfo");
+
+ String oldId = update(producerInfo);
+
+ // if we updated and oldId is not null, we need to update the local consumers map
+ if (oldId != null)
+ {
+ WSRPConsumer consumer = consumers.remove(oldId);
+ consumers.put(producerInfo.getId(), consumer);
+ }
+ }
+
+ public void start() throws Exception
+ {
+ reloadConsumers();
+ }
+
+ public void reloadConsumers()
+ {
+ // load the configured consumers
+ consumers = new TreeMap<String, WSRPConsumer>();
+
+ Iterator producerInfos = getAllProducerInfos();
+
+ // load the configured producers
+ ProducerInfo producerInfo;
+ while (producerInfos.hasNext())
+ {
+ producerInfo = (ProducerInfo)producerInfos.next();
+
+ // need to set the registry after loading from DB since registry is not
persisted.
+ producerInfo.setRegistry(this);
+
+ createConsumerFrom(producerInfo);
+
+ try
+ {
+ // if the producer is marked as active, activate it fo' real! :)
+ if (producerInfo.isActive())
+ {
+ activateConsumerWith(producerInfo.getId());
+ }
+ }
+ catch (Exception e)
+ {
+ producerInfo.setActive(false);
+ updateProducerInfo(producerInfo);
+ }
+
+ }
+ }
+
+ public void stop() throws Exception
+ {
+ for (WSRPConsumer consumer : consumers.values())
+ {
+ // if producer is not active, it shouldn't be registered with the federating
portlet invoker, hence do not
+ // unregister it.
+ if (consumer.getProducerInfo().isActive())
+ {
+ federatingPortletInvoker.unregisterInvoker(consumer.getProducerId());
+ }
+
+ try
+ {
+ consumer.stop();
+ }
+ catch (Exception e)
+ {
+ // ignore and continue
+ }
+ }
+
+ consumers.clear();
+ consumers = null;
+ }
+
+ public List<WSRPConsumer> getConfiguredConsumers()
+ {
+ return new ArrayList<WSRPConsumer>(consumers.values());
+ }
+
+ public WSRPConsumer getConsumer(String id)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "consumer
id", null);
+ return consumers.get(id);
+ }
+
+ public void registerOrDeregisterConsumerWith(String id, boolean register)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Registering or deregistering a Consumer");
+
+ WSRPConsumer consumer = getConsumer(id);
+
+ if (consumer == null)
+ {
+ throw new ConsumerException(CONSUMER_WITH_ID + id + "' doesn't
exist!");
+ }
+
+ try
+ {
+ if (register)
+ {
+ consumer.getProducerInfo().register();
+ }
+ else
+ {
+ consumer.getProducerInfo().deregister();
+ }
+ }
+ catch (Exception e)
+ {
+ // unexpected exception: deactivate the consumer
+ deactivateConsumerWith(id);
+ Throwable cause = e.getCause();
+ throw new ConsumerException("Couldn't " + (register ?
"register" : "deregister") + CONSUMER_WITH_ID + id +
"'",
+ cause != null ? cause : e);
+ }
+ }
+
+ private void startOrStopConsumer(String id, boolean start)
+ {
+ WSRPConsumer consumer;
+
+ try
+ {
+ if (start)
+ {
+ consumer = getConsumer(id);
+
+ if (consumer == null)
+ {
+ throw new IllegalArgumentException(CONSUMER_WITH_ID + id + "'
doesn't exist!");
+ }
+
+ consumer.activate();
+ federatingPortletInvoker.registerInvoker(id, consumer);
+ sessionEventBroadcaster.registerListener(getListenerIdFrom(id), consumer);
+ }
+ else
+ {
+ FederatedPortletInvoker fedInvoker =
federatingPortletInvoker.getFederatedInvoker(id);
+ if (fedInvoker != null)
+ {
+ PortletInvoker invoker = fedInvoker.getPortletInvoker();
+ if (invoker instanceof WSRPConsumer)
+ {
+ consumer = (WSRPConsumer)invoker;
+ consumer.deactivate();
+ federatingPortletInvoker.unregisterInvoker(id);
+ sessionEventBroadcaster.unregisterListener(getListenerIdFrom(id));
+ }
+ else
+ {
+ throw new IllegalArgumentException("PortletInvoker with id
'" + id + "' is not a WSRPConsumer!");
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("There is no registered
PortletInvoker with id '" + id + "'");
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new ConsumerException("Couldn't " + (start ?
"start" : "stop") + " Consumer service '" + id +
"'", e);
+ }
+
+ // update ProducerInfo
+ updateProducerInfo(consumer.getProducerInfo());
+ }
+
+ private String getListenerIdFrom(String id)
+ {
+ return RELEASE_SESSIONS_LISTENER + id;
+ }
+
+ protected abstract void save(ProducerInfo info, String messageOnError);
+
+ protected abstract void delete(ProducerInfo info);
+
+ protected abstract String update(ProducerInfo producerInfo);
+
+ protected abstract Iterator getAllProducerInfos();
+}
Copied:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java
(from rev 212,
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ConsumerRegistry.java)
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, 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.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.wsrp.consumer.registry;
+
+import org.gatein.pc.federation.FederatingPortletInvoker;
+import org.gatein.wsrp.WSRPConsumer;
+import org.gatein.wsrp.api.SessionEventBroadcaster;
+import org.gatein.wsrp.consumer.ConsumerException;
+import org.gatein.wsrp.consumer.ProducerInfo;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 12693 $
+ * @since 2.6
+ */
+public interface ConsumerRegistry
+{
+ List<WSRPConsumer> getConfiguredConsumers();
+
+ WSRPConsumer getConsumer(String id);
+
+ FederatingPortletInvoker getFederatingPortletInvoker();
+
+ WSRPConsumer createConsumer(String id, Integer expirationCacheSeconds) throws
ConsumerException;
+
+ void persistConsumer(WSRPConsumer consumer) throws ConsumerException;
+
+ /**
+ * Activates the consumer associated with the specified identifier if and only if
access to the remote producer is
+ * properly setup (i.e. the associated service factory MUST be available).
+ *
+ * @param id the identifier of the consumer to be activated
+ * @throws ConsumerException
+ */
+ void activateConsumerWith(String id) throws ConsumerException;
+
+ void updateProducerInfo(ProducerInfo producerInfo) throws ConsumerException;
+
+ void deactivateConsumerWith(String id) throws ConsumerException;
+
+ void registerOrDeregisterConsumerWith(String id, boolean register) throws
ConsumerException;
+
+ void destroyConsumer(String id) throws ConsumerException;
+
+ void reloadConsumers();
+
+ void start() throws Exception;
+
+ void stop() throws Exception;
+
+ void setSessionEventBroadcaster(SessionEventBroadcaster sessionEventBroadcaster);
+
+ void setFederatingPortletInvoker(FederatingPortletInvoker federatingPortletInvoker);
+}
\ No newline at end of file
Added:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -0,0 +1,129 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.gatein.wsrp.consumer.registry.hibernate;
+
+import org.gatein.wsrp.consumer.ConsumerException;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.registry.AbstractConsumerRegistry;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+
+import javax.naming.InitialContext;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class HibernateConsumerRegistry extends AbstractConsumerRegistry
+{
+ private SessionFactory sessionFactory;
+ private String sessionFactoryJNDIName;
+
+ protected void save(ProducerInfo info, String messageOnError)
+ {
+ try
+ {
+ Session session = sessionFactory.getCurrentSession();
+ session.persist(info);
+ }
+ catch (HibernateException e)
+ {
+ throw new ConsumerException(messageOnError, e);
+ }
+ }
+
+ protected void delete(ProducerInfo info)
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ session.delete(info);
+ }
+
+ public String getSessionFactoryJNDIName()
+ {
+ return sessionFactoryJNDIName;
+ }
+
+ public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+ {
+ this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+ }
+
+ /**
+ * Updates the given ProducerInfo
+ *
+ * @param producerInfo the ProducerInfo to update
+ * @return the id that was previously assigned to the specified ProducerInfo or
<code>null</code> if the id hasn't
+ * been modified
+ */
+ protected String update(ProducerInfo producerInfo)
+ {
+ String oldId;
+ Session session = sessionFactory.getCurrentSession();
+ try
+ {
+
+ // Retrieve the previous id of the given ProducerInfo to update local consumers
map if needed
+ oldId = (String)session.createQuery("select pi.persistentId from
ProducerInfo pi where pi.id = :key")
+ .setParameter("key", producerInfo.getKey()).uniqueResult();
+ if (producerInfo.getId().equals(oldId))
+ {
+ oldId = null; // reset oldId as the ProducerInfo's id hasn't been
modified
+ }
+
+ // merge old producer info with new data
+ session.update(producerInfo);
+
+ }
+ catch (HibernateException e)
+ {
+ throw new ConsumerException("Couldn't update ProducerInfo for Consumer
'" + producerInfo.getId() + "'", e);
+ }
+ return oldId;
+ }
+
+ protected Iterator getAllProducerInfos()
+ {
+ Session session = sessionFactory.getCurrentSession();
+
+ Iterator producerInfos = session.createQuery("from ProducerInfo pi order by
pi.persistentId").iterate();
+ return producerInfos;
+ }
+
+ @Override
+ public void start() throws Exception
+ {
+ InitialContext initialContext = new InitialContext();
+ sessionFactory = (SessionFactory)initialContext.lookup(sessionFactoryJNDIName);
+ super.start();
+ }
+
+ @Override
+ public void stop() throws Exception
+ {
+ sessionFactory = null;
+ super.stop();
+ }
+}
Added:
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
(rev 0)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -0,0 +1,139 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.gatein.wsrp.consumer.registry.xml;
+
+import org.gatein.common.xml.NullEntityResolver;
+import org.gatein.wsrp.WSRPConsumer;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.registry.AbstractConsumerRegistry;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.EntityResolver;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 9360 $
+ */
+public class XMLConsumerRegistry extends AbstractConsumerRegistry
+{
+ private final static Logger log = LoggerFactory.getLogger(XMLConsumerRegistry.class);
+
+ /** . */
+ private static final String defaultWSRPLocation =
"conf/wsrp-consumers-config.xml";
+
+ private EntityResolver entityResolver;
+
+ public XMLConsumerRegistry()
+ {
+ consumers = new TreeMap<String, WSRPConsumer>();
+ }
+
+ public EntityResolver getEntityResolver()
+ {
+ return entityResolver;
+ }
+
+ public void setEntityResolver(EntityResolver entityResolver)
+ {
+ this.entityResolver = entityResolver;
+ }
+
+ public void start() throws Exception
+ {
+ URL defaultWSRPURL =
Thread.currentThread().getContextClassLoader().getResource(defaultWSRPLocation);
+ if (defaultWSRPURL != null)
+ {
+ InputStream inputStream = defaultWSRPURL.openStream();
+
+ 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.setEntityResolver(entityResolver);
+ try
+ {
+ consumers = (SortedMap<String,
WSRPConsumer>)unmarshaller.unmarshal(inputStream, factory, null);
+ }
+ catch (JBossXBException e)
+ {
+ e.printStackTrace();
+ }
+
+ for (WSRPConsumer consumer : consumers.values())
+ {
+ activateConsumerWith(consumer.getProducerId());
+ }
+ }
+ }
+
+ @Override
+ public void stop() throws Exception
+ {
+ for (WSRPConsumer consumer : consumers.values())
+ {
+ consumer.stop();
+ }
+ }
+
+ @Override
+ protected void save(ProducerInfo info, String messageOnError)
+ {
+ // do nothing
+ }
+
+ @Override
+ protected void delete(ProducerInfo info)
+ {
+ // do nothing
+ }
+
+ @Override
+ protected String update(ProducerInfo producerInfo)
+ {
+ return null;
+ }
+
+ @Override
+ protected Iterator getAllProducerInfos()
+ {
+ return consumers.values().iterator();
+ }
+
+ SortedMap<String, WSRPConsumer> getConsumers()
+ {
+ return consumers;
+ }
+}
Property changes on:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLWSRPConsumerFactory.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLWSRPConsumerFactory.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLWSRPConsumerFactory.java 2009-10-01
03:25:02 UTC (rev 219)
@@ -0,0 +1,366 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.gatein.wsrp.consumer.registry.xml;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.wsrp.WSRPConsumer;
+import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.RegistrationInfo;
+import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
+import org.jboss.util.StringPropertyReplacer;
+import org.jboss.xb.binding.GenericObjectModelFactory;
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.Attributes;
+
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * Wire the mbeans to install
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class XMLWSRPConsumerFactory implements GenericObjectModelFactory
+{
+ private static final Logger log =
LoggerFactory.getLogger(XMLWSRPConsumerFactory.class);
+
+ private ConsumerRegistry consumerRegistry;
+
+ private static final boolean DEBUG = true;
+
+ /** . */
+ private static final String WSRP_PRODUCER = "wsrp-producer";
+
+ public static class Property
+ {
+ String name;
+ String value;
+ String lang;
+ }
+
+ public XMLWSRPConsumerFactory(ConsumerRegistry consumerRegistry)
+ {
+ this.consumerRegistry = consumerRegistry;
+ }
+
+ public Object newRoot(Object root, UnmarshallingContext nav, String nsURI, String
localName, Attributes attrs)
+ {
+ if (consumerRegistry instanceof XMLConsumerRegistry)
+ {
+ XMLConsumerRegistry registry = (XMLConsumerRegistry)consumerRegistry;
+ return registry.getConsumers();
+ }
+
+ return new TreeMap<String, WSRPConsumer>();
+ }
+
+ public Object completeRoot(Object root, UnmarshallingContext nav, String nsURI, String
localName)
+ {
+ return root;
+ }
+
+ public Object newChild(Object parent, UnmarshallingContext unmarshallingContext,
String nsURI, String localName, Attributes attributes)
+ {
+ if (parent instanceof SortedMap)
+ {
+ return newChild((SortedMap<String, WSRPConsumer>)parent,
unmarshallingContext, nsURI, localName, attributes);
+ }
+ if (parent instanceof RegistrationInfo)
+ {
+ return newChild((RegistrationInfo)parent, unmarshallingContext, nsURI,
localName, attributes);
+ }
+ if (parent instanceof WSRPConsumer)
+ {
+ return newChild((WSRPConsumer)parent, unmarshallingContext, nsURI, localName,
attributes);
+ }
+ return null;
+ }
+
+ public void addChild(Object parent, Object child, UnmarshallingContext
unmarshallingContext, String nsURI, String localName)
+ {
+ if (parent instanceof RegistrationInfo && child instanceof Property)
+ {
+ addChild((RegistrationInfo)parent, (Property)child, unmarshallingContext, nsURI,
localName);
+ }
+ else if (parent instanceof SortedMap && child instanceof WSRPConsumer)
+ {
+ addChild((SortedMap<String, WSRPConsumer>)parent, (WSRPConsumer)child,
unmarshallingContext, nsURI, localName);
+ }
+ }
+
+ public void setValue(Object parent, UnmarshallingContext unmarshallingContext, String
nsURI, String localName, String value)
+ {
+ if (parent instanceof EndpointConfigurationInfo)
+ {
+ setValue((EndpointConfigurationInfo)parent, unmarshallingContext, nsURI,
localName, value);
+ }
+ else if (parent instanceof Property)
+ {
+ setValue((Property)parent, unmarshallingContext, nsURI, localName, value);
+ }
+ else if (parent instanceof RegistrationInfo)
+ {
+ setValue((RegistrationInfo)parent, unmarshallingContext, nsURI, localName,
value);
+ }
+ }
+
+ public Object newChild(SortedMap<String, WSRPConsumer> consumers,
UnmarshallingContext nav, String nsURI, String localName,
+ Attributes attrs)
+ {
+ if (DEBUG)
+ {
+ System.out.println("newchild deployment " + localName);
+ }
+
+ if (WSRP_PRODUCER.equals(localName))
+ {
+ String id = attrs.getValue("id");
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "producer
identifier", "Configuring a producer");
+
+ // check that the consumer doesn't exist in the database first
+ WSRPConsumer consumer = consumerRegistry.getConsumer(id);
+ if (consumer != null)
+ {
+ String message = "Added consumer for producer '" + id +
"' with status: ";
+
+ // if consumer is active, add it to the list of services
+ if (consumer.getProducerInfo().isActive())
+ {
+ consumers.put(id, consumer);
+ message += "active";
+ }
+ else
+ {
+ message += "inactive";
+ }
+
+ log.info(message + " (loaded from database).");
+
+ // consumer already exists, do not further process this producer and use the
DB configuration instead
+ return null;
+ }
+
+ String expirationCache = attrs.getValue("expiration-cache");
+ Integer expirationCacheSeconds = null;
+ if (expirationCache != null)
+ {
+ try
+ {
+ expirationCacheSeconds = new Integer(expirationCache);
+ }
+ catch (NumberFormatException e)
+ {
+ log.info("Ignoring bad expiration cache value " +
expirationCache + " for producer '" + id + "'");
+ }
+ }
+
+ // consumer didn't exist in the database, so create one and configure it
+ consumer = consumerRegistry.createConsumer(id, expirationCacheSeconds);
+
+ return consumer;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Object newChild(WSRPConsumer consumer, UnmarshallingContext nav, String nsURI,
String localName,
+ Attributes attrs)
+ {
+ if (DEBUG)
+ {
+ System.out.println("newchild service " + localName);
+ }
+
+ ProducerInfo prodInfo = consumer.getProducerInfo();
+
+ if ("endpoint-config".equals(localName) ||
"endpoint-wsdl-url".equals(localName))
+ {
+ return prodInfo.getEndpointConfigurationInfo();
+ }
+ else if ("registration-data".equals(localName))
+ {
+ return new RegistrationInfo(prodInfo);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Object newChild(RegistrationInfo registrationInfo, UnmarshallingContext nav,
String nsURI, String localName,
+ Attributes attrs)
+ {
+ if (DEBUG)
+ {
+ System.out.println("newChild registrationInfo " + localName);
+ }
+
+ if ("property".equals(localName))
+ {
+ return new Property();
+ }
+ return null;
+ }
+
+ public void setValue(EndpointConfigurationInfo endpointInfo, UnmarshallingContext nav,
String nsURI,
+ String localName, String value)
+ {
+ if (DEBUG)
+ {
+ System.out.println("setvalue endpointInfo " + localName);
+ }
+
+ if ("service-description-url".equals(localName))
+ {
+ // Resolve value that may contain properties for that one
+ value = StringPropertyReplacer.replaceProperties(value);
+ endpointInfo.setServiceDescriptionURL(value);
+ }
+ else if ("markup-url".equals(localName))
+ {
+ // Resolve value that may contain properties for that one
+ value = StringPropertyReplacer.replaceProperties(value);
+ endpointInfo.setMarkupURL(value);
+ }
+ else if ("registration-url".equals(localName))
+ {
+ // Resolve value that may contain properties for that one
+ value = StringPropertyReplacer.replaceProperties(value);
+ endpointInfo.setRegistrationURL(value);
+ }
+ else if ("portlet-management-url".equals(localName))
+ {
+ // Resolve value that may contain properties for that one
+ value = StringPropertyReplacer.replaceProperties(value);
+ endpointInfo.setPortletManagementURL(value);
+ }
+ else if ("endpoint-wsdl-url".equals(localName))
+ {
+ value = StringPropertyReplacer.replaceProperties(value);
+ try
+ {
+ endpointInfo.setWsdlDefinitionURL(value);
+ }
+ catch (RuntimeException e)
+ {
+ // ignore at this point if the WSDL cannot be retrieved, another attempt will
be made before persisting
+ }
+ }
+ }
+
+ public void setValue(RegistrationInfo registrationInfo, UnmarshallingContext nav,
String nsURI, String localName,
+ String value)
+ {
+ if (DEBUG)
+ {
+ System.out.println("setvalue registrationinfo " + localName);
+ }
+
+ if ("consumer-name".equals(localName))
+ {
+ value = StringPropertyReplacer.replaceProperties(value);
+ registrationInfo.setConsumerName(value);
+ }
+ }
+
+ public void setValue(Property property, UnmarshallingContext nav, String nsURI, String
localName, String value)
+ {
+ if (DEBUG)
+ {
+ System.out.println("setvalue property " + localName);
+ }
+
+ if ("name".equals(localName))
+ {
+ value = StringPropertyReplacer.replaceProperties(value);
+ property.name = value;
+ }
+ else if ("lang".equals(localName))
+ {
+ value = StringPropertyReplacer.replaceProperties(value);
+ property.lang = value;
+ }
+ else if ("value".equals(localName))
+ {
+ value = StringPropertyReplacer.replaceProperties(value);
+ property.value = value;
+ }
+ }
+
+ public void addChild(RegistrationInfo registrationInfo, Property property,
+ UnmarshallingContext nav, String nsURI, String localName)
+ {
+ if (DEBUG)
+ {
+ System.out.println("addchild registrationinfo property " +
localName);
+ }
+
+ registrationInfo.setRegistrationPropertyValue(property.name,
property.value).setLang(property.lang);
+ }
+
+ public void addChild(SortedMap<String, WSRPConsumer> consumers, WSRPConsumer
consumer, UnmarshallingContext nav, String nsURI,
+ String localName)
+ {
+ ProducerInfo info = consumer.getProducerInfo();
+
+ if (DEBUG)
+ {
+ System.out.println("adding consumer " + info.getId() + " to
deployment - localName: " + localName);
+ }
+
+ String message;
+ String id = consumer.getProducerId();
+ if (consumer.getProducerInfo().getEndpointConfigurationInfo().isAvailable())
+ {
+ message = "Added consumer for producer '" + id + "' from
xml configuration.";
+ consumers.put(id, consumer);
+ }
+ else
+ {
+ message = "There was a problem initializing the WSRP interface for producer
'"
+ + id + "'. The consumer will NOT be available.";
+ info.setActive(false);
+ }
+
+ // update the producer info once the whole information is known
+ try
+ {
+ consumerRegistry.updateProducerInfo(info);
+ }
+ catch (Exception e)
+ {
+ // if we couldn't update the info, remove it from the list of service to be
activated
+ consumers.remove(id);
+ log.info("Couldn't update the ProducerInfo for Consumer '" +
info.getId() + "'", e);
+ return;
+ }
+
+ log.info(message);
+ }
+}
Property changes on:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLWSRPConsumerFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/consumer/src/main/resources/conf/wsrp-consumers-config.xml
===================================================================
--- components/wsrp/trunk/consumer/src/main/resources/conf/wsrp-consumers-config.xml
(rev 0)
+++
components/wsrp/trunk/consumer/src/main/resources/conf/wsrp-consumers-config.xml 2009-10-01
03:25:02 UTC (rev 219)
@@ -0,0 +1,85 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2006, 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. ~
+ ~ ~
+ ~ This is free software; you can redistribute it and/or modify it ~
+ ~ under the terms of the GNU Lesser General Public License as ~
+ ~ published by the Free Software Foundation; either version 2.1 of ~
+ ~ the License, or (at your option) any later version. ~
+ ~ ~
+ ~ This software is distributed in the hope that it will be useful, ~
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ~
+ ~ Lesser General Public License for more details. ~
+ ~ ~
+ ~ You should have received a copy of the GNU Lesser General Public ~
+ ~ License along with this software; if not, write to the Free ~
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ~
+ ~ 02110-1301 USA, or see the FSF site:
http://www.fsf.org. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<deployments xmlns="urn:jboss:portal:wsrp:consumer:v2_7"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:portal:wsrp:consumer:v2_7
http://www.jboss.org/portal/xsd/jboss-wsrp-consumer_2_7.xsd">
+ <deployment>
+ <wsrp-producer id="self" expiration-cache="300">
+ <!--
+ we need to use the individual endpoint configuration because the configuration
via wsdl forces an
+ immediate attempt to access the web service description which is not available
yet at this point of deployment
+ -->
+ <endpoint-config>
+
<service-description-url>http://localhost:8080/portal-wsrp/ServiceDescriptionService
+ </service-description-url>
+
<markup-url>http://localhost:8080/portal-wsrp/MarkupService</markup-url>
+
<registration-url>http://localhost:8080/portal-wsrp/RegistrationService</registration-url>
+
<portlet-management-url>http://localhost:8080/portal-wsrp/PortletManagementService</portlet-management-url>
+ </endpoint-config>
+ <registration-data/>
+ </wsrp-producer>
+ </deployment>
+ <!--<deployment>
+ <wsrp-producer id="NetUnity" expiration-cache="300">
+
<
endpoint-wsdl-url>http://wsrp.netunitysoftware.com/WSRPTestService/WSR...
+ <registration-data/>
+ </wsrp-producer>
+ </deployment>-->
+ <!--<deployment>
+ <wsrp-producer id="vignette" expiration-cache="300">
+
<endpoint-wsdl-url>http://wsrpdemo.vignette.com:8080/producer/wsdl</endpoint-wsdl-url>
+ <registration-data>
+ <property>
+ <name>com.vignette.wsrp.registration.username</name>
+ <lang>en</lang>
+ <value>test</value>
+ </property>
+ <property>
+ <name>com.vignette.wsrp.registration.password</name>
+ <lang>en</lang>
+ <value>test</value>
+ </property>
+ </registration-data>
+ </wsrp-producer>
+ </deployment>-->
+ <deployment>
+ <wsrp-producer id="bea" expiration-cache="300">
+
<endpoint-wsdl-url>http://wsrp.bea.com:7001/producer/producer?WSDL</endpoint-wsdl-url>
+ <registration-data>
+ <property>
+ <name>registration/consumerRole</name>
+ <lang>en</lang>
+ <value>insider</value>
+ </property>
+ </registration-data>
+ </wsrp-producer>
+ </deployment>
+ <!--<deployment>
+ <wsrp-producer id="oracle" expiration-cache="300">
+
<
endpoint-wsdl-url>http://portalstandards.oracle.com/portletapp/portlet...
+ <registration-data/>
+ </wsrp-producer>
+ </deployment>-->
+</deployments>
\ No newline at end of file
Property changes on:
components/wsrp/trunk/consumer/src/main/resources/conf/wsrp-consumers-config.xml
___________________________________________________________________
Name: svn:executable
+ *