简体   繁体   中英

Get Token from destination response and pass to new Channel in Mirth

I've created a channel in Mirth which first calls authentication service and returns response. Source I've configured to HTTP Listener and in destination I've used HTTP Sender which calls a rest service for login and returns token as below.

{"token":"5912aa99-af21-5614-c232-d22be9e5c102","app":"TEST API Suite","expires":845,"userID":"ZCT06D123Cfk20oROB9x-bEXeY12oQGfack6dMMc-0o="}

Question: From the response that I'm receiving from rest service , how do I extract the token part and then pass that token to another channel and use it for calling another service.

Is there a way that I can set the token in a variable or global map in Destination1 and use that in Destination2 configuration?

Please Help. I'm a Newbie in Mirth. Thanks.

The following helped me and solved my issue. Add a post processor script as this in channel1 :

var dest1 = responseMap.get("Destination 1");
var response123=dest1.getMessage();
var obj = JSON.parse(response123);
logger.info('token==='+obj.token);
router.routeMessage('newChannelName', obj.token);
return;

And then in newChannelName Channel preprocessor script, I was able to get this token as message.

logger.info('token: '+message);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM