Package: trapperkeeper-webserver-jetty9-clojure / 1.7.0-2

0003-TK-369-Add-LifeCycleImplementingRequestLogImpl.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From: Matthaus Owens <matthaus@puppet.com>
Date: Thu, 2 Mar 2017 10:44:01 -0800
Subject: (TK-369) Add LifeCycleImplementingRequestLogImpl

As of Jetty 9.3, logback's RequestLogImpl will no longer auto-start
because it no longer implements Jetty's LifeCycle interface (because
Jetty refactored the RequestLog interfact to no longer extend the
LifeCycle interface). In order for our request logger to auto-start, we
extend logback's implementation and have it implement Jetty's LifeCycle
interface (which it already does).
---
 .../utils/LifeCycleImplementingRequestLogImpl.java | 32 ++++++++++++++++++++++
 .../services/webserver/jetty9_config.clj           |  7 ++---
 2 files changed, 35 insertions(+), 4 deletions(-)
 create mode 100644 java/com/puppetlabs/trapperkeeper/services/webserver/jetty9/utils/LifeCycleImplementingRequestLogImpl.java

diff --git a/java/com/puppetlabs/trapperkeeper/services/webserver/jetty9/utils/LifeCycleImplementingRequestLogImpl.java b/java/com/puppetlabs/trapperkeeper/services/webserver/jetty9/utils/LifeCycleImplementingRequestLogImpl.java
new file mode 100644
index 0000000..c29363a
--- /dev/null
+++ b/java/com/puppetlabs/trapperkeeper/services/webserver/jetty9/utils/LifeCycleImplementingRequestLogImpl.java
@@ -0,0 +1,32 @@
+package com.puppetlabs.trapperkeeper.services.webserver.jetty9.utils;
+
+import ch.qos.logback.access.jetty.RequestLogImpl;
+import org.eclipse.jetty.util.component.LifeCycle;
+
+/*
+	Sit down, it's story time.
+	Once upon a time logback had a RequestLogImpl that you could just drop in
+	Jetty and use without any modifications. Developers used this and it was
+	good. Then, during Jetty 9.3 development, the RequestLog interface that
+	RequestLogImpl implemented was "refactored"[0] to no longer extend Jetty's
+	LifeCycle interface (this is distinct from Logback's LifeCycle interface,
+	so try to keep up).
+	Implementing Jetty's LifeCycle interface turns out to be important because
+	Jetty uses it to decide whether or not to automatically start a Bean[1].
+	Many people were sad about this[2] and tried to make the RequestLogImpl
+	again start automatically with Jetty[3], but their efforts have so far not
+	been merged.
+	In order for our RequestLogImpl to automatically start, we decide to extend
+	the existing built-in logback implementation and have it implement Jetty's
+	LifeCycle interface, which it already does, but doesn't declare.
+
+	[0] - https://github.com/eclipse/jetty.project/commit/e3bda4ef
+	[1] - https://github.com/eclipse/jetty.project/blob/0c8273f2ca1f9bf2064cd9c4c939d2546443f759/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java#L98
+	[2] - https://jira.qos.ch/browse/LOGBACK-1052
+	[3] - https://github.com/qos-ch/logback/pull/269
+
+	And Jetty and Logback lived happily ever after.
+
+ */
+
+public class LifeCycleImplementingRequestLogImpl extends RequestLogImpl implements LifeCycle {}
diff --git a/src/puppetlabs/trapperkeeper/services/webserver/jetty9_config.clj b/src/puppetlabs/trapperkeeper/services/webserver/jetty9_config.clj
index 21a6085..7c8629f 100644
--- a/src/puppetlabs/trapperkeeper/services/webserver/jetty9_config.clj
+++ b/src/puppetlabs/trapperkeeper/services/webserver/jetty9_config.clj
@@ -2,11 +2,11 @@
   (:import [java.security KeyStore]
            (java.io FileInputStream)
            (org.eclipse.jetty.server.handler RequestLogHandler)
-           (ch.qos.logback.access.jetty RequestLogImpl)
            (org.eclipse.jetty.server Server)
            (org.codehaus.janino ScriptEvaluator)
            (org.codehaus.commons.compiler CompileException)
-           (java.lang.reflect InvocationTargetException))
+           (java.lang.reflect InvocationTargetException)
+           (com.puppetlabs.trapperkeeper.services.webserver.jetty9.utils LifeCycleImplementingRequestLogImpl))
   (:require [clojure.tools.logging :as log]
             [clojure.string :as str]
             [me.raynes.fs :as fs]
@@ -444,11 +444,10 @@
   init-log-handler :- RequestLogHandler
   [config :- WebserverRawConfig]
   (let [handler (RequestLogHandler.)
-        logger (RequestLogImpl.)]
+        logger (LifeCycleImplementingRequestLogImpl.)]
     (.setFileName logger (:access-log-config config))
     (.setQuiet logger true)
     (.setRequestLog handler logger)
-    (.start logger)
     handler))
 
 (defn maybe-init-log-handler