1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.web.context.support;
  17. import org.springframework.context.ApplicationEvent;
  18. /**
  19. * Event raised when a request is handled within a WebApplicationContext.
  20. * Supported by Spring's own FrameworkServlet, but can also be raised
  21. * by any other web component.
  22. * @author Rod Johnson
  23. * @since January 17, 2001
  24. * @see org.springframework.web.servlet.FrameworkServlet
  25. */
  26. public class RequestHandledEvent extends ApplicationEvent {
  27. private String url;
  28. private long timeMillis;
  29. private String ipAddress;
  30. /** Usually GET or POST */
  31. private String method;
  32. /** Name of the servlet that handled this request is available */
  33. private String servletName;
  34. /** Cause of failure, if any */
  35. private Throwable failureCause;
  36. public RequestHandledEvent(Object source, String url, long timeMillis, String ipAddress,
  37. String method, String servletName) {
  38. super(source);
  39. this.url = url;
  40. this.timeMillis = timeMillis;
  41. this.ipAddress = ipAddress;
  42. this.method = method;
  43. this.servletName = servletName;
  44. }
  45. public RequestHandledEvent(Object source, String url, long timeMillis, String ipAddress,
  46. String method, String servletName, Throwable ex) {
  47. this(source, url, timeMillis, ipAddress, method, servletName);
  48. this.failureCause = ex;
  49. }
  50. public String getURL() {
  51. return url;
  52. }
  53. public long getTimeMillis() {
  54. return timeMillis;
  55. }
  56. public String getIpAddress() {
  57. return ipAddress;
  58. }
  59. public String getMethod() {
  60. return method;
  61. }
  62. public String getServletName() {
  63. return servletName;
  64. }
  65. public boolean wasFailure() {
  66. return failureCause != null;
  67. }
  68. public Throwable getFailureCause() {
  69. return failureCause;
  70. }
  71. public String toString() {
  72. StringBuffer sb = new StringBuffer("RequestHandledEvent: url=[");
  73. sb.append(getURL()).append("] time=").append(getTimeMillis()).append("ms");
  74. sb.append(" client=").append(getIpAddress()).append(" method='").append(getMethod());
  75. sb.append("' servlet='").append(getServletName()).append("'");
  76. sb.append(" status=");
  77. if (!wasFailure()) {
  78. sb.append("OK");
  79. }
  80. else {
  81. sb.append("failed: ").append(getFailureCause());
  82. }
  83. return sb.toString();
  84. }
  85. }