def _create_jms_streammessage(self, test_value_type, test_value): """Create a JMS stream message""" if test_value_type == 'boolean': body_list = [test_value == 'True'] elif test_value_type == 'byte': body_list = [byte(int(test_value, 16))] elif test_value_type == 'bytes': body_list = [str(test_value)] elif test_value_type == 'char': body_list = [char(test_value)] elif test_value_type == 'double': body_list = [unpack('!d', test_value[2:].decode('hex'))[0]] elif test_value_type == 'float': body_list = [ float32(unpack('!f', test_value[2:].decode('hex'))[0]) ] elif test_value_type == 'int': body_list = [int32(int(test_value, 16))] elif test_value_type == 'long': body_list = [long(test_value, 16)] elif test_value_type == 'short': body_list = [short(int(test_value, 16))] elif test_value_type == 'string': body_list = [test_value] else: raise InteropTestError( 'JmsMessagesTestSender._create_jms_streammessage: Unknown or unsupported subtype "%s"' % test_value_type) return Message(id=(self.sent + 1), body=body_list, inferred=True, annotations=create_annotation('JMS_STREAMMESSAGE_TYPE'))
def _create_jms_mapmessage(self, test_value_type, test_value, name): """Create a JMS map message""" if test_value_type == 'boolean': value = test_value == 'True' elif test_value_type == 'byte': value = byte(int(test_value, 16)) elif test_value_type == 'bytes': value = str(test_value) # remove unicode elif test_value_type == 'char': value = char(test_value) elif test_value_type == 'double': value = unpack('!d', test_value[2:].decode('hex'))[0] elif test_value_type == 'float': value = float32(unpack('!f', test_value[2:].decode('hex'))[0]) elif test_value_type == 'int': value = int32(int(test_value, 16)) elif test_value_type == 'long': value = long(test_value, 16) elif test_value_type == 'short': value = short(int(test_value, 16)) elif test_value_type == 'string': value = test_value else: raise InteropTestError( 'JmsMessagesTestSender._create_jms_mapmessage: Unknown or unsupported subtype "%s"' % test_value_type) return Message(id=(self.sent + 1), body={name: value}, inferred=False, annotations=create_annotation('JMS_MAPMESSAGE_TYPE'))
def _create_jms_bytesmessage(self, test_value_type, test_value): """Create a JMS bytes message""" # NOTE: test_value contains all unicode strings u'...' as returned by json body_bytes = None if test_value_type == 'boolean': body_bytes = b'\x01' if test_value == 'True' else b'\x00' elif test_value_type == 'byte': body_bytes = pack('b', int(test_value, 16)) elif test_value_type == 'bytes': body_bytes = str(test_value) # remove unicode elif test_value_type == 'char': # JMS expects two-byte chars, ASCII chars can be prefixed with '\x00' body_bytes = '\x00' + str(test_value) # remove unicode elif test_value_type == 'double' or test_value_type == 'float': body_bytes = test_value[2:].decode('hex') elif test_value_type == 'int': body_bytes = pack('!i', int(test_value, 16)) elif test_value_type == 'long': body_bytes = pack('!q', long(test_value, 16)) elif test_value_type == 'short': body_bytes = pack('!h', short(test_value, 16)) elif test_value_type == 'string': # NOTE: First two bytes must be string length test_value_str = str(test_value) # remove unicode body_bytes = pack('!H', len(test_value_str)) + test_value_str else: raise InteropTestError( 'JmsMessagesTestSender._create_jms_bytesmessage: Unknown or unsupported subtype "%s"' % test_value_type) return Message(id=(self.sent + 1), body=body_bytes, inferred=True, content_type='application/octet-stream', annotations=create_annotation('JMS_BYTESMESSAGE_TYPE'))
def _create_jms_objectmessage(self, test_value): """Create a JMS object message""" java_binary = self._s_get_java_obj_binary(test_value) return Message(id=(self.sent + 1), body=java_binary, inferred=True, content_type='application/x-java-serialized-object', annotations=create_annotation('JMS_OBJECTMESSAGE_TYPE'))
def _create_jms_textmessage(self, test_value_text, hdr_kwargs, hdr_annotations): """Create a JMS text message""" return Message(id=(self.sent + 1), body=unicode(test_value_text), annotations=TestTypeMap.merge_dicts( create_annotation('JMS_TEXTMESSAGE_TYPE'), hdr_annotations), **hdr_kwargs)
def _create_jms_objectmessage(self, test_value, hdr_kwargs, hdr_annotations): """Create a JMS object message""" java_binary = self._s_get_java_obj_binary(test_value) return Message(id=(self.sent + 1), body=java_binary, inferred=True, content_type='application/x-java-serialized-object', annotations=TestTypeMap.merge_dicts( create_annotation('JMS_MAPMESSAGE_TYPE'), hdr_annotations), **hdr_kwargs)
def _create_jms_message(self, test_value_type, test_value): """Create a JMS message type (without message body)""" if test_value_type != 'none': raise InteropTestError( 'JmsMessagesTestSender._create_jms_message: Unknown or unsupported subtype "%s"' % test_value_type) if test_value is not None: raise InteropTestError( 'JmsMessagesTestSender._create_jms_message: Invalid value "%s" for subtype "%s"' % (test_value, test_value_type)) return Message(id=(self.sent + 1), content_type='application/octet-stream', annotations=create_annotation('JMS_MESSAGE_TYPE'))
def _create_jms_message(self, test_value_type, test_value, hdr_kwargs, hdr_annotations): """Create a JMS message type (without message body)""" if test_value_type != 'none': raise InteropTestError( 'JmsSenderShim._create_jms_message: Unknown or unsupported subtype "%s"' % test_value_type) if test_value is not None: raise InteropTestError( 'JmsSenderShim._create_jms_message: Invalid value "%s" for subtype "%s"' % (test_value, test_value_type)) return Message(id=(self.sent + 1), content_type='application/octet-stream', annotations=TestTypeMap.merge_dicts( create_annotation('JMS_MESSAGE_TYPE'), hdr_annotations), **hdr_kwargs)
def _create_jms_textmessage(self, test_value_text): """Create a JMS text message""" return Message(id=(self.sent + 1), body=unicode(test_value_text), annotations=create_annotation('JMS_TEXTMESSAGE_TYPE'))