From f2bd99c91b3d615c9fea4f9195fe1a888a2d93e8 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 22 Sep 2013 20:25:21 -0700 Subject: 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. --- src/com/p4square/grow/GrowProcessComponent.java | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/com/p4square/grow/GrowProcessComponent.java (limited to 'src/com/p4square/grow/GrowProcessComponent.java') 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 + */ +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(); + } +} -- cgit v1.2.3