webMethods Java service to get Context ID for services
Context IDâs are required for accessing most of the services in Monitor API's. Unfortunately there are no public flow services provided by webMethods to know the current context ID's.
However, webMethods Java library provide some API's to extract the context ID. Following is the code for extracting the context ID.
Remember that Java flow service coded here will have a unique context ID and the caller service will have another one. So, caller services should take the parent ID as its context ID.
public static final void getContextIDs(IData pipeline) throws ServiceException {
String[] contextStack;
String currentContextID = "";
String currentParentID = "";
String currentRootID = "";
try{
contextStack = InvokeState.getCurrentState().getAuditRuntime().getContextStack();
if(contextStack!=null)
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.
pipelineCursor_1.destroy();
}
