001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.web.context.support;
018:
019: /**
020: * Servlet-specific subclass of RequestHandledEvent,
021: * adding servlet-specific context information.
022: *
023: * @author Juergen Hoeller
024: * @since 2.0
025: * @see org.springframework.web.servlet.FrameworkServlet
026: * @see org.springframework.context.ApplicationContext#publishEvent
027: */
028: public class ServletRequestHandledEvent extends RequestHandledEvent {
029:
030: /** URL that the triggered the request */
031: private final String requestUrl;
032:
033: /** IP address that the request came from */
034: private final String clientAddress;
035:
036: /** Usually GET or POST */
037: private final String method;
038:
039: /** Name of the servlet that handled the request */
040: private final String servletName;
041:
042: /**
043: * Create a new ServletRequestHandledEvent.
044: * @param source the component that published the event
045: * @param requestUrl the URL of the request
046: * @param clientAddress the IP address that the request came from
047: * @param method the HTTP method of the request (usually GET or POST)
048: * @param servletName the name of the servlet that handled the request
049: * @param sessionId the id of the HTTP session, if any
050: * @param userName the name of the user that was associated with the
051: * request, if any (usually the UserPrincipal)
052: * @param processingTimeMillis the processing time of the request in milliseconds
053: */
054: public ServletRequestHandledEvent(Object source, String requestUrl,
055: String clientAddress, String method, String servletName,
056: String sessionId, String userName, long processingTimeMillis) {
057:
058: super (source, sessionId, userName, processingTimeMillis);
059: this .requestUrl = requestUrl;
060: this .clientAddress = clientAddress;
061: this .method = method;
062: this .servletName = servletName;
063: }
064:
065: /**
066: * Create a new ServletRequestHandledEvent.
067: * @param source the component that published the event
068: * @param requestUrl the URL of the request
069: * @param clientAddress the IP address that the request came from
070: * @param method the HTTP method of the request (usually GET or POST)
071: * @param servletName the name of the servlet that handled the request
072: * @param sessionId the id of the HTTP session, if any
073: * @param userName the name of the user that was associated with the
074: * request, if any (usually the UserPrincipal)
075: * @param processingTimeMillis the processing time of the request in milliseconds
076: * @param failureCause the cause of failure, if any
077: */
078: public ServletRequestHandledEvent(Object source, String requestUrl,
079: String clientAddress, String method, String servletName,
080: String sessionId, String userName,
081: long processingTimeMillis, Throwable failureCause) {
082:
083: super (source, sessionId, userName, processingTimeMillis,
084: failureCause);
085: this .requestUrl = requestUrl;
086: this .clientAddress = clientAddress;
087: this .method = method;
088: this .servletName = servletName;
089: }
090:
091: /**
092: * Return the URL of the request.
093: */
094: public String getRequestUrl() {
095: return requestUrl;
096: }
097:
098: /**
099: * Return the IP address that the request came from.
100: */
101: public String getClientAddress() {
102: return clientAddress;
103: }
104:
105: /**
106: * Return the HTTP method of the request (usually GET or POST).
107: */
108: public String getMethod() {
109: return method;
110: }
111:
112: /**
113: * Return the name of the servlet that handled the request.
114: */
115: public String getServletName() {
116: return servletName;
117: }
118:
119: public String getShortDescription() {
120: StringBuffer sb = new StringBuffer();
121: sb.append("url=[").append(getRequestUrl()).append("]; ");
122: sb.append("client=[").append(getClientAddress()).append("]; ");
123: sb.append(super .getShortDescription());
124: return sb.toString();
125: }
126:
127: public String getDescription() {
128: StringBuffer sb = new StringBuffer();
129: sb.append("url=[").append(getRequestUrl()).append("]; ");
130: sb.append("client=[").append(getClientAddress()).append("]; ");
131: sb.append("method=[").append(getMethod()).append("]; ");
132: sb.append("servlet=[").append(getServletName()).append("]; ");
133: sb.append(super .getDescription());
134: return sb.toString();
135: }
136:
137: public String toString() {
138: return ("ServletRequestHandledEvent: " + getDescription());
139: }
140:
141: }
|