No announcement yet.

Simple HTTP Listener response question

  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple HTTP Listener response question

    I have a simple channel for testing. It has an HTTP Listener source with HL7 v2 data type as input, and a Transformer step that write some Javascript by building a message:

    if (msg.elements('ARQ').length() > 0) {
    var o = {};
    var j = 0;
    process_ARQ(o, j);
    content.ARQ = o;

    // lots more code...

    msg = JSON.stringify(object);

    If I put a File Writer destination, and use Curl to send a message like this:

    [email protected]:~$ curl -i -X POST -H "Content-Type: text/plain" --data-binary @adt04-2.hl7 http://localhost:5000
    HTTP/1.1 200 OK
    Content-Type: text/plain;charset=UTF-8
    Content-Length: 0
    Server: Jetty(7.6.7.v20120910)

    then I can look in Mirth and see that the HL7 file was turned into JSON and written to the file. Nice.

    But, what I really want is to simply have the JSON message be returned to the caller. I don't want to send the results to a separate destination.

    This isn't anything fancy around integration - just trying to create a service that turns HL7 into JSON as a web service (not SOAP - just something RESTful). Seems easy since the 'msg' clearly contains what I want it to have, but not sure how to return that to the caller.

    Any simple examples of setting this up in Mirth?

  • #2
    That's easy to do. Go to the Source tab; whatever you select in the "Response" drop-down menu will be returned to the caller. If you were using a destination that got a response payload (like a TCP Sender or an HTTP Sender), then you could just select that destination and be done. However in this channel since you want to transform and return JSON without calling any destination, you can put a custom variable in the response map and choose that.

    If you have a destination doing the transformation, you could also switch the destination type to JavaScript Writer and do this:

    return connectorMessage.getEncodedData();
    Then you can choose that destination in the Response drop-down.
    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

    Nicholas Rupley
    Work: 949-237-6069
    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

    - How do I foo?
    - You just bar.


    • #3
      it works, thanks (returns the original JSON that was received)

      but how to send a different one? I have this one but it doesn't work:

      var json; = { "foo": "1", "bar": "a string" };
      var content = JSON.stringify(json);
      return content;