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();
}
Enjoy Reading , If you have any Question related to webMethods please comment below , I will try to answer the questions.Please Subscribe for latest update on the blogs
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();
}
Enjoy Reading , If you have any Question related to webMethods please comment below , I will try to answer the questions.Please Subscribe for latest update on the blogs
4 Comments
contextStack is not necessarily in order, so unable to decide which one is what context?
ReplyDeleteThanks for Information SAP Online Training
ReplyDeleteHi Rakesh ,
ReplyDeleteI tried with this code and it is working fine . Please see the below code :-
public static void getContextID() throws ServiceException {
InvokeState is = InvokeState.getCurrentState();
IAuditRuntime iar = is.getAuditRuntime();
String[] contextStack = iar.getContextStack();
PRootContextId = iar.ROOTCTX_ID;
PParentId = iar.PARENT_ID;
PContextId = iar.getCurrentAuditedContextId();
if (contextStack.length > 0) {
PRootContextId = contextStack[0];
PParentId = PRootContextId;
}
if (contextStack.length > 1) {
PParentId = contextStack[1];
}
if (PContextId==null)
if (contextStack.length > 2) PContextId = contextStack[contextStack.length-1];
else if (contextStack.length > 1) PContextId = PParentId;
else PContextId = PRootContextId;
}
Great, thanks for sharing this post.Much thanks again. Awesome.
ReplyDeletemulesoft training
linux training
mulesoft training
web methods training