Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/delibero.git

Loading configuration from external file.

AuthorDave Jarvis <email>
Date2015-01-21 15:27:14 GMT-0800
Commit503c7257d883db656312d3d04e7ce71b175fe776
Parentcb6e953
build.gradle
buildMenu.dependsOn( copyLibraries )
-run.dependsOn( createServletMap )
-run.dependsOn( buildMenu )
-run.dependsOn( copyResources )
+run.dependsOn( [createServletMap, buildMenu, copyResources] )
dependencies {
compile "org.eclipse.jetty:jetty-xml:9.2.6.v20141205"
compile "org.eclipse.jetty:jetty-servlet:9.2.6.v20141205"
+ compile "org.eclipse.jetty:jetty-io:9.2.6.v20141205"
// Logging, security, and persistence are cross-cutting concerns
resources/jetty.xml
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
+
+<Configure id="Discuss" class="org.eclipse.jetty.server.Server">
+ <New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
+ <Set name="secureScheme">https</Set>
+ <Set name="securePort"><Property name="jetty.tls.port" default="8443" /></Set>
+ <Set name="outputBufferSize">65536</Set>
+ <Set name="requestHeaderSize">8192</Set>
+ <Set name="responseHeaderSize">8192</Set>
+ </New>
+ <Call name="addConnector">
+ <Arg>
+ <New class="org.eclipse.jetty.server.ServerConnector">
+ <Arg name="server"><Ref refid="Discuss" /></Arg>
+ <Arg name="acceptors" type="int"><Property name="http.acceptors" default="-1"/></Arg>
+ <Arg name="selectors" type="int"><Property name="http.selectors" default="-1"/></Arg>
+ <Arg name="factories">
+ <Array type="org.eclipse.jetty.server.ConnectionFactory">
+ <Item>
+ <New class="org.eclipse.jetty.server.HttpConnectionFactory">
+ <Arg name="config"><Ref refid="httpConfig" /></Arg>
+ </New>
+ </Item>
+ </Array>
+ </Arg>
+ <Set name="host"><Property name="jetty.host" default="localhost" /></Set>
+ <Set name="port"><Property name="jetty.port" default="8080" /></Set>
+ </New>
+ </Arg>
+ </Call>
+</Configure>
+
source/java/to/discuss/Main.java
import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.xml.XmlConfiguration;
+
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.config.IniSecurityManagerFactory;
public class Main implements Base {
public void run() throws Exception {
- Server server = new Server( 8080 );
ServletContextHandler context = new ServletContextHandler();
configureAuthProperties();
configureSystemProperties();
configureServletMap( context );
configureServletDefault( context );
+
+ Server server = createServer();
+ configure( server );
server.setHandler( context );
server.start();
server.join();
+ }
+
+ /**
+ * Returns a new server instance, not yet configured.
+ *
+ * @return A non-null server instance.
+ */
+ protected Server createServer() throws Exception {
+ return new Server();
+ }
+
+ /**
+ * Creates a new configuration and applies the settings to the given
+ * server instance.
+ *
+ * @param server The server instance to configure.
+ */
+ protected void configure( Server server ) throws Exception {
+ createConfiguration().configure( server );
+ }
+
+ /**
+ * Creates a new configuration file based on "jetty.xml".
+ */
+ protected XmlConfiguration createConfiguration() throws Exception {
+ return new XmlConfiguration( open( getConfigurationFile() ) );
+ }
+
+ /**
+ * Returns the default configuration filename to load. The file should
+ * be located in the resources directory.
+ *
+ * @return "jetty.xml" by default.
+ */
+ protected String getConfigurationFile() {
+ return "jetty.xml";
}
Delta76 lines added, 4 lines removed, 72-line increase