001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.pageflow;
020:
021: import org.apache.struts.action.ActionMapping;
022: import org.apache.struts.action.ActionForm;
023: import org.apache.struts.action.ActionForward;
024: import org.apache.struts.config.ModuleConfig;
025: import org.apache.beehive.netui.util.internal.InternalStringBuilder;
026: import org.apache.beehive.netui.util.logging.Logger;
027:
028: import javax.servlet.ServletContext;
029:
030: /**
031: * Default event reporter. Logs every event when the log level is set to "debug" or "trace".
032: */
033: public class DefaultPageFlowEventReporter extends PageFlowEventReporter {
034: private static final Logger _log = Logger
035: .getInstance(DefaultPageFlowEventReporter.class);
036:
037: protected DefaultPageFlowEventReporter(ServletContext servletContext) {
038: super (servletContext);
039: }
040:
041: public void actionRaised(RequestContext requestContext,
042: FlowController flowController, ActionMapping mapping,
043: ActionForm form)
044:
045: {
046: if (_log.isDebugEnabled()) {
047: LogMsg msg = new LogMsg("actionRaised");
048: msg.addParam("FlowController", flowController);
049: msg.addParam("ActionMapping", mapping);
050: msg.addParam("ActionForm", form);
051: msg.addParam("Request", requestContext.getRequest());
052: msg.addParam("Response", requestContext.getResponse());
053: _log.debug(msg);
054: }
055: }
056:
057: public void actionSuccess(RequestContext requestContext,
058: FlowController flowController, ActionMapping mapping,
059: ActionForm form, ActionForward result, long timeTakenMillis) {
060: if (_log.isDebugEnabled()) {
061: LogMsg msg = new LogMsg("actionSuccess");
062: msg.addParam("FlowController", flowController);
063: msg.addParam("ActionMapping", mapping);
064: msg.addParam("ActionForm", form);
065: msg.addParam("Request", requestContext.getRequest());
066: msg.addParam("Response", requestContext.getResponse());
067: msg.addParam("ActionForward", result);
068: msg.addParam("TimeTakenMillis", new Long(timeTakenMillis));
069: _log.debug(msg);
070: }
071: }
072:
073: public void exceptionRaised(RequestContext requestContext,
074: Throwable ex, ActionMapping actionMapping, ActionForm form,
075: FlowController flowController) {
076: if (_log.isDebugEnabled()) {
077: LogMsg msg = new LogMsg("exceptionRaised");
078: msg.addParam("Throwable", ex);
079: msg.addParam("ActionMapping", actionMapping);
080: msg.addParam("ActionForm", form);
081: msg.addParam("FlowController", flowController);
082: msg.addParam("Request", requestContext.getRequest());
083: msg.addParam("Response", requestContext.getResponse());
084: _log.debug(msg);
085: }
086: }
087:
088: public void exceptionHandled(RequestContext requestContext,
089: Throwable ex, ActionMapping actionMapping, ActionForm form,
090: FlowController flowController, ActionForward result,
091: long timeTakenMillis) {
092: if (_log.isDebugEnabled()) {
093: LogMsg msg = new LogMsg("exceptionHandled");
094: msg.addParam("Throwable", ex);
095: msg.addParam("ActionMapping", actionMapping);
096: msg.addParam("ActionForm", form);
097: msg.addParam("FlowController", flowController);
098: msg.addParam("Request", requestContext.getRequest());
099: msg.addParam("Response", requestContext.getResponse());
100: msg.addParam("ActionForward", result);
101: msg.addParam("TimeTakenMillis", new Long(timeTakenMillis));
102: _log.debug(msg);
103: }
104: }
105:
106: public void flowControllerCreated(RequestContext requestContext,
107: FlowController flowController) {
108: if (_log.isDebugEnabled()) {
109: LogMsg msg = new LogMsg("flowControllerCreated");
110: msg.addParam("FlowController", flowController);
111: msg.addParam("Request", requestContext.getRequest());
112: msg.addParam("Response", requestContext.getResponse());
113: _log.debug(msg);
114: }
115: }
116:
117: public void flowControllerDestroyed(FlowController flowController,
118: Object storageLocation) {
119: if (_log.isDebugEnabled()) {
120: LogMsg msg = new LogMsg("flowControllerDestroyed");
121: msg.addParam("FlowController", flowController);
122: msg.addParam("StorageLocation", storageLocation);
123: _log.debug(msg);
124: }
125: }
126:
127: public void beginActionRequest(RequestContext requestContext) {
128: if (_log.isDebugEnabled()) {
129: LogMsg msg = new LogMsg("beginActionRequest");
130: msg.addParam("Request", requestContext.getRequest());
131: msg.addParam("Response", requestContext.getResponse());
132: _log.debug(msg);
133: }
134: }
135:
136: public void endActionRequest(RequestContext requestContext,
137: long timeTakenMillis) {
138: if (_log.isDebugEnabled()) {
139: LogMsg msg = new LogMsg("endActionRequest");
140: msg.addParam("Request", requestContext.getRequest());
141: msg.addParam("Response", requestContext.getResponse());
142: msg.addParam("TimeTakenMillis", new Long(timeTakenMillis));
143: _log.debug(msg);
144: }
145: }
146:
147: public void beginPageRequest(RequestContext requestContext) {
148: if (_log.isDebugEnabled()) {
149: LogMsg msg = new LogMsg("beginPageRequest");
150: msg.addParam("Request", requestContext.getRequest());
151: msg.addParam("Response", requestContext.getResponse());
152: _log.debug(msg);
153: }
154: }
155:
156: public void endPageRequest(RequestContext requestContext,
157: long timeTakenMillis) {
158: if (_log.isDebugEnabled()) {
159: LogMsg msg = new LogMsg("endPageRequest");
160: msg.addParam("Request", requestContext.getRequest());
161: msg.addParam("Response", requestContext.getResponse());
162: msg.addParam("TimeTakenMillis", new Long(timeTakenMillis));
163: _log.debug(msg);
164: }
165: }
166:
167: public void flowControllerRegistered(String modulePath,
168: String controllerClassName, ModuleConfig moduleConfig) {
169: if (_log.isDebugEnabled()) {
170: LogMsg msg = new LogMsg("flowControllerRegistered");
171: msg.addParam("ModulePath", modulePath);
172: msg.addParam("ControllerClassName", controllerClassName);
173: msg.addParam("ModuleConfig", moduleConfig);
174: _log.debug(msg);
175: }
176: }
177:
178: protected static class LogMsg {
179: private String _eventName;
180: private InternalStringBuilder _logMessage;
181:
182: public LogMsg(String eventName) {
183: _eventName = eventName;
184: }
185:
186: public void addParam(String name, Object value) {
187: if (_logMessage == null) {
188: _logMessage = new InternalStringBuilder(_eventName)
189: .append(": ");
190: } else {
191: _logMessage.append(", ");
192: }
193:
194: _logMessage.append(name).append('=').append(value);
195: }
196:
197: public String toString() {
198: return _logMessage == null ? _eventName : _logMessage
199: .toString();
200: }
201: }
202: }
|