web stats
Problem with channelMap.put - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-28-2016, 03:21 AM
JoaoAiveca JoaoAiveca is offline
Mirth Newb
 
Join Date: Nov 2016
Posts: 8
JoaoAiveca is on a distinguished road
Default 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 at 08:27 AM.
Reply With Quote
  #2  
Old 12-28-2016, 07:56 AM
ocakici ocakici is offline
Mirth Newb
 
Join Date: Sep 2010
Posts: 17
ocakici is on a distinguished road
Default

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']['...']
Reply With Quote
  #3  
Old 12-28-2016, 08:18 AM
JoaoAiveca JoaoAiveca is offline
Mirth Newb
 
Join Date: Nov 2016
Posts: 8
JoaoAiveca is on a distinguished road
Default

Quote:
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".
Reply With Quote
  #4  
Old 12-28-2016, 08:52 AM
ocakici ocakici is offline
Mirth Newb
 
Join Date: Sep 2010
Posts: 17
ocakici is on a distinguished road
Default

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();
Reply With Quote
  #5  
Old 12-28-2016, 09:01 AM
JoaoAiveca JoaoAiveca is offline
Mirth Newb
 
Join Date: Nov 2016
Posts: 8
JoaoAiveca is on a distinguished road
Default

Quote:
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!
Reply With Quote
Reply

Tags
channel response, channelmap, postprocessor

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 01:43 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation