Announcement

Collapse
No announcement yet.

Custom response message creation after source filter step itself.

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

  • Custom response message creation after source filter step itself.

    Hello All,

    I have a channel, whose source is 'TCP Listener' and destination is 'Database Writer'.

    I have created a filter to check if the receiving message is of type 'ORM^O01'. If it is other than 'ORM^O01' event type, i reject the message. In the return acknowledgement, i want to inform the sender with a reason why the message has been rejected. Kindly inform the steps briefly to do it. I saw few posts, but nothing i found an explaination of generating the custom response during source filtering step itself.

    Thank you so much !!.
    Last edited by taanil; 09-18-2019, 06:54 AM.

  • #2
    https://www.mirthcorp.com/community/...ght=custom+ack

    Comment


    • #3
      That thread will get you most of the way there. The unanswered question in the last post I think is the same as yours.

      You can store your filter reason to a channelMap variable in the source filter, then access it in the post-processor to populate the ACK.

      The following line will likely set httpResponse to null if the message was filtered at the source since 'Destination1' wouldn't have run at all. 'Destination1' should match the actual name of your destination for which you want to check the status. Alternatively, you can just assume that if you didn't set a filter reason you want to return an AA response.
      Code:
      var httpResponse = responseMap.get('Destination1');

      Comment


      • #4
        Thank you cory_cole and agermano.
        I want to do another improvement, which is, if the message is not filtered, i want to return the default acknowledgement which was generated by Mirth.
        Like this, in postprocessor,

        if (message.getConnectorMessages().get(0).getStatus() == 'FILTERED') {
        return ACKGenerator.generateAckResponse(message.getConnec torMessages().get(0).getRawData(),'AR', 'Message is Filtered');
        }
        else
        {
        --> Here i want to return the default acknowledgement. How to get the default acknowledgement ?
        }
        Last edited by taanil; 09-20-2019, 04:25 AM.

        Comment


        • #5
          I don't think that you should have to do anything. It should be the default if it doesn't go into the if loop.

          Comment


          • #6
            The default is an AA code with an empty message. It won't generate if you don't have auto-generate selected, but you create it the same way as your custom filtered ACK.

            From your previous question, I assume you will be potentially returning several different filter reasons, but if it's always the same reason, you don't need to do any of this custom stuff. You can just edit the Rejected ACK Message in your source inbound data type properties and the auto-generate will use your custom message instead of the default.

            Comment


            • #7
              For the below 'Postprocessor' code, if the message is filtered, control enters the 'if' condition, then the client receives an acknowledgement.
              Code:
              if (message.getConnectorMessages().get(0).getStatus() == 'FILTERED') {
              	return ACKGenerator.generateAckResponse(message.getConnectorMessages().get(0).getRawData(), 'AR', channelMap.get('ErrorStatus'));	
              }
              If the message is not filtered, the control doesnt enter the 'if' condition. In this case, the client waits for the acknowledgement, and ultimately times out. Because, there was no code to generate and return acknowledgement for success scenarios.

              I think, as agermano confirmed, once the Source --> Source Settings --> Response is changed to 'Postprocessor', it becomes entirely the 'Postprocessors' responsibility to generate and return the acknowledgement for both filtered and success scenarios. Then i changed 'Preprocessor' script to below, it returned the acknowledgement to the client.

              Code:
              if (message.getConnectorMessages().get(0).getStatus() == 'FILTERED') {
              	return ACKGenerator.generateAckResponse(message.getConnectorMessages().get(0).getRawData(), 'AR', channelMap.get('ErrorStatus'));	
              }
              else {
              	return ACKGenerator.generateAckResponse(message.getConnectorMessages().get(0).getRawData(), 'AA', 'SUCCESS');
              }
              My question is, in the else condition, instead of me creating the success acknowledgement by calling 'generateAckResponse', is there a object which i can get which is already generated for success scenario by Mirth, then this helps me to use the default acknowledgement code and message ? then, this leaves me to worry only about 'AR'.

              "From your previous question, I assume you will be potentially returning several different filter reasons, but if it's always the same reason, you don't need to do any of this custom stuff. You can just edit the Rejected ACK Message in your source inbound data type properties and the auto-generate will use your custom message instead of the default."
              --> We have different filters and would like to send the actual reason why we rejected the message. For example, if the order is not new 'NW', then we will reject with the message 'Only new orders are accepted'. Another one, if the event is not 'ORM^O01' we will reject, then the message is 'Only 'ORM^O01' events are supported' and so on...
              Last edited by taanil; 09-23-2019, 01:01 AM.

              Comment


              • #8
                Originally posted by taanil View Post
                I think, as agermano confirmed, once the Source --> Source Settings --> Response is changed to 'Postprocessor', it becomes entirely the 'Postprocessors' responsibility to generate and return the acknowledgement for both filtered and success scenarios.
                This is correct.

                Originally posted by taanil View Post
                My question is, in the else condition, instead of me creating the success acknowledgement by calling 'generateAckResponse', is there a object which i can get which is already generated for success scenario by Mirth, then this helps me to use the default acknowledgement code and message?
                Mirth will not automatically generate any response for you, because you are no longer using one of the "auto-generate" options. The ACKGenerator is there to make the task of creating an ACK response yourself easier.

                This basically does the same thing, but maybe it's closer to what you want?

                Code:
                var sourceRawContent = message.getConnectorMessages().get(0).getRawData();
                var ackCode = 'AA';
                var ackMessage = 'SUCCESS';
                
                if (message.getConnectorMessages().get(0).getStatus() == 'FILTERED') {
                	ackCode = 'AR';
                	ackMessage = channelMap.get('ErrorStatus'));	
                }
                
                return ACKGenerator.generateAckResponse(sourceRawContent, ackCode, ackMessage);

                Comment


                • #9
                  Thank you for this.
                  Another question, how about AE error handling when we do not opt for "auto-generate" option ?
                  I think errors are very broad and can be anything. How can we know in PostProcessor if there was any error so that we can create 'AE' ack code return messages ?
                  Last edited by taanil; 09-27-2019, 03:00 AM.

                  Comment


                  • #10
                    message in the post-processor is an instance of ImmutableMessage from the User API. When you call getConnectorMessages, you get a Map holding an ImmutableConnectorMessage for the source and each destination that ran. The source connector is always 0, and the number for each destination will match the Id column on the destinations tab of your channel. These are not always sequential if destinations were reordered or deleted.

                    Code:
                    message.getConnectorMessages().get(0).getStatus() == 'FILTERED'
                    When you're calling the above expression from the previous post you're checking the status of the source connector. You might need to adjust the logic, but something like this should work.

                    Code:
                    // Set up default values for success
                    var sourceRawContent = message.getConnectorMessages().get(0).getRawData();
                    var ackCode = 'AA';
                    var ackMessage = 'SUCCESS';
                    
                    // Send AR with reason if source connector was filtered
                    if (message.getConnectorMessages().get(0).getStatus() == Status.FILTERED) {
                    	ackCode = 'AR';
                    	ackMessage = channelMap.get('ErrorStatus'));	
                    }
                    
                    // Send AE if the source or any destinations had an error
                    for (var connectorMessage in Iterator(message.getConnectorMessages().values())) {
                        if (connectorMessage.getStatus() == Status.ERROR) {
                            ackCode = 'AE';
                            ackMessage = 'ERROR';
                            break; // we don't need to keep looking after we find one
                        }
                    }
                    
                    return ACKGenerator.generateAckResponse(sourceRawContent, ackCode, ackMessage);

                    Comment


                    • #11
                      Thank you. I have all the necessary design information for returning my own custom error messages. I will incorporate this into my channel and will let you know.

                      Comment

                      Working...
                      X