Hi,
Is it possible to get the name of the service that invoked the current service?
I am using log4j and want the logger name to be the interface + service of the service that invoke the logging method.
something like:
myPackage.a.b:serviceC
-> doStuff
-> logging.logWARN
Instead of giving the logger name “myPackage.a.b:serviceC” as an argument, it would be nice if I inside logging.logWARN could programatically retrieve that info.
thanks Morten
Invesigate this java service.
import com.wm.util.JournalLogger
IDataCursor idcPipeline = pipeline.getCursor();
com.wm.lang.ns.NSService cs = com.wm.app.b2b.server.Service.getCallingService();
String csStr = cs.toString();
idcPipeline.insertAfter("callingServiceName",csStr);
IData idataInput = IDataFactory.create(1);
IDataHashCursor idc = idataInput.getHashCursor();
idc.insertAfter("message", csStr);
idc.insertAfter("function", "");
idc.insertAfter("level", "4");
try {
Service.doInvoke( "pub.flow", "debugLog", (IData)idataInput );
}
catch (Exception e) {
e.printStackTrace();
I think what you are loking for is stacktrace.
Try this Java code it works as service inside IS runtime but should also work within your logger.
IDataHashCursor curs = pipeline.getHashCursor();
String caller = "SVC - ";
try
{
Thread t = Thread.currentThread();
com.wm.app.b2b.server.ServerThread st = (com.wm.app.b2b.server.ServerThread)t;
java.util.Stack stack = st.getState().getCallStack();
for (int i = 0; i < stack.size(); i++)
{
if (i < stack.size() - 1)
{
caller += stack.elementAt(i).toString();
caller += " ";
}
}
}
catch (Exception e)
{
caller = new String("non-determinable");
}
curs.last();
curs.insertAfter("serviceName", caller);
Here is a much more slimed down approach…
try
{
IDataCursor pipelineCursor = pipeline.getCursor();
IDataUtil.put(pipelineCursor,"currentServiceName",Service.getCallingService().toString());
pipelineCursor.destroy();
}
catch (Exception e)
{
throw new ServiceException(e.toString());
}
Thank you
Both methods work.
One interesting thing to notice is that if you use these methods in a debug mode (stepping through some service), the caller can’t be determined. Both methods (stack and callingService) returns wm.server.flow:stepFlow instead of the correct service name.
wm.server.flow:stepFlow is one of the Debug API services of the Flow engine, but they are just services like any other. The Developer drives a debug session through these services, so in this case stepFlow was the service executed, which in tern was passed information on what service/subservice to execute.
There are a few subtle behavior differences between stepping and running a Flow, but it means there is one code path to handle incoming service invocations. The debug interface goes through the same codepath.