[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [exonerator/master] Make ExoneraTor work from an embedded Jetty.



commit c2731e580b2cd2a638cfe7bdb3b31aa7d0b08767
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date:   Thu Nov 2 12:47:35 2017 +0000

    Make ExoneraTor work from an embedded Jetty.
    
    The default port is 8080 and can be changed by setting system property
    'exonerator.jetty.port', e.g. `-Dexonerator.jetty.port=8888`.
    
    Also added ant task 'smoke-test-war' for creating a dummy war.  This dummy
    war file can be used for smoke-tests not depending on the database resource.
    
    Implements task-24174.
---
 .gitignore                                         |   7 +-
 CHANGELOG.md                                       |   5 +
 build.xml                                          | 112 ++++++++++++++++++---
 .../java/org/torproject/exonerator/ServerMain.java |  32 ++++++
 src/main/resources/context.xml                     |  13 ---
 src/main/resources/jetty.xml                       |  91 +++++++++++++++++
 src/main/resources/logback.xml                     |  57 +++++++++++
 src/main/resources/logging.properties              |   6 --
 src/main/resources/test-web.xml                    |  67 ++++++++++++
 src/main/resources/web.xml                         |  43 ++++++--
 10 files changed, 392 insertions(+), 41 deletions(-)

diff --git a/.gitignore b/.gitignore
index e93ccb8..48cf962 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,10 @@
-# Eclipse files
-.classpath
-.project
+# hidden files
+.*
 
 # Generated stuff
 generated/
+LOGBASE_IS_UNDEFINED/
+cobertura.ser
 
 # library folder
 lib/
diff --git a/CHANGELOG.md b/CHANGELOG.md
index edfd429..b699ba9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# Changes in version 2.0.0 - 2017-11-??
+
+ * Major changes
+   - Use an embedded Jetty.
+
 # Changes in version 1.0.3 - 2017-10-16
 
  * Major changes
diff --git a/build.xml b/build.xml
index ee04e1b..ec861b5 100644
--- a/build.xml
+++ b/build.xml
@@ -10,6 +10,7 @@
   <property name="implementation-title" value="ExoneraTor" />
   <property name="release.version" value="1.0.0-dev" />
   <property name="metricslibversion" value="2.1.1" />
+  <property name="jetty.version" value="-9.2.21.v20170120" />
   <property name="warfile"
             value="exonerator-${release.version}.war"/>
 
@@ -34,6 +35,8 @@
     <include name="commons-codec-1.10.jar"/>
     <include name="commons-lang3-3.5.jar"/>
     <include name="gson-2.4.jar" />
+    <include name="logback-core-1.1.9.jar" />
+    <include name="logback-classic-1.1.9.jar" />
     <include name="postgresql-9.4.1212.jar"/>
     <include name="slf4j-api-1.7.22.jar"/>
   </patternset>
@@ -42,43 +45,126 @@
     <patternset refid="common" />
     <include name="metrics-lib-${metricslibversion}.jar"/>
     <include name="commons-compress-1.13.jar"/>
-    <include name="servlet-api-3.0.jar"/>
-    <include name="logback-core-1.1.9.jar" />
-    <include name="logback-classic-1.1.9.jar" />
+    <include name="servlet-api-3.1.jar"/>
     <include name="xz-1.6.jar"/>
   </patternset>
 
   <patternset id="web" >
-    <patternset refid="common" />
+    <include name="jetty9-annotations${jetty.version}.jar"/>
+    <include name="jetty9-server${jetty.version}.jar"/>
+    <include name="jetty9-servlet${jetty.version}.jar"/>
+    <include name="jetty9-util${jetty.version}.jar"/>
+    <include name="jetty9-http${jetty.version}.jar"/>
+    <include name="jetty9-io${jetty.version}.jar"/>
+    <include name="jetty9-xml${jetty.version}.jar"/>
+    <include name="jetty9-webapp${jetty.version}.jar"/>
+    <include name="jetty9-continuation${jetty.version}.jar"/>
+    <include name="jetty9-security${jetty.version}.jar"/>
+  </patternset>
+
+  <patternset id="webruntime" >
+    <include name="asm-5.2.jar" />
+    <include name="asm-commons-5.2.jar" />
+    <include name="jetty9-plus${jetty.version}.jar"/>
+    <include name="jetty9-jndi${jetty.version}.jar"/>
+    <include name="jetty9-apache-jsp${jetty.version}-tweaked.jar" />
+    <include name="tomcat8-embed-jasper-8.5.14.jar" />
+    <include name="tomcat8-embed-el-8.5.14.jar" />
+    <include name="tomcat8-embed-core-8.5.14.jar" />
+    <include name="eclipse-ecj-3.11.1.jar" />
   </patternset>
 
   <patternset id="runtime" >
     <patternset refid="library" />
+    <patternset refid="web" />
   </patternset>
 
   <!-- Create a .war file for deployment. -->
   <target name="war"
           depends="compile">
+    <echo message="Removing problematic service definitions from"/>
+    <echo message="${libs}/jetty9-apache-jsp${jetty.version}.jar and using "/>
+    <echo message="${libs}/jetty9-apache-jsp${jetty.version}-tweaked.jar below." />
+    <delete file="${libs}/jetty9-apache-jsp${jetty.version}-tweaked.jar"
+            quiet="true" />
+    <jar destfile="${libs}/jetty9-apache-jsp${jetty.version}-tweaked.jar">
+      <zipfileset src="${libs}/jetty9-apache-jsp${jetty.version}.jar" >
+        <exclude name="**/javax.servlet.ServletContainerInitializer"/>
+      </zipfileset>
+    </jar>
     <war destfile="${dist}/${warfile}"
-         webxml="${resources}/web.xml">
+         duplicate="fail"
+         webxml="${resources}/web.xml"
+	       basedir="${classes}">
+      <restrict>
+        <not>
+          <and>
+            <name name="META-INF/*" />
+            <not>
+              <name name="META-INF/services/*" />
+            </not>
+          </and>
+        </not>
+        <archives>
+          <zips>
+            <fileset dir="${libs}">
+              <patternset refid="common" />
+              <patternset refid="web" />
+              <patternset refid="webruntime" />
+            </fileset>
+          </zips>
+        </archives>
+      </restrict>
+      <exclude name="**/Test*.class" />
+      <zipfileset dir="${resources}"
+                  prefix=""
+                  includes="logback.xml" />
       <zipfileset dir="${resources}/web"
                   prefix=""
-                  includes="css/* images/*"/>
+                  includes="css/* images/*" />
       <zipfileset dir="${resources}/web/jsps"
                   prefix="WEB-INF"
                   includes="*.jsp"/>
-      <lib dir="${libs}">
-        <patternset refid="web" />
-      </lib>
-      <classes dir="${classes}"/>
       <zipfileset dir="${resources}"
-                  prefix="WEB-INF/classes"
                   includes="*.properties" />
-      <metainf dir="${resources}"
-               includes="context.xml"/>
+      <fileset dir="${resources}" includes="jetty.xml" />
+      <manifest>
+        <attribute name="Implemented-By" value="The Tor Project" />
+        <attribute name="Implementation-Title" value="Exonerator Server"/>
+        <attribute name="Implementation-Version"
+                   value="${release.version}-${git.revision}"/>
+        <attribute name="Main-Class"
+                   value="org.torproject.exonerator.ServerMain" />
+      </manifest>
     </war>
   </target>
 
+  <!-- Create a test .war file for basic start w/o db resources. -->
+  <target name="smoke-test-war"
+          depends="war">
+
+    <delete file="${generated}/${name}-dummy-test.war"
+            quiet="true" />
+    <copy overwrite="true"
+          file="${resources}/test-web.xml"
+          tofile="${generated}/web.xml"/>
+    <jar destfile="${generated}/${name}-dummy-test.war">
+      <zipfileset src="${dist}/${warfile}" >
+        <exclude name="WEB-INF/web.xml"/>
+      </zipfileset>
+      <zipfileset dir="${generated}"
+                  prefix="WEB-INF"
+                  includes="web.xml" />
+      <manifest>
+        <attribute name="Implemented-By" value="The Tor Project" />
+        <attribute name="Implementation-Title" value="Test Exonerator Server"/>
+        <attribute name="Implementation-Version"
+                   value="${release.version}-${git.revision}"/>
+        <attribute name="Main-Class"
+                   value="org.torproject.exonerator.ServerMain" />
+      </manifest>
+    </jar>
+  </target>
 
   <!-- The following line adds the common targets and properties
        for Metrics' Java Projects.
diff --git a/src/main/java/org/torproject/exonerator/ServerMain.java b/src/main/java/org/torproject/exonerator/ServerMain.java
new file mode 100644
index 0000000..704c7a5
--- /dev/null
+++ b/src/main/java/org/torproject/exonerator/ServerMain.java
@@ -0,0 +1,32 @@
+/* Copyright 2017 The Tor Project
+ * See LICENSE for licensing information */
+
+package org.torproject.exonerator;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.util.resource.Resource;
+import org.eclipse.jetty.xml.XmlConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ServerMain {
+
+  private static final Logger log = LoggerFactory.getLogger(ServerMain.class);
+
+  /** Starts the web server listening for incoming client connections. */
+  public static void main(String[] args) {
+    try {
+      Resource jettyXml = Resource.newSystemResource("jetty.xml");
+      log.info("Reading configuration from '{}'.", jettyXml);
+      XmlConfiguration configuration
+          = new XmlConfiguration(jettyXml.getInputStream());
+      Server server = (Server) configuration.configure();
+      server.start();
+      server.join();
+    } catch (Exception ex) {
+      log.error("Exiting, because of: {}.", ex.getMessage(), ex);
+      System.exit(1);
+    }
+  }
+}
+
diff --git a/src/main/resources/context.xml b/src/main/resources/context.xml
deleted file mode 100644
index 1cf53c5..0000000
--- a/src/main/resources/context.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<Context cookies="false">
-  <Resource name="jdbc/exonerator"
-            type="javax.sql.DataSource"
-            auth="Container"
-            username="metrics"
-            password="password"
-            driverClassName="org.postgresql.Driver"
-            url="jdbc:postgresql://localhost/exonerator"
-            maxActive="8"
-            maxIdle="4"
-            maxWait="15000"/>
-</Context>
-
diff --git a/src/main/resources/jetty.xml b/src/main/resources/jetty.xml
new file mode 100644
index 0000000..ba15c61
--- /dev/null
+++ b/src/main/resources/jetty.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
+  "http://www.eclipse.org/jetty/configure.dtd";>
+
+<Configure id="server" class="org.eclipse.jetty.server.Server" >
+  <Set name="dumpAfterStart">false</Set>
+
+  <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
+    <Set name="minThreads">25</Set>
+    <Set name="maxThreads">250</Set>
+    <Set name="detailedDump">false</Set>
+  </New>
+
+  <New id="webAppContext" class="org.eclipse.jetty.webapp.WebAppContext">
+    <Set name="logUrlOnStart">true</Set>
+    <Set name="contextPath">/</Set>
+    <Set name="war">
+      <SystemProperty name="java.class.path" />
+    </Set>
+    <Call name="setAttribute" >
+      <Arg>org.apache.tomcat.JarScanner</Arg>
+      <Arg>
+        <New class="org.apache.tomcat.util.scan.StandardJarScanner" />
+      </Arg>
+    </Call>
+    <New class="org.eclipse.jetty.plus.jndi.Resource">
+      <Arg><Ref refid="webAppContext" /></Arg>
+      <Arg>jdbc/exonerator</Arg>
+      <Arg>
+        <New class="org.postgresql.ds.PGPoolingDataSource">
+          <Set name="user">dummydatabaseuser</Set>
+          <Set name="password">dummypassword</Set>
+          <Set name="databaseName">exonerator</Set>
+          <Set name="serverName">localhost</Set>
+          <Set name="dataSourceName">exonerator</Set>
+          <Set name="initialConnections">2</Set>
+          <Set name="maxConnections">8</Set>
+          <Call name="initialize" />
+        </New>
+      </Arg>
+    </New>
+  </New>
+
+  <Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="setServerDefault">
+    <Arg><Ref refid="server" /></Arg>
+    <Call name="addBefore">
+      <Arg name="beforeClass">org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Arg>
+      <Arg>
+        <Array type="String">
+          <Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
+        </Array>
+      </Arg>
+    </Call>
+    <Call name="addAfter">
+      <Arg name="afterClass">org.eclipse.jetty.webapp.FragmentConfiguration</Arg>
+      <Arg>
+        <Array type="String">
+          <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
+          <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
+        </Array>
+      </Arg>
+    </Call>
+  </Call>
+
+  <Call name="addConnector">
+    <Arg>
+      <New class="org.eclipse.jetty.server.ServerConnector">
+        <Arg>
+          <Ref id="server"/>
+        </Arg>
+        <Set name="port">
+          <SystemProperty name="exonerator.jetty.port" default="8080" />
+        </Set>
+        <Set name="host">127.0.0.1</Set>
+      </New>
+    </Arg>
+  </Call>
+
+  <Set name="handler">
+    <!-- maybe add more handlers (statistics, logging, etc.) later -->
+    <New class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
+      <Call name="addHandler">
+        <Arg>
+          <Ref id="webAppContext"/>
+        </Arg>
+      </Call>
+    </New>
+  </Set>
+
+</Configure>
+
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml
new file mode 100644
index 0000000..c29c057
--- /dev/null
+++ b/src/main/resources/logback.xml
@@ -0,0 +1,57 @@
+<configuration debug="false">
+
+  <!-- a path and a prefix -->
+  <property name="logfile-base" value="${LOGBASE}/exonerator-" />
+
+  <!-- log file names -->
+  <property name="fileall-logname" value="${logfile-base}all" />
+  <property name="fileerr-logname" value="${logfile-base}err" />
+  <property name="filestatistics-logname" value="${logfile-base}statistics" />
+
+  <!-- date pattern -->
+  <property name="utc-date-pattern" value="%date{ISO8601, UTC}" />
+
+  <!-- appender section -->
+  <appender name="FILEALL" class="ch.qos.logback.core.rolling.RollingFileAppender">
+    <file>${fileall-logname}.log</file>
+    <encoder>
+      <pattern>${utc-date-pattern} %level %logger{20}:%line %msg%n</pattern>
+    </encoder>
+    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+      <!-- rollover daily -->
+      <FileNamePattern>${fileall-logname}.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
+      <maxHistory>10</maxHistory>
+      <timeBasedFileNamingAndTriggeringPolicy
+            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+        <!-- or whenever the file size reaches 1MB -->
+        <maxFileSize>1MB</maxFileSize>
+      </timeBasedFileNamingAndTriggeringPolicy>
+    </rollingPolicy>
+  </appender>
+
+  <appender name="FILEERR" class="ch.qos.logback.core.FileAppender">
+    <file>${fileerr-logname}.log</file>
+    <encoder>
+      <pattern>${utc-date-pattern} %level %logger{20}:%line %msg%n</pattern>
+    </encoder>
+
+    <!-- ERROR or worse -->
+    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+      <level>ERROR</level>
+    </filter>
+  </appender>
+
+  <!-- logger section -->
+  <logger name="org.torproject" >
+    <appender-ref ref="FILEERR" />
+  </logger>
+
+  <logger name="org.eclipse" level="INFO" />
+  <logger name="org.apache" level="INFO" />
+
+  <root level="INFO">
+    <appender-ref ref="FILEALL" />
+  </root>
+
+</configuration>
+
diff --git a/src/main/resources/logging.properties b/src/main/resources/logging.properties
deleted file mode 100644
index 44fbbbe..0000000
--- a/src/main/resources/logging.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-handlers = org.apache.juli.FileHandler
-
-org.apache.juli.FileHandler.level = FINE
-org.apache.juli.FileHandler.directory = ${catalina.base}/logs
-org.apache.juli.FileHandler.prefix = exonerator.
-
diff --git a/src/main/resources/test-web.xml b/src/main/resources/test-web.xml
new file mode 100644
index 0000000..04107f1
--- /dev/null
+++ b/src/main/resources/test-web.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="3.1"
+   xmlns="http://xmlns.jcp.org/xml/ns/javaee";
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
+       http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd";
+   metadata-complete="false" >
+
+  <servlet>
+    <servlet-name>ExoneraTor</servlet-name>
+    <servlet-class>
+      org.torproject.exonerator.ExoneraTorServlet
+    </servlet-class>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>ExoneraTor</servlet-name>
+    <url-pattern>/index.html</url-pattern>
+  </servlet-mapping>
+
+  <servlet>
+    <servlet-name>Default</servlet-name>
+    <servlet-class>
+      org.eclipse.jetty.servlet.DefaultServlet
+    </servlet-class>
+    <init-param>
+      <param-name>aliases</param-name>
+      <param-value>false</param-value>
+    </init-param>
+    <init-param>
+      <param-name>acceptRanges</param-name>
+      <param-value>true</param-value>
+    </init-param>
+    <init-param>
+      <param-name>dirAllowed</param-name>
+      <param-value>false</param-value>
+    </init-param>
+    <init-param>
+      <param-name>welcomeServlets</param-name>
+      <param-value>true</param-value>
+    </init-param>
+    <init-param>
+      <param-name>redirectWelcome</param-name>
+      <param-value>false</param-value>
+    </init-param>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>Default</servlet-name>
+    <url-pattern>/</url-pattern>
+  </servlet-mapping>
+
+  <servlet>
+    <servlet-name>Query</servlet-name>
+    <servlet-class>
+      org.torproject.exonerator.QueryServlet
+    </servlet-class>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>Query</servlet-name>
+    <url-pattern>/query.json</url-pattern>
+  </servlet-mapping>
+
+  <welcome-file-list>
+    <welcome-file>index.html</welcome-file>
+  </welcome-file-list>
+
+</web-app>
+
diff --git a/src/main/resources/web.xml b/src/main/resources/web.xml
index 881a613..78ededd 100644
--- a/src/main/resources/web.xml
+++ b/src/main/resources/web.xml
@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
-
-<web-app version="2.4"
-  xmlns="http://java.sun.com/xml/ns/j2ee";
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
-  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"; >
+<web-app version="3.1"
+   xmlns="http://xmlns.jcp.org/xml/ns/javaee";
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
+       http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd";
+   metadata-complete="false" >
 
   <servlet>
     <servlet-name>ExoneraTor</servlet-name>
@@ -18,6 +18,37 @@
   </servlet-mapping>
 
   <servlet>
+    <servlet-name>Default</servlet-name>
+    <servlet-class>
+      org.eclipse.jetty.servlet.DefaultServlet
+    </servlet-class>
+    <init-param>
+      <param-name>aliases</param-name>
+      <param-value>false</param-value>
+    </init-param>
+    <init-param>
+      <param-name>acceptRanges</param-name>
+      <param-value>true</param-value>
+    </init-param>
+    <init-param>
+      <param-name>dirAllowed</param-name>
+      <param-value>false</param-value>
+    </init-param>
+    <init-param>
+      <param-name>welcomeServlets</param-name>
+      <param-value>true</param-value>
+    </init-param>
+    <init-param>
+      <param-name>redirectWelcome</param-name>
+      <param-value>false</param-value>
+    </init-param>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>Default</servlet-name>
+    <url-pattern>/</url-pattern>
+  </servlet-mapping>
+
+  <servlet>
     <servlet-name>Query</servlet-name>
     <servlet-class>
       org.torproject.exonerator.QueryServlet



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits