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

Include HTTP status code in ServletRequestHandledEvent #638

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@
@SuppressWarnings("serial")
public class ServletRequestHandledEvent extends RequestHandledEvent {

/** URL that the triggered the request */
/** URL that triggered the request */
private final String requestUrl;

/** IP address that the request came from */
Expand All @@ -40,6 +40,9 @@ public class ServletRequestHandledEvent extends RequestHandledEvent {
/** Name of the servlet that handled the request */
private final String servletName;

/** HTTP status code of the response */
private final int statusCode;


/**
* Create a new ServletRequestHandledEvent.
Expand All @@ -62,6 +65,7 @@ public ServletRequestHandledEvent(Object source, String requestUrl,
this.clientAddress = clientAddress;
this.method = method;
this.servletName = servletName;
this.statusCode = -1;
}

/**
Expand All @@ -86,6 +90,33 @@ public ServletRequestHandledEvent(Object source, String requestUrl,
this.clientAddress = clientAddress;
this.method = method;
this.servletName = servletName;
this.statusCode = -1;
}

/**
* Create a new ServletRequestHandledEvent.
* @param source the component that published the event
* @param requestUrl the URL of the request
* @param clientAddress the IP address that the request came from
* @param method the HTTP method of the request (usually GET or POST)
* @param servletName the name of the servlet that handled the request
* @param sessionId the id of the HTTP session, if any
* @param userName the name of the user that was associated with the
* request, if any (usually the UserPrincipal)
* @param processingTimeMillis the processing time of the request in milliseconds
* @param failureCause the cause of failure, if any
* @param statusCode the HTTP status code of the response
*/
public ServletRequestHandledEvent(Object source, String requestUrl,
String clientAddress, String method, String servletName, String sessionId,
String userName, long processingTimeMillis, Throwable failureCause, int statusCode) {

super(source, sessionId, userName, processingTimeMillis, failureCause);
this.requestUrl = requestUrl;
this.clientAddress = clientAddress;
this.method = method;
this.servletName = servletName;
this.statusCode = statusCode;
}


Expand Down Expand Up @@ -117,6 +148,14 @@ public String getServletName() {
return this.servletName;
}

/**
* Return the HTTP status code of the response.
* If the status code is not defined, return -1.
* @since 4.1
*/
public int getStatusCode() {
return statusCode;
}

@Override
public String getShortDescription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ protected final void processRequest(HttpServletRequest request, HttpServletRespo
}
}

publishRequestHandledEvent(request, startTime, failureCause);
publishRequestHandledEvent(request, response, startTime, failureCause);
}
}

Expand Down Expand Up @@ -1054,7 +1054,7 @@ private void resetContextHolders(HttpServletRequest request,
}
}

private void publishRequestHandledEvent(HttpServletRequest request, long startTime, Throwable failureCause) {
private void publishRequestHandledEvent(HttpServletRequest request, HttpServletResponse response, long startTime, Throwable failureCause) {
if (this.publishEvents) {
// Whether or not we succeeded, publish an event.
long processingTime = System.currentTimeMillis() - startTime;
Expand All @@ -1063,7 +1063,7 @@ private void publishRequestHandledEvent(HttpServletRequest request, long startTi
request.getRequestURI(), request.getRemoteAddr(),
request.getMethod(), getServletConfig().getServletName(),
WebUtils.getSessionId(request), getUsernameForRequest(request),
processingTime, failureCause));
processingTime, failureCause, response.getStatus()));
}
}

Expand Down