|
41 | 41 | import org.eclipse.jetty.server.Request;
|
42 | 42 | import org.eclipse.jetty.server.RequestLog;
|
43 | 43 | import org.eclipse.jetty.server.Response;
|
44 |
| -import org.eclipse.jetty.util.Jetty; |
45 | 44 | import org.eclipse.jetty.util.component.LifeCycle;
|
46 | 45 |
|
47 | 46 | /**
|
@@ -222,31 +221,30 @@ enum State {
|
222 | 221 | String fileName;
|
223 | 222 | String resource;
|
224 | 223 |
|
225 |
| - // Default to non-modern Jetty (ie: Jetty 9.3 or earlier) |
226 | 224 | // Jetty 9.4.x and newer is considered modern.
|
227 |
| - boolean modernJettyRequestLog = false; |
| 225 | + boolean modernJettyRequestLog; |
228 | 226 | boolean quiet = false;
|
229 | 227 |
|
230 | 228 | public RequestLogImpl() {
|
231 | 229 | putObject(CoreConstants.EVALUATOR_MAP, new HashMap<String, EventEvaluator<?>>());
|
232 | 230 |
|
233 | 231 | // plumb the depths of Jetty and the environment ...
|
234 |
| - try { |
235 |
| - Class.forName("jakarta.servlet.http.HttpServlet"); |
| 232 | + if (classIsPresent("jakarta.servlet.http.HttpServlet")) { |
236 | 233 | throw new RuntimeException("The new jakarta.servlet classes are not supported by this " +
|
237 | 234 | "version of logback-access (check for a newer version of logback-access that " +
|
238 | 235 | "does support it)");
|
239 |
| - } catch(Throwable ignore) { |
240 |
| - // Class doesn't exist, assumption is that this is normal javax.servlet environment. |
241 | 236 | }
|
242 | 237 |
|
243 | 238 | // look for modern approach to RequestLog
|
| 239 | + modernJettyRequestLog = classIsPresent("org.eclipse.jetty.server.CustomRequestLog"); |
| 240 | + } |
| 241 | + |
| 242 | + private boolean classIsPresent(String className) { |
244 | 243 | try {
|
245 |
| - Class.forName("org.eclipse.jetty.server.CustomRequestLog"); |
246 |
| - // Class exists, treat as modern Jetty. |
247 |
| - modernJettyRequestLog = true; |
248 |
| - } catch(Throwable ignore) { |
249 |
| - // Class doesn't exist, this is an old school Jetty. |
| 244 | + Class.forName(className); |
| 245 | + return true; |
| 246 | + } catch (ClassNotFoundException e) { |
| 247 | + return false; |
250 | 248 | }
|
251 | 249 | }
|
252 | 250 |
|
|
0 commit comments