01: package com.xoetrope.service;
02:
03: import java.util.Enumeration;
04: import java.util.Hashtable;
05: import net.xoetrope.optional.service.ServiceContext;
06: import net.xoetrope.optional.service.ServiceProxy;
07: import net.xoetrope.optional.service.ServiceProxyArgs;
08: import net.xoetrope.optional.service.ServiceProxyException;
09:
10: /**
11: * Logs service calls to a file specified in the startup properties as the
12: * 'logfile' parameter.
13: *
14: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
15: * the GNU Public License (GPL), please see license.txt for more details. If
16: * you make commercial use of this software you must purchase a commercial
17: * license from Xoetrope.</p>
18: * <p> $Revision: 1.7 $</p>
19: */
20: public class XLoggingService extends ServiceProxy {
21: private LogWriter logWriter;
22:
23: /**
24: * Sets up a logging service by getting an instance of teh LogWrite class.
25: */
26: public XLoggingService() {
27: status = OK;
28: logWriter = LogWriter.getInstance();
29: }
30:
31: /**
32: * Logs the call, its arguments and the response. The call is forwarded to the
33: * next service proxy in the chain.
34: * @param method the method name to be invoked
35: * @param context the context of the service call
36: * @return the response or result of the call
37: * @throws ServiceProxyException
38: */
39: public Object call(String method, ServiceContext context)
40: throws ServiceProxyException {
41: ServiceProxyArgs args = context.getArgs();
42: try {
43: status = STARTED;
44: String route = getRouteName();
45: logWriter.log(route, "Method=" + method);
46: /*int numArgs = args.getNumArgs();
47: for ( int i = 0; i < numArgs; i++ ) {
48: String arg = args.getParam( i ).toString();
49: logWriter.log( route, " arg(" + i + ") name=" + args.getParam( i ) + " length=" + Integer.toString( arg.length() ) + " value=" + arg );
50: }*/
51: Hashtable passArgs = context.getPassArgs();
52: Enumeration keys = passArgs.keys();
53: int i = 0;
54: while (keys.hasMoreElements()) {
55: String name = (String) keys.nextElement();
56: String value = (String) passArgs.get(name);
57: logWriter.log(route, " arg(" + i + ") name=" + value
58: + " length=" + Integer.toString(value.length())
59: + " value=" + value);
60: i++;
61: }
62:
63: String res = nextProxy.call(method, context).toString();
64: logWriter.log(route, " Response=" + method);
65: status = COMPLETE;
66: return res;
67: } catch (ServiceProxyException ex) {
68: status = FAILED;
69: logWriter.log(method, "Exception: "
70: + ex.getLocalizedMessage());
71: throw (ex);
72: }
73: }
74: }
|