Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4467 - Add logging to HttpWebApplicationServer for debugging purposes #4481

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.lang.System.Logger;
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.ERROR;
import static java.lang.System.Logger.Level.TRACE;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -89,6 +90,9 @@ public HttpWebApplicationServer() {
* @param contextPath the context path.
*/
public void addMapping(String servletContextName, String contextPath) {
if (LOGGER.isLoggable(TRACE)) {
LOGGER.log(TRACE, "Adding context path: %s for: %s", contextPath, servletContextName);
}
for (WebApplication webApp : webApplications.values()) {
if (webApp.getServletContextName().equals(servletContextName)) {
requestMapper.addMapping(webApp, contextPath);
Expand All @@ -99,7 +103,9 @@ public void addMapping(String servletContextName, String contextPath) {

@Override
public void addWebApplication(WebApplication webApplication) {
LOGGER.log(DEBUG, () -> "Adding web application with context path: " + webApplication.getContextPath());
if (LOGGER.isLoggable(DEBUG)) {
LOGGER.log(DEBUG, () -> "Adding web application with context path: " + webApplication.getContextPath());
}
webApplications.put(webApplication.getContextPath(), webApplication);
requestMapper.addMapping(webApplication, webApplication.getContextPath());
}
Expand All @@ -111,17 +117,24 @@ public WebApplicationServerRequestMapper getRequestMapper() {

@Override
public void initialize() {
LOGGER.log(DEBUG, "Starting initialization of {0} web application(s)", webApplications.size());
if (LOGGER.isLoggable(DEBUG)) {
LOGGER.log(DEBUG, "Starting initialization of {0} web application(s)", webApplications.size());
}
for (WebApplication webApp : webApplications.values()) {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(webApp.getClassLoader());
if (LOGGER.isLoggable(TRACE)) {
LOGGER.log(TRACE, "Initializing web application at: %s", webApp.getContextPath());
}
webApp.initialize();
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
LOGGER.log(DEBUG, "Finished initialization of {0} web application(s)", webApplications.size());
if (LOGGER.isLoggable(DEBUG)) {
LOGGER.log(DEBUG, "Finished initialization of {0} web application(s)", webApplications.size());
}
}

@Override
Expand All @@ -140,6 +153,11 @@ public HttpServerProcessorEndState process(HttpServerRequest request, HttpServer
} catch (Throwable t) {
LOGGER.log(ERROR, "An error occurred while processing the request", t);
}

if (LOGGER.isLoggable(TRACE)) {
LOGGER.log(TRACE, "Processor end state: %s", state.name());
}

return state;
}

Expand All @@ -154,13 +172,24 @@ public HttpServerProcessorEndState process(HttpServerRequest request, HttpServer
@Override
public void service(WebApplicationRequest request, WebApplicationResponse response) throws IOException, ServletException {
String requestUri = request.getRequestURI();

if (requestUri == null) {
if (LOGGER.isLoggable(TRACE)) {
LOGGER.log(TRACE, "Request URI is invalid");
}
response.sendError(500);
return;
}

if (LOGGER.isLoggable(TRACE)) {
LOGGER.log(TRACE, "Request URI: %s", requestUri);
}

WebApplication webApplication = requestMapper.findMapping(requestUri);
if (webApplication == null) {
if (LOGGER.isLoggable(TRACE)) {
LOGGER.log(TRACE, "No web application found for request URI: %s", requestUri);
}
response.sendError(404);
return;
}
Expand All @@ -174,6 +203,11 @@ public void service(WebApplicationRequest request, WebApplicationResponse respon
request.setWebApplication(webApplication);
response.setWebApplication(webApplication);

if (LOGGER.isLoggable(TRACE)) {
LOGGER.log(TRACE, "Context Path: %s", contextPath);
LOGGER.log(TRACE, "Servlet Path: %s", request.getServletPath());
}

webApplication.service(request, response);

// Make sure the request is fully read wrt parameters (if any still)
Expand Down
Loading