How does webMethods generate the ContextId

Dear Experts
I am designing an Error Handling solution. I need to know how the ContextId is generated in webMethods.
Can someone please help ?

Do you want the flow/java service to generate the contextId or something else?

Yes, correct Mahesh. I am looking for the flow/java service that webMethods uses to generate it. Also, if you could say how that service is called when an error occurs, would be good.

You must be able to find the java service in WmPublic package to get/set the contextId from webMthods 8.2 and up.

Can you share your version? We can write a java code using the wM API.

public static final void getContextIDs(IData pipeline) throws ServiceException {
                                String[] contextStack;
                                String currentContextID = "";
                                String currentParentID = "";
                                String currentRootID = "";
                                                contextStack = InvokeState.getCurrentState().getAuditRuntime().getContextStack();
                                                                if(contextStack.length >=3){
                                                                                currentRootID = contextStack[0];
                                                                                currentParentID = contextStack[1];
                                                                                currentContextID = contextStack[2];
                                                                }else if (contextStack.length>=2){
                                                                                                currentRootID = contextStack[0];
                                                                                                currentParentID = contextStack[1];
                                                                                                currentContextID = currentParentID;
                                                                }else if (contextStack.length>=1){
                                                                                                currentRootID = contextStack[0];
                                                                                                currentParentID = currentRootID;
                                                                                                currentContextID = currentRootID;
                                }catch(Exception ex){
                                                ServiceException sx = new ServiceException(ex);
                                                throw sx;
                                // pipeline
                                IDataCursor pipelineCursor_1 = pipeline.getCursor();
                                IDataUtil.put(pipelineCursor_1, "currentContextID", currentParentID); // Assuming that caller is looking for its context ID. currentContextID extracted is the context ID for the java service, not the caller service.

Hi Mahesh, We are using wM 9.5 in this project.

Hi Mahesh
Thanks for the code for getting the ContextId.

I am actually looking for the services(flow/java) that webMethods uses to generate the ContextId and how those are invoked when an error/exception occurs.

I am not sure! May be others might be able to help you on your question. Keep us posted if you find something.

The generation of contextID is internal and is present in jar files provided by Webmethods. The way it works is like this:

When a service runs it generates a context id. If its a top level service, the root, parent and context id will be same, if its a 1st level child service then the context id will be different , but root and parent context id will be same. If its embedded at level 2 or 3 then all 3 will be different. The SAG code generates a context id whenever it spawns a thread or does an invoke of one process from another.

If you want to get the context id, you can do so using the code Mahesh gave earlier. You can get the context id either if you use the Exception Event manager and set the exception event handling to be synchronous or you can call the exception handling service below getLastError

1 Like