web stats
return response with HTTP listener and PostProcessor - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-25-2019, 07:01 AM
erikbeltran erikbeltran is offline
What's HL7?
 
Join Date: Feb 2019
Posts: 1
erikbeltran is on a distinguished road
Default return response with HTTP listener and PostProcessor

Hi All.

I having a few problem trying to proxy a HTTP API REST using mirth, basically I cant return the response from the service in mirth

I have this Source Transformer (http listener) , who routes the request and works:
Code:
if (sourceMap.get('method') == 'GET' ){
	destinationSet.removeAllExcept([1]);
} else if (sourceMap.get('method') == 'POST' && sourceMap.get('contextPath') == '/oauth/token'){ 
	destinationSet.removeAllExcept([5]);
} else {
	destinationSet.removeAllExcept([2]);
}
basically I have multiples destination (GET/ POST), but when I do the request to mirth, I receive ever a empty response

In source settings I set the response as PostProcessor, because I need only the response of one destination source, but when I pick another destination , like the GET destination , I can see the response.

so basically my problem is, how I can set correctly the postProcessor script to return the correct destination response, because actually I receive an empty response.
Reply With Quote
  #2  
Old 03-04-2019, 02:03 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,031
agermano is on a distinguished road
Default

Try this in the post-processor

Code:
var cms = message.getConnectorMessages();
for (var key in Iterator(cms.keySet())) {
    // Ignore source connector (0)
    if (key != 0) {
        // Assume first one found is the only destination. Destinations
        // removed from the destinationSet will not appear in this Map.
        return cms.get(key).getResponseData();
    }
}
message in the post-processor is an instance of the ImmutableMessage class from the User API.
Reply With Quote
  #3  
Old 03-04-2019, 03:05 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,031
agermano is on a distinguished road
Default

Here's another way to do the same thing with Java 8 Streams.

Code:
var cms = message.getConnectorMessages();
return cms.keySet().stream()
    .filter({test: function(i) {return i != 0}})
    .findFirst()
    .map({apply: function(i) {return cms.get(i).getResponseData()}}).get();
The above was tested in mirth 3.5. I have not tested the next example, but I presume it should work in mirth 3.7 with ES6 mode enabled.

Code:
var cms = message.getConnectorMessages();
return cms.keySet().stream()
    .filter(i => i != 0)
    .findFirst()
    .map(i => cms.get(i).getResponseData()).get();

This will work in older mirth versions, too, using javascript Array.prototype methods.
Code:
var cms = message.getConnectorMessages();
return cms.keySet().toArray()
    .filter(function(i) {return i != 0})
    .map(function(i) {return cms.get(i).getResponseData()})[0];

Last edited by agermano; 03-04-2019 at 03:12 PM.
Reply With Quote
Reply

Tags
http, postprocessor, proxy

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 05:39 AM.


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