def on_response(self, msg):
        """
        setup response if correlation id is the good one
        """
        LOGGER.debug("natsd.Requester.on_response: " + str(sys.getsizeof(msg)) + " bytes received")
        working_response = json.loads(msg.data.decode())
        working_properties = DriverTools.json2properties(working_response['properties'])
        working_body = b''+bytes(working_response['body'], 'utf8') if 'body' in working_response else None
        if DriverTools.MSG_CORRELATION_ID in working_properties:
            if self.corr_id == working_properties[DriverTools.MSG_CORRELATION_ID]:
                if DriverTools.MSG_SPLIT_COUNT in working_properties and \
                        int(working_properties[DriverTools.MSG_SPLIT_COUNT]) > 1:
                    working_body_decoded = base64.b64decode(working_body) if working_body is not None else None
                    if self.split_responses is None:
                        self.split_responses = []
                        self.split_responses_mid = working_properties[DriverTools.MSG_SPLIT_MID]
                    if working_properties[DriverTools.MSG_SPLIT_MID] == self.split_responses_mid:
                        response = {
                            'properties': working_properties,
                            'body': working_body_decoded
                        }
                        self.split_responses.insert(int(working_properties[DriverTools.MSG_SPLIT_OID]), response)

                        if self.split_responses.__len__() == int(working_properties[DriverTools.MSG_SPLIT_COUNT]):
                            properties = {}
                            body = b''
                            for num in range(0, self.split_responses.__len__()):
                                properties.update(self.split_responses[num]['properties'])
                                body += self.split_responses[num]['body']
                            self.response = {
                                'properties': properties,
                                'body': body
                            }
                            self.split_responses = None
                            self.split_responses_mid = None

                    else:
                        LOGGER.warn("natsd.Requester.on_response - discarded response : (" +
                                    str(working_properties[DriverTools.MSG_CORRELATION_ID]) + "," +
                                    str(working_properties[DriverTools.MSG_SPLIT_MID]) + ")")
                        LOGGER.debug("natsd.Requester.on_response - discarded response : " + str({
                            'properties': working_properties,
                            'body': working_body_decoded
                        }))
                else:
                    working_body_decoded = base64.b64decode(working_body) if working_body is not None else \
                        bytes(json.dumps({}), 'utf8')
                    self.response = {
                        'properties': working_properties,
                        'body': working_body_decoded
                    }
            else:
                working_body_decoded = base64.b64decode(working_body) if working_body is not None else None
                LOGGER.warn("natsd.Requester.on_response - discarded response : " +
                            str(working_properties[DriverTools.MSG_CORRELATION_ID]))
                LOGGER.debug("natsd.Requester.on_response - discarded response : " + str({
                    'properties': working_properties,
                    'body': working_body_decoded
                }))
        else:
            working_body_decoded = base64.b64decode(working_body) if working_body is not None else None
            LOGGER.warn("natsd.Requester.on_response - discarded response (no correlation ID)")
            LOGGER.debug("natsd.Requester.on_response - discarded response : " + str({
                'properties': working_properties,
                'body': working_body_decoded
            }))
def on_response ( self , msg ) : LOGGER . debug ( "natsd.Requester.on_response: " + str ( sys . getsizeof ( msg ) ) + " bytes received" ) working_response = json . loads ( msg . data . decode ( ) ) working_properties = DriverTools . json2properties ( working_response [ 'properties' ] ) working_body = b'' + bytes ( working_response [ 'body' ] , 'utf8' ) if 'body' in working_response else None if DriverTools . MSG_CORRELATION_ID in working_properties : if self . corr_id == working_properties [ DriverTools . MSG_CORRELATION_ID ] : if DriverTools . MSG_SPLIT_COUNT in working_properties and int ( working_properties [ DriverTools . MSG_SPLIT_COUNT ] ) > 1 : working_body_decoded = base64 . b64decode ( working_body ) if working_body is not None else None if self . split_responses is None : self . split_responses = [ ] self . split_responses_mid = working_properties [ DriverTools . MSG_SPLIT_MID ] if working_properties [ DriverTools . MSG_SPLIT_MID ] == self . split_responses_mid : response = { 'properties' : working_properties , 'body' : working_body_decoded } self . split_responses . insert ( int ( working_properties [ DriverTools . MSG_SPLIT_OID ] ) , response ) if self . split_responses . __len__ ( ) == int ( working_properties [ DriverTools . MSG_SPLIT_COUNT ] ) : properties = { } body = b'' for num in range ( 0 , self . split_responses . __len__ ( ) ) : properties . update ( self . split_responses [ num ] [ 'properties' ] ) body += self . split_responses [ num ] [ 'body' ] self . response = { 'properties' : properties , 'body' : body } self . split_responses = None self . split_responses_mid = None else : LOGGER . warn ( "natsd.Requester.on_response - discarded response : (" + str ( working_properties [ DriverTools . MSG_CORRELATION_ID ] ) + "," + str ( working_properties [ DriverTools . MSG_SPLIT_MID ] ) + ")" ) LOGGER . debug ( "natsd.Requester.on_response - discarded response : " + str ( { 'properties' : working_properties , 'body' : working_body_decoded } ) ) else : working_body_decoded = base64 . b64decode ( working_body ) if working_body is not None else bytes ( json . dumps ( { } ) , 'utf8' ) self . response = { 'properties' : working_properties , 'body' : working_body_decoded } else : working_body_decoded = base64 . b64decode ( working_body ) if working_body is not None else None LOGGER . warn ( "natsd.Requester.on_response - discarded response : " + str ( working_properties [ DriverTools . MSG_CORRELATION_ID ] ) ) LOGGER . debug ( "natsd.Requester.on_response - discarded response : " + str ( { 'properties' : working_properties , 'body' : working_body_decoded } ) ) else : working_body_decoded = base64 . b64decode ( working_body ) if working_body is not None else None LOGGER . warn ( "natsd.Requester.on_response - discarded response (no correlation ID)" ) LOGGER . debug ( "natsd.Requester.on_response - discarded response : " + str ( { 'properties' : working_properties , 'body' : working_body_decoded } ) )
setup response if correlation id is the good one