How to get the name of a string var through an imput java service

Hi,

I have a very simple java service.
I send a string to my java service, but how can I do to get the initial name of my var ? (it is a need for doing some looging)

Example (see the atttached picture please) :

“myVar1” is mapped to “input1”
In the testVar service, how to retrieve the “myVar1” name ? (of course, I don’t want to explore the pipeline to get it)

Regards

It could be done but would require, as you note, an exploration of the pipeline AND reverse engineering the FLOW service itself to know what var was mapped to your input var.

My advice – don’t do this. If you need to log the var name, have the service that “owns” the var do the logging. Your Java service should have knowledge only of its inputs and outputs.

1 Like

Thank you Rob
I understand what you’re saying but I can’t do what you recommend me, because my initial aim was to create a function (java service) that automatically log some variables (name key + value).
If I do it in the parent service flow…i’m loosing the java added value… and the sharing function principle.

never mind…

Well, IMO, you’re violating modularity and segregation principles. What you’re doing is akin to a class method knowing the name of the variable used by the code that calls the method. In structured programming, that is a distinct no-no.

Perhaps logging the pipeline will do what you’re after. You can do this:

Create your own FLOW service. Named perhaps “logMyPipeline”.

Set the “Enable auditing” and “Include pipeline” properties for that service to “Always”

Within it, call pub.prt.log:logActivityMessages (assuming you have PRT/PE).

Call it from your “parent” service. Passing whatever makes sense for FullMessage/BriefMessage (nothing is okay).

This will log everything in the pipeline. Then you can use MWS to review the audit log and pipeline.

Another alternative – have the caller pass the name of the var. Then the logging will use the name you want. A maintenance headache of sorts (if anyone changes the var name, they have to remember to change the static input too – but that should be rare).

1 Like

yes you’re right.

I already done the 2nd solution you wrote.
it’s not ideal, but because it is really to debug some litle part of services, some particular cases, it is sufficient.

Thank you

Please try the java code below:


public static final void testspy(IData pipeline) throws ServiceException {
		InvokeState invokeState = InvokeState.getCurrentState();
		FlowState flowState = invokeState.getFlowState();
		if (flowState != null){
			FlowElement flowElement = flowState.current();
			FlowMap inputMap = flowElement.getInputMap();
			FlowElement[] mapNodes = inputMap.getNodes();
			for (FlowElement mapNode : mapNodes){
				if (mapNode instanceof FlowMapCopy){
					FlowMapCopy mapCopyNode = (FlowMapCopy)mapNode;
					Debug.log(0, mapCopyNode.getMapFrom() + " -> " + mapCopyNode.getMapTo());
				}
			}
		}
			
	}

Then you will find something in server log like : /source;1;0 → /target;1;0
The value between “/” and first “;” is the variable name you’re looking for, the number like “1” and “0” specific variable type (string, idata, or object) and variable dimension(list or table), and you could ignore it in your case.

Rob,
I was not trying to violate any principle, I was just trying to know If webMethods permits this kind of advantage using the pipeline.

One of the simplest solution to me would be to just loop the pipeline and get all the strings and just ignoring all IData, array and other complex data.

My services do not have a lot of var during execution (they are dropped as they don’t serve anymore)
In that way I don’t need anymore the need to get their name.

Thanks a lot Xiaowei, I will take a look at your code.

Regards

Xiaowei, that’s the reverse engineering I was referring to. :slight_smile: Cool!

Just keep in mind that those classes are not public and not intended for our use. So support will not help if issues are encountered. But many of us use such classes anyway, as they can be quite useful. :slight_smile:

Cedric – yes, a generic approach that logs everything, or a subset that you mention, would be good. My concern was adding the “knowledge” of the specific var name to the Java service. But it seems I misinterpreted your intent and you were looking for a general approach. Sorry for my confusion.

No problem Rob.
Thank you for your useful help.

Thanks a lot Xiaowei, this works fine ! :slight_smile: