summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2013-09-22 20:25:21 -0700
committerJesse Morgan <jesse@jesterpm.net>2013-09-22 20:25:21 -0700
commit96c4b0fea8203a0520a42b56c468dc7f3ca49673 (patch)
treeb12a0ce7fce0da67924114c5da79493169291314
parent8b6dce760201677bb6a8eba37cabd87d826687ce (diff)
Fixing tomcat config overrides.
Finally fixing config overrides. Found a bug? in restlet where the Servlet context parameters aren't passed to the final application. I'm working around the issue by creating my own component which builds the config and shares it with the frontend and backend. Overall I think it's a much more elegant solution. Now we have the ability to specify an external config file for the F1 credentials and the ability configure different domains in different tomcat containers.
-rw-r--r--src/com/p4square/grow/GrowProcessComponent.java59
-rw-r--r--src/com/p4square/grow/backend/GrowBackend.java23
-rw-r--r--src/com/p4square/grow/frontend/GrowFrontend.java20
-rw-r--r--src/grow.properties5
-rw-r--r--web/META-INF/context.xml2
-rw-r--r--web/WEB-INF/restlet.xml20
-rw-r--r--web/WEB-INF/web.xml4
7 files changed, 73 insertions, 60 deletions
diff --git a/src/com/p4square/grow/GrowProcessComponent.java b/src/com/p4square/grow/GrowProcessComponent.java
new file mode 100644
index 0000000..4196a5e
--- /dev/null
+++ b/src/com/p4square/grow/GrowProcessComponent.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow;
+
+import org.restlet.Component;
+import org.restlet.data.Protocol;
+
+import com.p4square.grow.backend.GrowBackend;
+import com.p4square.grow.config.Config;
+import com.p4square.grow.frontend.GrowFrontend;
+
+/**
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class GrowProcessComponent extends Component {
+ private final Config mConfig;
+
+ /**
+ * Create a new Grow Process website component combining a frontend and backend.
+ */
+ public GrowProcessComponent() throws Exception {
+ // Clients
+ getClients().add(Protocol.FILE);
+ getClients().add(Protocol.HTTP);
+ getClients().add(Protocol.HTTPS);
+
+ // Prepare mConfig
+ mConfig = new Config();
+
+ // Frontend
+ GrowFrontend frontend = new GrowFrontend(mConfig);
+ getDefaultHost().attach(frontend);
+
+ // Backend
+ GrowBackend backend = new GrowBackend(mConfig);
+ getInternalRouter().attach("/backend", backend);
+ }
+
+ @Override
+ public void start() throws Exception {
+ // Load mConfigs
+ mConfig.updateConfig(this.getClass().getResourceAsStream("/grow.properties"));
+
+ String configDomain = getContext().getParameters().getFirstValue("com.p4square.grow.configDomain");
+ if (configDomain != null) {
+ mConfig.setDomain(configDomain);
+ }
+
+ String configFilename = getContext().getParameters().getFirstValue("com.p4square.grow.configFile");
+ if (configFilename != null) {
+ mConfig.updateConfig(configFilename);
+ }
+
+ super.start();
+ }
+}
diff --git a/src/com/p4square/grow/backend/GrowBackend.java b/src/com/p4square/grow/backend/GrowBackend.java
index 09c1d84..7da6fff 100644
--- a/src/com/p4square/grow/backend/GrowBackend.java
+++ b/src/com/p4square/grow/backend/GrowBackend.java
@@ -34,7 +34,11 @@ public class GrowBackend extends Application {
private final CassandraDatabase mDatabase;
public GrowBackend() {
- mConfig = new Config();
+ this(new Config());
+ }
+
+ public GrowBackend(Config config) {
+ mConfig = config;
mDatabase = new CassandraDatabase();
}
@@ -71,23 +75,6 @@ public class GrowBackend extends Application {
public void start() throws Exception {
super.start();
- // Load config
- final String configDomain =
- getContext().getParameters().getFirstValue("configDomain");
- if (configDomain != null) {
- mConfig.setDomain(configDomain);
- }
-
- mConfig.updateConfig(this.getClass().getResourceAsStream("/grow.properties"));
-
- final String configFilename =
- getContext().getParameters().getFirstValue("configFile");
-
- if (configFilename != null) {
- LOG.info("Loading configuration from " + configFilename);
- mConfig.updateConfig(configFilename);
- }
-
// Setup database
mDatabase.setClusterName(mConfig.getString("clusterName", "Dev Cluster"));
mDatabase.setKeyspaceName(mConfig.getString("keyspace", "GROW"));
diff --git a/src/com/p4square/grow/frontend/GrowFrontend.java b/src/com/p4square/grow/frontend/GrowFrontend.java
index 07abd16..ecb2475 100644
--- a/src/com/p4square/grow/frontend/GrowFrontend.java
+++ b/src/com/p4square/grow/frontend/GrowFrontend.java
@@ -55,28 +55,16 @@ public class GrowFrontend extends FMFacade {
mConfig = new Config();
}
+ public GrowFrontend(Config config) {
+ mConfig = config;
+ }
+
public Config getConfig() {
return mConfig;
}
@Override
public synchronized void start() throws Exception {
- final String configDomain =
- getContext().getParameters().getFirstValue("configDomain");
- if (configDomain != null) {
- mConfig.setDomain(configDomain);
- }
-
- mConfig.updateConfig(this.getClass().getResourceAsStream("/grow.properties"));
-
- final String configFilename =
- getContext().getParameters().getFirstValue("configFile");
-
- if (configFilename != null) {
- LOG.info("Loading configuration from " + configFilename);
- mConfig.updateConfig(configFilename);
- }
-
Template errorTemplate = getTemplate("templates/error.ftl");
if (errorTemplate != null) {
ErrorPage.setTemplate(errorTemplate);
diff --git a/src/grow.properties b/src/grow.properties
index 6dd282c..d9d3f29 100644
--- a/src/grow.properties
+++ b/src/grow.properties
@@ -7,11 +7,6 @@ dev.dynamicRoot =
*.staticRoot = /grow-frontend
*.dynamicRoot = /grow-frontend
-*.f1ConsumerKey = 123
-*.f1ConsumerSecret = password-here
-*.f1BaseUrl = staging.fellowshiponeapi.com
-*.f1ChurchCode = pfseawa
-
prod.postAccountCreationPage = http://foursquaregrow.com/login.html
# Backend Settings
diff --git a/web/META-INF/context.xml b/web/META-INF/context.xml
index 24744f5..c8a8f07 100644
--- a/web/META-INF/context.xml
+++ b/web/META-INF/context.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<Context>
- <Parameter name="configFile" value="grow.properties" override="false"/>
+ <Parameter name="com.p4square.grow.configDomain" value="prod" override="true"/>
</Context>
diff --git a/web/WEB-INF/restlet.xml b/web/WEB-INF/restlet.xml
deleted file mode 100644
index 67ee36d..0000000
--- a/web/WEB-INF/restlet.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0"?>
-<component xmlns="http://www.restlet.org/schemas/2.0/Component">
- <client protocol="FILE" />
- <client protocol="HTTP" />
- <client protocol="HTTPS" />
- <server protocols="HTTP HTTPS" />
-
- <defaultHost>
- <attach uripattern="/images" targetDescriptor="war:///images" />
- <attach uripattern="/scripts" targetDescriptor="war:///scripts" />
- <attach uripattern="/style.css" targetDescriptor="war:///style.css" />
- <attach uripattern="/favicon.ico" targetDescriptor="war:///favicon.ico" />
- <attach uriPattern="" targetClass="com.p4square.grow.frontend.GrowFrontend" />
- </defaultHost>
-
- <internalRouter>
- <attach uriPattern="/backend"
- targetClass="com.p4square.grow.backend.GrowBackend" />
- </internalRouter>
-</component>
diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml
index 758b004..4b85bde 100644
--- a/web/WEB-INF/web.xml
+++ b/web/WEB-INF/web.xml
@@ -14,6 +14,10 @@
<servlet-class>
org.restlet.ext.servlet.ServerServlet
</servlet-class>
+ <init-param>
+ <param-name>org.restlet.component</param-name>
+ <param-value>com.p4square.grow.GrowProcessComponent</param-value>
+ </init-param>
</servlet>
<!-- Catch all requests -->