You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by dd...@apache.org on 2005/12/05 20:10:40 UTC
svn commit: r354130 - in /portals/pluto/trunk:
pluto-container/src/main/java/org/apache/pluto/core/
pluto-portal-driver/src/main/java/org/apache/pluto/driver/
pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/
pluto-portal-driver/sr...
Author: ddewolf
Date: Mon Dec 5 11:10:23 2005
New Revision: 354130
URL: http://svn.apache.org/viewcvs?rev=354130&view=rev
Log:
Adding portlet application publishing abilities; Requests to /admin/Publish/context=/path/to/context will register the app and all portlets if it does not allready exist in the configuration
Modified:
portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletDescriptorRegistry.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/AdminConfigurationImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/DriverAdministrationException.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/PortletRegistryAdminService.java
portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml
portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/web.xml
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletDescriptorRegistry.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletDescriptorRegistry.java?rev=354130&r1=354129&r2=354130&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletDescriptorRegistry.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletDescriptorRegistry.java Mon Dec 5 11:10:23 2005
@@ -38,7 +38,7 @@
* @version 1.0
* @since Nov 3, 2004
*/
-class PortletDescriptorRegistry {
+public class PortletDescriptorRegistry {
/** Portlet deployment descriptor location. */
private static final String PORTLET_XML = "/WEB-INF/portlet.xml";
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java?rev=354130&r1=354129&r2=354130&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PublishServlet.java Mon Dec 5 11:10:23 2005
@@ -16,6 +16,8 @@
package org.apache.pluto.driver;
import org.apache.pluto.driver.services.portal.admin.DriverAdministrationException;
+import org.apache.pluto.driver.services.portal.admin.PortletRegistryAdminService;
+import org.apache.pluto.driver.config.AdminConfiguration;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -43,12 +45,20 @@
try {
doPublish(context);
}
- catch(DriverAdministrationException driverAdministration) {
- res.getWriter().println("Unable to publish portlet application bound to context '"+context+"'.");
+ catch(Throwable t) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Unable to publish portlet application bound to context '"+context+"'.");
+ sb.append("Reason: ").append(t.getMessage());
+ res.getWriter().println(sb.toString());
}
}
private void doPublish(String context) throws DriverAdministrationException {
+ AdminConfiguration adminConfig = (AdminConfiguration)getServletContext()
+ .getAttribute(AttributeKeys.DRIVER_ADMIN_CONFIG);
+ PortletRegistryAdminService admin = adminConfig.getPortletRegistryAdminService();
+
+ admin.addPortletApplication(context);
}
}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/AdminConfigurationImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/AdminConfigurationImpl.java?rev=354130&r1=354129&r2=354130&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/AdminConfigurationImpl.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/AdminConfigurationImpl.java Mon Dec 5 11:10:23 2005
@@ -33,6 +33,10 @@
private RenderConfigAdminService renderConfigAdminService;
public void init(ServletContext context) {
+
+ }
+
+ public void destroy() {
}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java?rev=354130&r1=354129&r2=354130&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java Mon Dec 5 11:10:23 2005
@@ -139,6 +139,17 @@
this.renderService.init(context);
}
+ public void destroy() {
+ if(propertyService != null)
+ propertyService.destroy();
+
+ if(registryService != null)
+ registryService.destroy();
+
+ if(renderService != null)
+ renderService.destroy();
+ }
+
//
// Container Services
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java?rev=354130&r1=354129&r2=354130&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/DBPortletRegistryService.java Mon Dec 5 11:10:23 2005
@@ -24,13 +24,18 @@
import org.apache.pluto.driver.services.impl.resource.ResourceConfigReader;
import org.apache.pluto.driver.config.DriverConfigurationException;
import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.core.PortletDescriptorRegistry;
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+import org.apache.pluto.descriptors.portlet.PortletDD;
import org.apache.pluto.optional.db.common.DataSourceManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.ServletContext;
import java.util.Set;
+import java.util.Iterator;
import java.io.InputStream;
+import java.io.IOException;
import java.sql.SQLException;
/**
@@ -45,6 +50,8 @@
private static final Log LOG = LogFactory.getLog(DBPortletRegistryService.class);
+ private ServletContext servletContext;
+
private DataSourceManager dataSourceManager;
private PortletRegistryDao dao;
@@ -70,6 +77,7 @@
}
public void init(ServletContext ctx) throws DriverConfigurationException {
+ this.servletContext = ctx;
if(LOG.isDebugEnabled()) {
LOG.debug("Registering portlet applications. . .");
@@ -91,7 +99,14 @@
}
public void destroy() throws DriverConfigurationException {
-
+ if(dataSourceManager != null) {
+ try {
+ dataSourceManager.shutdown();
+ }
+ catch(PortletContainerException pce) {
+ LOG.error("Unable to shutdown dataSourceManager: "+pce.getMessage(), pce);
+ }
+ }
}
public Set getPortletApplications() {
@@ -126,18 +141,43 @@
}
}
- public void addPortletApplication(PortletApplicationConfig app)
+ public void addPortletApplication(String contextPath)
throws DriverAdministrationException {
- if(app == null)
- throw new IllegalArgumentException("Portal Application Config may not be null.");
+ if(contextPath == null)
+ throw new IllegalArgumentException("Can not add servlet context 'null'.");
try {
+ PortletApplicationConfig app = new PortletApplicationConfig();
+ app.setContextPath(contextPath);
+
+ ServletContext portletContext = servletContext.getContext(contextPath);
+ if(portletContext == null) {
+ throw new DriverAdministrationException("Unable to locate context: "+contextPath+". Ensure that crossContext support is enabled and the portlet application has been deployed.");
+ }
+
+ PortletAppDD descriptor = getPortletDescriptor(portletContext);
+ Iterator it = descriptor.getPortlets().iterator();
+ while(it.hasNext()) {
+ PortletDD portlet = (PortletDD)it.next();
+ PortletWindowConfig config = new PortletWindowConfig();
+ config.setContextPath(contextPath);
+ config.setPortletName(portlet.getPortletName());
+ app.addPortlet(config);
+ }
dao.addPortletApplication(app);
}
- catch(SQLException sqle) {
+ catch(PortletContainerException pce) {
+ throw new DriverAdministrationException("Unable to load descriptor. ", pce);
+ }
+ catch(SQLException sqle) {
throw new DriverAdministrationException("Unable to add portlet application due to database error.", sqle);
}
+ }
+
+ private PortletAppDD getPortletDescriptor(ServletContext context)
+ throws PortletContainerException {
+ return PortletDescriptorRegistry.getRegistry().getPortletAppDD(context);
}
}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java?rev=354130&r1=354129&r2=354130&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/impl/db/PortletRegistryDao.java Mon Dec 5 11:10:23 2005
@@ -49,15 +49,78 @@
}
public PortletApplicationConfig getPortletApp(String context) throws SQLException {
- PortletApplicationConfig app = (PortletApplicationConfig)
- doSelect(createPortletAppSQL(context));
-
- return app;
+ return (PortletApplicationConfig) doSelect(createPortletAppSQL(context));
}
- public void addPortletApplication(PortletApplicationConfig config)
+ public void addPortletApplication(PortletApplicationConfig app)
throws SQLException {
+
+ boolean autoCommit = false;
+ Connection conn = null;
+ PreparedStatement appStmt = null;
+ PreparedStatement appTestStmt = null;
+ PreparedStatement portletTestStmt = null;
+ PreparedStatement pStmt = null;
+
+ try {
+ conn = getConnection();
+ autoCommit = conn.getAutoCommit();
+ conn.setAutoCommit(false);
+
+ appTestStmt = conn.prepareStatement(TEST_APP_SQL);
+ portletTestStmt = conn.prepareStatement(TEST_PORTLET_SQL);
+
+ appStmt = conn.prepareStatement(CREATE_APP_SQL);
+ pStmt = conn.prepareStatement(CREATE_PORTLET_SQL);
+
+ appTestStmt.setString(1, app.getContextPath());
+ ResultSet rs = appTestStmt.executeQuery();
+
+ if(!rs.next() || rs.getInt(1) < 1) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Publishing Portlet Application: "+app.getContextPath());
+ }
+ appStmt.setString(1, app.getContextPath());
+ appStmt.addBatch();
+ }
+
+ rs.close();
+
+ Iterator portlets = app.getPortlets().iterator();
+ while(portlets.hasNext()) {
+ PortletWindowConfig window = (PortletWindowConfig)portlets.next();
+ portletTestStmt.setString(1, app.getContextPath());
+ portletTestStmt.setString(2, window.getPortletName());
+ rs = portletTestStmt.executeQuery();
+
+ if(!rs.next() || rs.getInt(1) < 1) {
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Publishing Portlet: "+app.getContextPath() + " --> " + window.getPortletName());
+ }
+
+ pStmt.setString(1, app.getContextPath());
+ pStmt.setString(2, window.getPortletName());
+ pStmt.addBatch();
+ }
+ }
+ appStmt.executeBatch();
+ pStmt.executeBatch();
+ conn.commit();
+ }
+ catch(SQLException sql) {
+ if(conn != null)
+ conn.rollback();
+ LOG.error("Unable to seed portlet application.", sql);
+ throw sql;
+ }
+ finally {
+ if(conn != null)
+ conn.setAutoCommit(autoCommit);
+ cleanup(null, appTestStmt, null);
+ cleanup(null, pStmt, null);
+ cleanup(conn, appStmt, null);
+ }
}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/DriverAdministrationException.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/DriverAdministrationException.java?rev=354130&r1=354129&r2=354130&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/DriverAdministrationException.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/DriverAdministrationException.java Mon Dec 5 11:10:23 2005
@@ -25,6 +25,10 @@
*/
public class DriverAdministrationException extends ServletException {
+ public DriverAdministrationException(String string) {
+ super(string);
+ }
+
public DriverAdministrationException(String string, Throwable throwable) {
super(string, throwable);
}
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/PortletRegistryAdminService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/PortletRegistryAdminService.java?rev=354130&r1=354129&r2=354130&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/PortletRegistryAdminService.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/admin/PortletRegistryAdminService.java Mon Dec 5 11:10:23 2005
@@ -11,6 +11,6 @@
*/
public interface PortletRegistryAdminService {
- void addPortletApplication(PortletApplicationConfig app) throws DriverAdministrationException;
+ void addPortletApplication(String portletContext) throws DriverAdministrationException;
}
Modified: portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml?rev=354130&r1=354129&r2=354130&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml (original)
+++ portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/pluto-portal-driver-services-config.xml Mon Dec 5 11:10:23 2005
@@ -49,6 +49,10 @@
<property name="portletPreferencesService"><ref local="PortletPreferencesService"/></property>
</bean>
+ <bean id="AdminConfiguration" class="org.apache.pluto.driver.config.impl.AdminConfigurationImpl">
+ <property name="portletRegistryAdminService"><ref local="PortletRegistryConfig"/></property>
+ </bean>
+
<!-- ================================================ -->
<!-- Portal Services injected into the Configuration -->
<!-- ================================================ -->
Modified: portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/web.xml?rev=354130&r1=354129&r2=354130&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/web.xml (original)
+++ portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/web.xml Mon Dec 5 11:10:23 2005
@@ -33,6 +33,13 @@
</servlet>
<servlet>
+ <servlet-name>portletApplicationPublisher</servlet-name>
+ <display-name>Portlet Application Publisher</display-name>
+ <description>Portlet Application Publisher Service</description>
+ <servlet-class>org.apache.pluto.driver.PublishServlet</servlet-class>
+ </servlet>
+
+ <servlet>
<servlet-name>tckDriver</servlet-name>
<display-name>Pluto TCK Driver</display-name>
<description>Pluto TCK Driver Controller</description>
@@ -42,6 +49,11 @@
<servlet-mapping>
<servlet-name>plutoPortalDriver</servlet-name>
<url-pattern>/portal/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>portletApplicationPublisher</servlet-name>
+ <url-pattern>/admin/Publish</url-pattern>
</servlet-mapping>
<servlet-mapping>