webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

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

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

    Posted Mon October 15, 2018 10:31 AM

    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


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 2.  RE: How to get the name of a string var through an imput java service

    Posted Mon October 15, 2018 12:53 PM

    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.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 3.  RE: How to get the name of a string var through an imput java service

    Posted Mon October 15, 2018 01:08 PM

    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…


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 4.  RE: How to get the name of a string var through an imput java service

    Posted Mon October 15, 2018 01:25 PM

    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).


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 5.  RE: How to get the name of a string var through an imput java service

    Posted Mon October 15, 2018 02:02 PM

    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


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 6.  RE: How to get the name of a string var through an imput java service

    Posted Mon October 15, 2018 02:50 PM

    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.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 7.  RE: How to get the name of a string var through an imput java service

    Posted Mon October 15, 2018 02:59 PM

    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.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 8.  RE: How to get the name of a string var through an imput java service

    Posted Mon October 15, 2018 03:02 PM

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

    Regards


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 9.  RE: How to get the name of a string var through an imput java service

    Posted Mon October 15, 2018 03:19 PM

    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.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 10.  RE: How to get the name of a string var through an imput java service

    Posted Tue October 16, 2018 04:37 AM

    No problem Rob.
    Thank you for your useful help.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 11.  RE: How to get the name of a string var through an imput java service

    Posted Tue October 16, 2018 05:19 AM

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


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods