提交 36542549 编写于 作者: S Sebastien Deleuze 提交者: Rossen Stoyanchev

Add HTTP status to ServletRequestHandledEvent

Issue: SPR-12119
上级 5857cef0
/*
* 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.
......@@ -28,7 +28,7 @@ package org.springframework.web.context.support;
@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 */
......@@ -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.
......@@ -62,6 +65,7 @@ public class ServletRequestHandledEvent extends RequestHandledEvent {
this.clientAddress = clientAddress;
this.method = method;
this.servletName = servletName;
this.statusCode = -1;
}
/**
......@@ -86,6 +90,33 @@ public class ServletRequestHandledEvent extends RequestHandledEvent {
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;
}
......@@ -117,6 +148,14 @@ public class ServletRequestHandledEvent extends RequestHandledEvent {
return this.servletName;
}
/**
* Return the HTTP status code of the response or -1 if the status
* code is not available.
* @since 4.1
*/
public int getStatusCode() {
return this.statusCode;
}
@Override
public String getShortDescription() {
......
......@@ -993,7 +993,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
}
}
publishRequestHandledEvent(request, startTime, failureCause);
publishRequestHandledEvent(request, response, startTime, failureCause);
}
}
......@@ -1054,7 +1054,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
}
}
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;
......@@ -1063,7 +1063,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
request.getRequestURI(), request.getRemoteAddr(),
request.getMethod(), getServletConfig().getServletName(),
WebUtils.getSessionId(request), getUsernameForRequest(request),
processingTime, failureCause));
processingTime, failureCause, response.getStatus()));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册