def _create_jms_streammessage(self, test_value_type, test_value, hdr_kwargs, hdr_annotations): """Create a JMS stream message""" if test_value_type == 'boolean': body_list = [test_value == 'True'] elif test_value_type == 'byte': body_list = [proton.byte(int(test_value, 16))] elif test_value_type == 'bytes': body_list = [base64.b64decode(test_value)] elif test_value_type == 'char': body_list = [proton.char(base64.b64decode(test_value).decode('utf-8'))] elif test_value_type == 'double': body_list = [struct.unpack('!d', test_value[2:].decode('hex'))[0]] elif test_value_type == 'float': body_list = [proton.float32(struct.unpack('!f', test_value[2:].decode('hex'))[0])] elif test_value_type == 'int': body_list = [proton.int32(int(test_value, 16))] elif test_value_type == 'long': body_list = [_compat.str2long(test_value, 16)] elif test_value_type == 'short': body_list = [proton.short(int(test_value, 16))] elif test_value_type == 'string': body_list = [test_value] else: raise InteropTestError('JmsSenderShim._create_jms_streammessage: Unknown or unsupported subtype "%s"' % test_value_type) return proton.Message(id=(self.sent+1), body=body_list, inferred=True, annotations=JmsHdrsPropsTestSender.merge_dicts(create_annotation('JMS_STREAMMESSAGE_TYPE'), hdr_annotations), **hdr_kwargs)
def _create_jms_textmessage(self, test_value_text, hdr_kwargs, hdr_annotations): """Create a JMS text message""" return proton.Message(id=(self.sent+1), body=_compat.unicode(test_value_text), annotations=JmsHdrsPropsTestSender.merge_dicts(create_annotation('JMS_TEXTMESSAGE_TYPE'), hdr_annotations), **hdr_kwargs)
def _create_jms_bytesmessage(self, test_value_type, test_value, hdr_kwargs, hdr_annotations): """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 = struct.pack('b', int(test_value, 16)) elif test_value_type == 'bytes': body_bytes = base64.b64decode(test_value) elif test_value_type == 'char': # JMS expects two-byte chars, ASCII chars can be prefixed with '\x00' body_bytes = b'\x00' + base64.b64decode(test_value) elif test_value_type == 'double' or test_value_type == 'float': body_bytes = test_value[2:].decode('hex') elif test_value_type == 'int': body_bytes = struct.pack('!i', int(test_value, 16)) elif test_value_type == 'long': body_bytes = struct.pack('!q', _compat.str2long(test_value, 16)) elif test_value_type == 'short': body_bytes = struct.pack('!h', proton.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 = struct.pack('!H', len(test_value_str)) + test_value_str else: raise InteropTestError('JmsSenderShim._create_jms_bytesmessage: Unknown or unsupported subtype "%s"' % test_value_type) return proton.Message(id=(self.sent+1), body=body_bytes, inferred=True, content_type='application/octet-stream', annotations=JmsHdrsPropsTestSender.merge_dicts(create_annotation('JMS_BYTESMESSAGE_TYPE'), hdr_annotations), **hdr_kwargs)
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 = proton.byte(int(test_value, 16)) elif test_value_type == 'bytes': value = test_value.encode('utf-8') elif test_value_type == 'char': value = proton.char(test_value) elif test_value_type == 'double': value = struct.unpack('!d', _compat.decode_hex(test_value[2:]))[0] elif test_value_type == 'float': value = proton.float32( struct.unpack('!f', _compat.decode_hex(test_value[2:]))[0]) elif test_value_type == 'int': value = proton.int32(int(test_value, 16)) elif test_value_type == 'long': value = _compat.str2long(test_value, 16) elif test_value_type == 'short': value = proton.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 proton.Message( id=(self.sent + 1), body={name: value}, inferred=False, annotations=create_annotation('JMS_MAPMESSAGE_TYPE'))
def _create_jms_mapmessage(self, test_value_type, test_value, name, hdr_kwargs, hdr_annotations): """Create a JMS map message""" if test_value_type == 'boolean': value = test_value == 'True' elif test_value_type == 'byte': value = proton.byte(int(test_value, 16)) elif test_value_type == 'bytes': value = base64.b64decode(test_value) elif test_value_type == 'char': value = proton.char(base64.b64decode(test_value).decode('utf-8')) elif test_value_type == 'double': value = struct.unpack('!d', test_value[2:].decode('hex'))[0] elif test_value_type == 'float': value = proton.float32( struct.unpack('!f', test_value[2:].decode('hex'))[0]) elif test_value_type == 'int': value = proton.int32(int(test_value, 16)) elif test_value_type == 'long': value = int(test_value, 16) elif test_value_type == 'short': value = proton.short(int(test_value, 16)) elif test_value_type == 'string': value = test_value else: raise InteropTestError( 'JmsSenderShim._create_jms_mapmessage: Unknown or unsupported subtype "%s"' % test_value_type) return proton.Message(id=(self.sent + 1), body={name: value}, inferred=False, annotations=JmsHdrsPropsTestSender.merge_dicts( create_annotation('JMS_MAPMESSAGE_TYPE'), hdr_annotations), **hdr_kwargs)
def _create_jms_objectmessage(self, test_value): """Create a JMS object message""" java_binary = self._s_get_java_obj_binary(test_value) return proton.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_objectmessage(self, test_value, hdr_kwargs, hdr_annotations): """Create a JMS object message""" java_binary = self._s_get_java_obj_binary(test_value) return proton.Message(id=(self.sent+1), body=java_binary, inferred=True, content_type='application/x-java-serialized-object', annotations=JmsHdrsPropsTestSender.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 proton.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 proton.Message(id=(self.sent+1), content_type='application/octet-stream', annotations=JmsHdrsPropsTestSender.merge_dicts(create_annotation('JMS_MESSAGE_TYPE'), hdr_annotations), **hdr_kwargs)
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 = [proton.byte(int(test_value, 16))] elif test_value_type == 'bytes': body_list = [test_value.encode('utf-8')] elif test_value_type == 'char': body_list = [proton.char(test_value)] elif test_value_type == 'double': body_list = [ struct.unpack('!d', _compat.decode_hex(test_value[2:]))[0] ] elif test_value_type == 'float': body_list = [ proton.float32( struct.unpack('!f', _compat.decode_hex(test_value[2:]))[0]) ] elif test_value_type == 'int': body_list = [proton.int32(int(test_value, 16))] elif test_value_type == 'long': body_list = [_compat.str2long(test_value, 16)] elif test_value_type == 'short': body_list = [proton.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 proton.Message( id=(self.sent + 1), body=body_list, inferred=True, annotations=create_annotation('JMS_STREAMMESSAGE_TYPE'))
def _create_jms_textmessage(self, test_value_text): """Create a JMS text message""" return proton.Message( id=(self.sent + 1), body=_compat.unicode(test_value_text), annotations=create_annotation('JMS_TEXTMESSAGE_TYPE'))