Author: snoopdave
Date: Tue May 29 11:29:36 2007
New Revision: 542611
URL: http://svn.apache.org/viewvc?view=rev&rev=542611
Log:
Changes to RollerContext described in Easy Install proposal:
http://cwiki.apache.org/confluence/display/ROLLER/Proposal+Easy+Install
* Change contextInitialized() so that it initializes only the UI portions of
Roller
** Move RollerImpl initialization into RollerImpl classes
* Change contextInitialized() so that it does not throw exceptions
** So context will load regardless of Roller configuration
Modified:
roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
roller/trunk/src/org/apache/roller/business/jpa/JPARollerImpl.java
roller/trunk/src/org/apache/roller/business/runnable/ThreadManager.java
roller/trunk/src/org/apache/roller/business/runnable/ThreadManagerImpl.java
roller/trunk/src/org/apache/roller/config/PingConfig.java
roller/trunk/src/org/apache/roller/ui/core/RollerContext.java
Modified:
roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
URL:
http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java?view=diff&rev=542611&r1=542610&r2=542611
==============================================================================
---
roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
(original)
+++
roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
Tue May 29 11:29:36 2007
@@ -42,10 +42,7 @@
static final long serialVersionUID = 5256135928578074652L;
- private static Log mLogger = LogFactory.getLog(HibernateRollerImpl.class);
-
- // our singleton instance
- private static HibernateRollerImpl me = null;
+ private static Log mLogger = LogFactory.getLog(HibernateRollerImpl.class);
// a persistence utility class
private HibernatePersistenceStrategy strategy = null;
@@ -82,17 +79,14 @@
* Instantiates and returns an instance of HibernateRollerImpl.
*/
public static Roller instantiate() throws RollerException {
- if (me == null) {
- mLogger.debug("Instantiating HibernateRollerImpl");
- me = new HibernateRollerImpl();
-
- // Now that Roller has been instantiated, initialize individual managers
- me.getPropertiesManager();
- me.getIndexManager();
- me.getThemeManager();
- }
-
- return me;
+ mLogger.debug("Instantiating HibernateRollerImpl");
+ Roller roller = new HibernateRollerImpl();
+
+ // Now that Roller has been instantiated, initialize individual
managers
+ roller.getPropertiesManager();
+ roller.getIndexManager();
+ roller.getThemeManager();
+ return roller;
}
Modified: roller/trunk/src/org/apache/roller/business/jpa/JPARollerImpl.java
URL:
http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/business/jpa/JPARollerImpl.java?view=diff&rev=542611&r1=542610&r2=542611
==============================================================================
--- roller/trunk/src/org/apache/roller/business/jpa/JPARollerImpl.java
(original)
+++ roller/trunk/src/org/apache/roller/business/jpa/JPARollerImpl.java Tue May
29 11:29:36 2007
@@ -126,7 +126,13 @@
*/
public static Roller instantiate() throws RollerException {
logger.debug("Instantiating JPARollerImpl");
- return new JPARollerImpl();
+ Roller roller = new JPARollerImpl();
+
+ // Now that Roller has been instantiated, initialize individual
managers
+ roller.getPropertiesManager();
+ roller.getIndexManager();
+ roller.getThemeManager();
+ return roller;
}
public void flush() throws RollerException {
Modified:
roller/trunk/src/org/apache/roller/business/runnable/ThreadManager.java
URL:
http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/business/runnable/ThreadManager.java?view=diff&rev=542611&r1=542610&r2=542611
==============================================================================
--- roller/trunk/src/org/apache/roller/business/runnable/ThreadManager.java
(original)
+++ roller/trunk/src/org/apache/roller/business/runnable/ThreadManager.java Tue
May 29 11:29:36 2007
@@ -30,6 +30,12 @@
/**
+ * Schedule execution of all configured tasks.
+ */
+ public void startTasks();
+
+
+ /**
* Execute runnable in background (asynchronously).
* @param runnable
* @throws java.lang.InterruptedException
Modified:
roller/trunk/src/org/apache/roller/business/runnable/ThreadManagerImpl.java
URL:
http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/business/runnable/ThreadManagerImpl.java?view=diff&rev=542611&r1=542610&r2=542611
==============================================================================
--- roller/trunk/src/org/apache/roller/business/runnable/ThreadManagerImpl.java
(original)
+++ roller/trunk/src/org/apache/roller/business/runnable/ThreadManagerImpl.java
Tue May 29 11:29:36 2007
@@ -24,8 +24,11 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.config.RollerConfig;
/**
@@ -46,6 +49,42 @@
serviceScheduler = Executors.newScheduledThreadPool(10);
}
+ public void startTasks() {
+
+ Date now = new Date();
+
+ // okay, first we look for what tasks have been enabled
+ String tasksStr = RollerConfig.getProperty("tasks.enabled");
+ String[] tasks = StringUtils.stripAll(StringUtils.split(tasksStr,
","));
+ for (int i=0; i < tasks.length; i++) {
+
+ String taskClassName = RollerConfig.getProperty("tasks."+tasks[i]+".class");
+ if(taskClassName != null) {
+ log.info("Initializing task: "+tasks[i]);
+
+ try {
+ Class taskClass = Class.forName(taskClassName);
+ RollerTask task = (RollerTask) taskClass.newInstance();
+ task.init();
+
+ Date startTime = task.getStartTime(now);
+ if(startTime == null || now.after(startTime)) {
+ startTime = now;
+ }
+
+ // schedule it
+ scheduleFixedRateTimerTask(task, startTime,
task.getInterval());
+
+ } catch (ClassCastException ex) {
+ log.warn("Task does not extend RollerTask class", ex);
+ } catch (RollerException ex) {
+ log.error("Error scheduling task", ex);
+ } catch (Exception ex) {
+ log.error("Error instantiating task", ex);
+ }
+ }
+ }
+ }
public void executeInBackground(Runnable runnable)
throws InterruptedException {
Modified: roller/trunk/src/org/apache/roller/config/PingConfig.java
URL:
http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/config/PingConfig.java?view=diff&rev=542611&r1=542610&r2=542611
==============================================================================
--- roller/trunk/src/org/apache/roller/config/PingConfig.java (original)
+++ roller/trunk/src/org/apache/roller/config/PingConfig.java Tue May 29
11:29:36 2007
@@ -98,6 +98,28 @@
// targets that implement minor variants of the WeblogUpdates.ping call.
// This is initialized once at startup, and referenced when pings are made.
private static final Map configuredVariants = new HashMap();
+
+
+ static {
+ try {
+ // Initialize common targets from the configuration
+ initializeCommonTargets();
+ // Initialize ping variants
+ initializePingVariants();
+ // Remove custom ping targets if they have been disallowed
+ if (getDisallowCustomTargets()) {
+ logger.info("Custom ping targets have been disallowed. Removing
any existing custom targets.");
+
RollerFactory.getRoller().getPingTargetManager().removeAllCustomPingTargets();
+ }
+ // Remove all autoping configurations if ping usage has been
disabled.
+ if (PingConfig.getDisablePingUsage()) {
+ logger.info("Ping usage has been disabled. Removing any existing
auto ping configurations.");
+
RollerFactory.getRoller().getAutopingManager().removeAllAutoPings();
+ }
+ } catch (RollerException e) {
+ logger.error("ERROR configing ping managers", e);
+ }
+ }
// Inhibit construction
Modified: roller/trunk/src/org/apache/roller/ui/core/RollerContext.java
URL:
http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/RollerContext.java?view=diff&rev=542611&r1=542610&r2=542611
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/RollerContext.java (original)
+++ roller/trunk/src/org/apache/roller/ui/core/RollerContext.java Tue May 29
11:29:36 2007
@@ -32,6 +32,7 @@
import org.acegisecurity.providers.encoding.PasswordEncoder;
import org.acegisecurity.providers.encoding.ShaPasswordEncoder;
import org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint;
+import org.acegisecurity.userdetails.jdbc.JdbcDaoImpl;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -52,14 +53,14 @@
import org.apache.roller.util.cache.CacheManager;
import org.apache.velocity.runtime.RuntimeSingleton;
import org.springframework.context.ApplicationContext;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;
/**
- * Responds to app init/destroy events and holds Roller instance.
- *
- * @web.listener
+ * Initialize the Roller web application/context.
*/
public class RollerContext extends ContextLoaderListener
implements ServletContextListener {
@@ -79,24 +80,14 @@
*/
public void contextInitialized(ServletContextEvent sce) {
- log.info("Roller Weblogger Initializing ...");
-
- // check that Hibernate code is in place
- try {
- Class.forName("org.hibernate.Session");
- } catch (Throwable t) {
- // if Hibernate is not available, we're hosed
- throw new RuntimeException(
- "FATAL ERROR: Hibernate not found, please refer to the Roller
Installation Guide for instructions on how to install the required Hibernate jars");
- }
-
- // keep a reverence to ServletContext object
+ log.info("Apache Roller Weblogger Initializing ...");
+
+ // Keep a reverence to ServletContext object
this.servletContext = sce.getServletContext();
- // call Spring's context ContextLoaderListener to initialize
- // all the context files specified in web.xml. This is necessary
- // because listeners don't initialize in the order specified in
- // 2.3 containers
+ // Call Spring's context ContextLoaderListener to initialize all the
+ // context files specified in web.xml. This is necessary because
+ // listeners don't initialize in the order specified in 2.3 containers
super.contextInitialized(sce);
// get the *real* path to <context>/resources
@@ -127,54 +118,47 @@
RollerConfig.setThemesDir(servletContext.getRealPath("/")+File.separator+"themes");
try {
- // always upgrade database first
+ // Parts of database upgrade are not included in migration scripts
upgradeDatabaseIfNeeded();
- Roller roller = RollerFactory.getRoller();
-
- setupRuntimeProperties();
+ // Initialize Aceigy based on Roller configuration
initializeSecurityFeatures(servletContext);
- setupSearch();
- initializePingFeatures();
- setupThemeLibrary();
- setupScheduledTasks();
+
+ // Setup Velocity template engine
setupVelocity();
- roller.flush();
- roller.release();
+ // This will cause instantiation and initialziation of Roller impl
+ Roller roller = RollerFactory.getRoller();
+
+ // And this will schedule all configured tasks
+ roller.getThreadManager().startTasks();
} catch (Throwable t) {
log.fatal("Roller Weblogger initialization failed", t);
- throw new RuntimeException(t);
}
// Initialize Planet if necessary
if(RollerConfig.getBooleanProperty("planet.aggregator.enabled")) {
try {
- Planet planet = PlanetFactory.getPlanet();
-
- setupPlanetProperties();
-
+ Planet planet = PlanetFactory.getPlanet();
+ PlanetFactory.getPlanet().getPropertiesManager();
planet.flush();
planet.release();
} catch (Throwable t) {
log.fatal("Roller Planet initialization failed", t);
- throw new RuntimeException(t);
}
}
- log.info("Roller Weblogger Initialization Complete");
+ log.info("Apache Roller Weblogger Initialization Complete");
}
/**
* Responds to app-destroy event and triggers shutdown sequence.
*/
- public void contextDestroyed(ServletContextEvent sce) {
-
- RollerFactory.getRoller().shutdown();
-
+ public void contextDestroyed(ServletContextEvent sce) {
+ RollerFactory.getRoller().shutdown();
// do we need a more generic mechanism for presentation layer shutdown?
CacheManager.shutdown();
}
@@ -193,8 +177,7 @@
/**
* Initialize the Velocity rendering engine.
*/
- private void setupVelocity() throws Exception {
-
+ private void setupVelocity() throws Exception {
log.info("Initializing Velocity");
// initialize the Velocity engine
@@ -224,106 +207,16 @@
}
}
-
-
- /**
- * Initialize the runtime configuration.
- */
- private void setupRuntimeProperties() throws Exception {
- // PropertiesManager initializes itself
- RollerFactory.getRoller().getPropertiesManager();
- }
-
-
- /**
- * Initialize the built-in search engine.
- */
- private void setupSearch() throws Exception {
- // IndexManager initializes itself
- RollerFactory.getRoller().getIndexManager();
- }
-
-
- /**
- * Initialize the Theme Library.
- */
- private void setupThemeLibrary() throws Exception {
- // theme manager initializes itself
- RollerFactory.getRoller().getThemeManager();
- }
-
-
- /**
- * Start up any scheduled background jobs.
- */
- private void setupScheduledTasks() throws Exception {
-
- ThreadManager tmgr = RollerFactory.getRoller().getThreadManager();
-
- Date now = new Date();
-
- // okay, first we look for what tasks have been enabled
- String tasksStr = RollerConfig.getProperty("tasks.enabled");
- String[] tasks = StringUtils.stripAll(StringUtils.split(tasksStr,
","));
- for (int i=0; i < tasks.length; i++) {
-
- String taskClassName = RollerConfig.getProperty("tasks."+tasks[i]+".class");
- if(taskClassName != null) {
- log.info("Initializing task: "+tasks[i]);
-
- try {
- Class taskClass = Class.forName(taskClassName);
- RollerTask task = (RollerTask) taskClass.newInstance();
- task.init();
-
- Date startTime = task.getStartTime(now);
- if(startTime == null || now.after(startTime)) {
- startTime = now;
- }
-
- // schedule it
- tmgr.scheduleFixedRateTimerTask(task, startTime,
task.getInterval());
-
- } catch (ClassCastException ex) {
- log.warn("Task does not extend RollerTask class", ex);
- } catch (RollerException ex) {
- log.error("Error scheduling task", ex);
- } catch (Exception ex) {
- log.error("Error instantiating task", ex);
- }
- }
- }
- }
-
-
- // Initialize ping features
- private void initializePingFeatures() throws RollerException {
-
- // Initialize common targets from the configuration
- PingConfig.initializeCommonTargets();
- // Initialize ping variants
- PingConfig.initializePingVariants();
- // Remove custom ping targets if they have been disallowed
- if (PingConfig.getDisallowCustomTargets()) {
- log.info("Custom ping targets have been disallowed. Removing any
existing custom targets.");
-
RollerFactory.getRoller().getPingTargetManager().removeAllCustomPingTargets();
- }
- // Remove all autoping configurations if ping usage has been disabled.
- if (PingConfig.getDisablePingUsage()) {
- log.info("Ping usage has been disabled. Removing any existing auto
ping configurations.");
-
RollerFactory.getRoller().getAutopingManager().removeAllAutoPings();
- }
- }
-
-
+
/**
* Setup Acegi security features.
*/
- protected void initializeSecurityFeatures(ServletContext context) {
-
+ protected void initializeSecurityFeatures(ServletContext context) throws RollerException {
+
ApplicationContext ctx =
WebApplicationContextUtils.getRequiredWebApplicationContext(context);
+
String rememberMe = RollerConfig.getProperty("rememberme.enabled");
boolean rememberMeEnabled = Boolean.valueOf(rememberMe).booleanValue();
@@ -336,6 +229,7 @@
provider.getProviders().add(ctx.getBean("rememberMeAuthenticationProvider"));
}
+
String encryptPasswords =
RollerConfig.getProperty("passwds.encryption.enabled");
boolean doEncrypt = Boolean.valueOf(encryptPasswords).booleanValue();
@@ -358,11 +252,14 @@
}
}
+
if (RollerConfig.getBooleanProperty("securelogin.enabled")) {
AuthenticationProcessingFilterEntryPoint entryPoint =
-
(AuthenticationProcessingFilterEntryPoint)ctx.getBean("authenticationProcessingFilterEntryPoint");
+ (AuthenticationProcessingFilterEntryPoint)
+ ctx.getBean("authenticationProcessingFilterEntryPoint");
entryPoint.setForceHttps(true);
}
+
/*
if (RollerConfig.getBooleanProperty("schemeenforcement.enabled")) {
@@ -389,19 +286,8 @@
*/
}
-
- /**
- * Initialize the Roller Planet runtime configuration.
- */
- private void setupPlanetProperties() throws Exception {
- // Planet PropertiesManager initializes itself
- PlanetFactory.getPlanet().getPropertiesManager();
- }
-
-
/**
* Get the ServletContext.
- *
* @return ServletContext
*/
public static ServletContext getServletContext() {
@@ -411,56 +297,49 @@
/**
* Get an instance of AutoProvision, if available in roller.properties
- *
* @return AutoProvision
*/
- public static AutoProvision getAutoProvision() {
-
- String clazzName = RollerConfig.getProperty("users.sso.autoProvision.className");
-
- if(null == clazzName) {
- return null;
- }
-
- Class clazz;
- try {
- clazz = Class.forName(clazzName);
- } catch (ClassNotFoundException e) {
- log.warn("Unable to found specified Auto Provision class.", e);
- return null;
- }
-
- if(null == clazz) {
- return null;
- }
-
- Class[] interfaces = clazz.getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- if (interfaces[i].equals(AutoProvision.class))
- {
- try {
- return (AutoProvision) clazz.newInstance();
- } catch (InstantiationException e) {
- log.warn("InstantiationException while creating: " + clazzName,
e);
- } catch (IllegalAccessException e) {
- log.warn("IllegalAccessException while creating: " + clazzName,
e);
+ public static AutoProvision getAutoProvision() {
+ String clazzName = RollerConfig.getProperty("users.sso.autoProvision.className");
+
+ if (null == clazzName) {
+ return null;
+ }
+
+ Class clazz;
+ try {
+ clazz = Class.forName(clazzName);
+ } catch (ClassNotFoundException e) {
+ log.warn("Unable to found specified Auto Provision class.", e);
+ return null;
+ }
+
+ if(null == clazz) {
+ return null;
+ }
+
+ Class[] interfaces = clazz.getInterfaces();
+ for (int i = 0; i < interfaces.length; i++) {
+ if (interfaces[i].equals(AutoProvision.class)) {
+ try {
+ return (AutoProvision) clazz.newInstance();
+ } catch (InstantiationException e) {
+ log.warn("InstantiationException while creating: " +
clazzName, e);
+ } catch (IllegalAccessException e) {
+ log.warn("IllegalAccessException while creating: " +
clazzName, e);
+ }
}
- }
- }
-
- return null;
-
+ }
+ return null;
}
/**
- * Access to the plugin manager for the UI layer.
- *
- * TODO: we may want something similar to the Roller interface for the
- * ui layer if we dont' want methods like this here in RollerContext.
+ * Access to the plugin manager for the UI layer. TODO: we may want
+ * something similar to the Roller interface for the UI layer if we dont
+ * want methods like this here in RollerContext.
*/
public static UIPluginManager getUIPluginManager() {
- // TODO: we may want to do this another way
return UIPluginManagerImpl.getInstance();
}