Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

#!/usr/bin/env python 

 

""" 

@file ion/core/intercept/ionmessage.py 

@author Michael Meisinger 

@brief base classes for the common ION message format 

""" 

 

from twisted.internet import defer 

 

import ion.util.ionlog 

log = ion.util.ionlog.getLogger(__name__) 

 

from ion.core import ionconst as ic 

from ion.core import ioninit 

from ion.core.intercept.interceptor import EnvelopeInterceptor 

import ion.util.procutils as pu 

 

 

class IONMessageInterceptor(EnvelopeInterceptor): 

    """ 

    Interceptor that assembles the headers in the ION message format. 

    """ 

    def before(self, invocation): 

        return invocation 

 

    def after(self, invocation): 

        message = invocation.message 

        headers = message['headers'] 

        msg = {} 

        # The following headers are FIPA ACL Message Format based 

        # Exchange name of sender (DO NOT SEND replies here) 

        msg['sender'] = str(headers.get('sender', message.get('sender'))) 

        # Exchange name of message recipient 

        msg['receiver'] = str(message.get('recipient')) 

        # Exchange name for message replies 

        msg['reply-to'] = str(headers.get('reply-to', message.get('sender'))) 

        # Wire form encoding, such as 'json', 'fudge', 'XDR', 'XML', 'custom' 

        msg['encoding'] = headers.get('encoding','json') 

        # See ion.data.dataobject Serializers for choices 

        #msg['accept-encoding'] = headers.get('accept-encoding','') 

        # Language of the format specification 

        msg['language'] = headers.get('language','ion1') 

        # Identifier of a registered format specification (i.e. message schema) 

        msg['format'] = headers.get('format','raw') 

        # Ontology associated with the content of the message 

        msg['ontology'] = headers.get('ontology','') 

        # OOI User id 

        msg['user-id'] = str(headers.get('user-id', 'ANONYMOUS')) 

        # Lifespan of user authority 

        msg['expiry'] = str(headers.get('expiry', '0')) 

        # Conversation instance id 

        msg['conv-id'] = headers.get('conv-id','') 

        # Conversation message sequence number 

        msg['conv-seq'] = headers.get('conv-seq',1) 

        # Conversation type id 

        msg[ic.IONMSG_HDR_PROTOCOL] = headers.get('protocol','') 

        # Status code 

        msg['status'] = headers.get('status','OK') 

        # Local timestamp in ms 

        msg['ts'] = str(pu.currenttime_ms()) 

        #msg['reply-with'] = '' 

        #msg['in-reply-to'] = '' 

        #msg['reply-by'] = '' 

        msg.update(headers) 

        # Performative of the message 

        msg[ic.IONMSG_HDR_PERFORMATIVE] = headers.get('performative','') 

        # Operation = Action request of the message 

        msg[ic.IONMSG_HDR_ACTION] = message.get('operation') 

        # The actual content 

        msg['content'] = message.get('content') 

 

        invocation.message = msg 

        return invocation