Announcement

Collapse
No announcement yet.

Problem with channelMap.put

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with channelMap.put

    Hello, and happy holidays!

    I'm having some trouble with channelMap (mirth v3.3.2.7911).

    Basically, I'm calling a channel on Mirth (MyListener) with a Web Service. That channel will call a second one that does a bunch of processing (BuildMessageFromPayload) - including a call to a different Service. I wish to take the response obtained from this second channel and send it upstream to MyListener, so as to have it return something back to my original Web Service call. Edit: For the (workaround) solution, see my next reply to this thread. It doesn't solve the channelMap issue, but it behaves the way I intended it to.

    All steps work, but I can't get to the message returned. I see it if I check BuildMessageFromPayload on the dashboard:



    Additionally:

    To catch errors upstream, I'm also using a postprocessor script.

    Code:
    // This script executes once after a message has been processed
    // Responses returned from here will be stored as "Postprocessor" in the response map
    for each (connectorMessage in message.getConnectorMessages().values().toArray())
    	if (connectorMessage.getStatus() == ERROR)
    		return new Response(ERROR,'','An error occurred processing through one or more connectors.');
    //I'm not certain that this globalChannelMap.get is the correct way of doing this!
    return new Response(SENT,'',globalChannelMap.get('CallingMagnetResponse'));
    However, for some reason, I'm unable to actually get the message I expected. I have the following code on the Response of the Destination that calls my second service:

    Code:
    //$('ReturnValueIsTrue') is a mapper step before this one.
    channelMap.put('CallingMagnetResponse',$('ReturnValueIsTrue'));
    //This logs a blank line.
    logger.info(channelMap.get('CallingMagnetResponse'));
    //This also logs a blank line.
    logger.info(msg['s:Body']['ProcessIncomingADTMessageResponse']['ProcessIncomingADTMessageResult'].toString());
    //This logs the message properly, the same as shown on my screenshot but without line breaks.
    logger.info(msg.toString());

    While not generating errors, trying to access my ProcessIncomingADTMessageResult variable inside that XML fails.

    Exact output of logger.info (the one that works):

    HTML Code:
    INFO  (response:?): <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header/><s:Body><ProcessIncomingADTMessageResponse xmlns="http://speculum.pt/services/"><ProcessIncomingADTMessageResult>true</ProcessIncomingADTMessageResult></ProcessIncomingADTMessageResponse></s:Body></s:Envelope>
    Is there something wrong with the call to channelMap.put that I'm unaware of?

    Thanks in advance.
    Last edited by JoaoAiveca; 12-28-2016, 08:27 AM.

  • #2
    The problem probably lies around the assignment of $('ReturnValueIsTrue'). Verify your previous step and see what value you retrieve from it. If its just a simple mapper step just before that one, you may as well just move it inside this step.

    On the other issue, try logger.info(msg['s:Envelope']['s:Body']['...']

    Comment


    • #3
      Originally posted by ocakici View Post
      The problem probably lies around the assignment of $('ReturnValueIsTrue'). Verify your previous step and see what value you retrieve from it. If its just a simple mapper step just before that one, you may as well just move it inside this step.

      On the other issue, try logger.info(msg['s:Envelope']['s:Body']['...']
      Yes, the previous step is a simple mapper. Adding the ['s:Envelope'] part still yields no reply.


      (My apologies, I was not aware of how Mirth's forum thread validation worked, I didn't know my thread had been approved).

      Keep in mind that I fixed my actual problem by using a different approach that doesn't depend on channelMap.put, thus dodging the problem. I modified my postprocessor script to return the message I intended to actually obtain without having to go through channelMap.get; in case anyone needs the code for it, the solution is as follows:

      Code:
      // This script executes once after a message has been processed
      // Responses returned from here will be stored as "Postprocessor" in the response map
      for each (connectorMessage in message.getConnectorMessages().values().toArray())
      	if (connectorMessage.getStatus() == ERROR)
      	
      		return new Response(ERROR,'','An error occurred processing through one or more connectors.');
      
      
      logger.info("Listing all destinations: ");
      logger.info(message.getDestinationIdMap());
      logger.info("Attempting to access the correct destination:");
      var destinationID=message.getDestinationIdMap().get("CallServiceToProcessADTMessage");
      logger.info(destinationID);
      
      logger.info("Showing Destination message: ");
      var correctMessage = message.getConnectorMessages().get(destinationID);
      logger.info(correctMessage);
      
      
      logger.info("Showing Destination response: ");
      logger.info(correctMessage.getResponseTransformed());
      
      return correctMessage.getResponseTransformedData();
      These steps allowed me to get my channel to work the way I intended; however, I'm still not sure why channelMap.get/put in the Response aren't quite working.

      What I know works:

      - I know my Response for my Destination is invoked. I see logs from there.
      - msg.toString() works perfecly fine. Output:

      Code:
      2016-12-28 17:11:32,247  INFO  (response:?): <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header/><s:Body><ProcessIncomingADTMessageResponse xmlns="http://speculum.pt/services/"><ProcessIncomingADTMessageResult>true</ProcessIncomingADTMessageResult></ProcessIncomingADTMessageResponse></s:Body></s:Envelope>
      - All my other methods of accessing the specific field fail.

      Code:
      channelMap.get('CallingMagnetResponse')
      
      msg['s:Body']['ProcessIncomingADTMessageResponse']['ProcessIncomingADTMessageResult'].toString()
      
      msg['s:Envelope']['s:Body']['ProcessIncomingADTMessageResponse']['ProcessIncomingADTMessageResult'].toString()
      Output (of all 3, obviously with different timestamps):

      Code:
      2016-12-28 17:11:32,246  INFO  (response:?):
      My best guess is that I'm either using forbidden characters (thus preventing me from accessing the XML nodes properly), or I'm flat out using the wrong way of traversing "msg".

      Comment


      • #4
        I created a simple test channel, where I fed the xml you provided. It looks like the namespaces are the problems. When I have the 'strip namespaces' checked, I could not load the message, I received the error 'TypeError: The prefix "s" for element "s:Envelope" is not bound.'

        When I uncheck the 'strip namespaces', I was able to retrieve the value with the following:

        msg.*::['Body'].*::['ProcessIncomingADTMessageResponse'].*::['ProcessIncomingADTMessageResult'].toString();

        Comment


        • #5
          Originally posted by ocakici View Post
          I created a simple test channel, where I fed the xml you provided. It looks like the namespaces are the problems. When I have the 'strip namespaces' checked, I could not load the message, I received the error 'TypeError: The prefix "s" for element "s:Envelope" is not bound.'

          When I uncheck the 'strip namespaces', I was able to retrieve the value with the following:

          msg.*::['Body'].*::['ProcessIncomingADTMessageResponse'].*::['ProcessIncomingADTMessageResult'].toString();
          That's it. I had also unchecked strip namespaces (forgot to mention it), else it would error, as you found out; but that syntax you provided does get to the element properly.

          It's not a syntax I'm familiar with (the double quotes), so I have some reading to do. Thanks a lot!

          Comment

          Working...
          X