1
2
3
4 """
5 Flex Messaging implementation.
6
7 This module contains the message classes used with Flex Data Services.
8
9 @see: U{RemoteObject on OSFlash (external)
10 <http://osflash.org/documentation/amf3#remoteobject>}
11
12 @since: 0.1.0
13 """
14
15 import pyamf
16
17 __all__ = [
18 'RemotingMessage',
19 'CommandMessage',
20 'AcknowledgeMessage',
21 'ErrorMessage'
22 ]
23
24 NAMESPACE = 'flex.messaging.messages'
25
27 """
28 Abstract base class for all Flex messages.
29
30 Messages have two customizable sections; headers and data. The headers
31 property provides access to specialized meta information for a specific
32 message instance. The data property contains the instance specific data
33 that needs to be delivered and processed by the decoder.
34
35 @see: U{AbstractMessage on Livedocs (external)
36 <http://livedocs.adobe.com/flex/201/langref/mx/messaging/messages/AbstractMessage.html>}
37
38 @ivar body: Specific data that needs to be delivered to the remote
39 destination.
40 @type body: C{mixed}
41 @ivar clientId: Indicates which client sent the message.
42 @type clientId: C{str}
43 @ivar destination: Message destination.
44 @type destination: C{str}
45 @ivar headers: Message headers. Core header names start with DS.
46 @type headers: C{dict}
47 @ivar messageId: Unique Message ID.
48 @type messageId: C{str}
49 @ivar timeToLive: How long the message should be considered valid and
50 deliverable.
51 @type timeToLive: C{int}
52 @ivar timestamp: Timestamp when the message was generated.
53 @type timestamp: C{int}
54 """
55
56
57
58 DESTINATION_CLIENT_ID_HEADER = "DSDstClientId"
59
60
61 ENDPOINT_HEADER = "DSEndpoint"
62
63
64 REMOTE_CREDENTIALS_HEADER = "DSRemoteCredentials"
65
66
67
68
69 REQUEST_TIMEOUT_HEADER = "DSRequestTimeout"
70
72 self.body = kwargs.get('body', None)
73 self.clientId = kwargs.get('clientId', None)
74 self.destination = kwargs.get('destination', None)
75 self.headers = kwargs.get('headers', {})
76 self.messageId = kwargs.get('messageId', None)
77 self.timeToLive = kwargs.get('timeToLive', 0)
78 self.timestamp = kwargs.get('timestamp', 0)
79
81 m = '<%s ' % self.__class__.__name__
82
83 for k, v in self.__dict__.iteritems():
84 m += ' %s=%r' % (k, v)
85
86 return m + " />"
87
88
89
90 pyamf.register_class(AbstractMessage, '.'.join([NAMESPACE, 'AbstractMessage']),
91 attrs=[
92 'body', 'clientId', 'destination', 'headers', 'messageId',
93 'timeToLive', 'timestamp'
94 ], metadata=['amf3', 'static'])
95
97 """
98 I am the base class for all asynchronous Flex messages.
99
100 @see: U{AsyncMessage on Livedocs (external)
101 <http://livedocs.adobe.com/flex/201/langref/mx/messaging/messages/AsyncMessage.html>}
102
103 @ivar correlationId: Correlation id of the message.
104 @type correlationId: C{str}
105 """
106
107
108
109 SUBTOPIC_HEADER = "DSSubtopic"
110
115
116 pyamf.register_class(AsyncMessage, '.'.join([NAMESPACE, 'AsyncMessage']),
117 attrs=['correlationId'], metadata=['amf3', 'static'])
118
120 """
121 I acknowledge the receipt of a message that was sent previously.
122
123 Every message sent within the messaging system must receive an
124 acknowledgement.
125
126 @see: U{AcknowledgeMessage on Livedocs (external)
127 <http://livedocs.adobe.com/flex/201/langref/mx/messaging/messages/AcknowledgeMessage.html>}
128 """
129
130
131
132 ERROR_HINT_HEADER = "DSErrorHint"
133
134 pyamf.register_class(AcknowledgeMessage, '.'.join([NAMESPACE, 'AcknowledgeMessage']),
135 attrs=[], metadata=['amf3', 'static'])
136
195
196 pyamf.register_class(CommandMessage, '.'.join([NAMESPACE, 'CommandMessage']),
197 attrs=['operation', 'messageRefType'], metadata=['amf3', 'static'])
198
200 """
201 I am the Flex error message to be returned to the client.
202
203 This class is used to report errors within the messaging system.
204
205 @see: U{ErrorMessage on Livedocs (external)
206 <http://livedocs.adobe.com/flex/201/langref/mx/messaging/messages/ErrorMessage.html>}
207 """
208
209
210
211 MESSAGE_DELIVERY_IN_DOUBT = "Client.Error.DeliveryInDoubt"
212
213
214
215
216 RETRYABLE_HINT_HEADER = "DSRetryableErrorHint"
217
219 AcknowledgeMessage.__init__(self, *args, **kwargs)
220
221
222 self.extendedData = kwargs.get('extendedData', {})
223
224 self.faultCode = kwargs.get('faultCode', None)
225
226 self.faultDetail = kwargs.get('faultDetail', None)
227
228 self.faultString = kwargs.get('faultString', None)
229
230
231 self.rootCause = kwargs.get('rootCause', {})
232
233 pyamf.register_class(ErrorMessage, '.'.join([NAMESPACE, 'ErrorMessage']),
234 attrs=['extendedData', 'faultCode', 'faultDetail', 'faultString', 'rootCause'],
235 metadata=['amf3', 'static'])
236
238 """
239 I am used to send RPC requests to a remote endpoint.
240
241 @see: U{RemotingMessage on Livedocs (external)
242 <http://livedocs.adobe.com/flex/201/langref/mx/messaging/messages/RemotingMessage.html>}
243 """
244
246 AbstractMessage.__init__(self, *args, **kwargs)
247
248 self.operation = kwargs.get('operation', None)
249
250
251 self.source = kwargs.get('source', None)
252
253 pyamf.register_class(RemotingMessage, '.'.join([NAMESPACE, 'RemotingMessage']),
254 attrs=['operation', 'source'], metadata=['amf3', 'static'])
255