Skip to content

Commit

Permalink
Correcting logic around classIsPresent
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Oct 15, 2021
1 parent bf66c83 commit 453f597
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.component.LifeCycle;

/**
Expand Down Expand Up @@ -222,31 +221,30 @@ enum State {
String fileName;
String resource;

// Default to non-modern Jetty (ie: Jetty 9.3 or earlier)
// Jetty 9.4.x and newer is considered modern.
boolean modernJettyRequestLog = false;
boolean modernJettyRequestLog;
boolean quiet = false;

public RequestLogImpl() {
putObject(CoreConstants.EVALUATOR_MAP, new HashMap<String, EventEvaluator<?>>());

// plumb the depths of Jetty and the environment ...
try {
Class.forName("jakarta.servlet.http.HttpServlet");
if (classIsPresent("jakarta.servlet.http.HttpServlet")) {
throw new RuntimeException("The new jakarta.servlet classes are not supported by this " +
"version of logback-access (check for a newer version of logback-access that " +
"does support it)");
} catch(Throwable ignore) {
// Class doesn't exist, assumption is that this is normal javax.servlet environment.
}

// look for modern approach to RequestLog
modernJettyRequestLog = classIsPresent("org.eclipse.jetty.server.CustomRequestLog");
}

private boolean classIsPresent(String className) {
try {
Class.forName("org.eclipse.jetty.server.CustomRequestLog");
// Class exists, treat as modern Jetty.
modernJettyRequestLog = true;
} catch(Throwable ignore) {
// Class doesn't exist, this is an old school Jetty.
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

Expand Down

0 comments on commit 453f597

Please sign in to comment.