Announcement

Collapse
No announcement yet.

return response with HTTP listener and PostProcessor

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

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

  • #2
    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.

    Comment


    • #3
      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, 02:12 PM.

      Comment

      Working...
      X