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 @author: U{Arnar Birgisson<mailto:arnarbi@gmail.com>}
13 @author: U{Thijs Triemstra<mailto:info@collab.nl>}
14 @author: U{Nick Joyce<mailto:nick@boxdesign.co.uk>}
15
16 @since: 0.1.0
17 """
18
19 import pyamf
20
21 __all__ = [
22 'RemotingMessage',
23 'CommandMessage',
24 'AcknowledgeMessage',
25 'ErrorMessage'
26 ]
27
29 """
30 Abstract base class for all Flex messages.
31
32 Messages have two customizable sections; headers and data. The headers
33 property provides access to specialized meta information for a specific
34 message instance. The data property contains the instance specific data
35 that needs to be delivered and processed by the decoder.
36
37 @see: U{AbstractMessage on Livedocs (external)
38 <http://livedocs.adobe.com/flex/201/langref/mx/messaging/messages/AbstractMessage.html>}
39
40 @ivar body: Specific data that needs to be delivered to the remote
41 destination.
42 @type body: C{mixed}
43 @ivar clientId: Indicates which client sent the message.
44 @type clientId: C{str}
45 @ivar destination: Message destination.
46 @type destination: C{str}
47 @ivar headers: Message headers. Core header names start with DS.
48 @type headers: C{dict}
49 @ivar messageId: Unique Message ID.
50 @type messageId: C{str}
51 @ivar timeToLive: How long the message should be considered valid and
52 deliverable.
53 @type timeToLive: C{int}
54 @ivar timestamp: Timestamp when the message was generated.
55 @type timestamp: C{int}
56 """
57
58
59
60 DESTINATION_CLIENT_ID_HEADER = "DSDstClientId"
61
62
63 ENDPOINT_HEADER = "DSEndpoint"
64
65
66 REMOTE_CREDENTIALS_HEADER = "DSRemoteCredentials"
67
68
69
70
71 REQUEST_TIMEOUT_HEADER = "DSRequestTimeout"
72
74 self.body = kwargs.get('body', None)
75 self.clientId = kwargs.get('clientId', None)
76 self.destination = kwargs.get('destination', None)
77 self.headers = kwargs.get('headers', {})
78 self.messageId = kwargs.get('messageId', None)
79 self.timeToLive = kwargs.get('timeToLive', 0)
80 self.timestamp = kwargs.get('timestamp', 0)
81
83 m = '<%s ' % self.__class__.__name__
84
85 for k, v in self.__dict__.iteritems():
86 m += ' %s=%s' % (k, v)
87
88 return m + " />"
89
91 """
92 I am the base class for all asynchronous Flex messages.
93
94 @see: U{AsyncMessage on Livedocs (external)
95 <http://livedocs.adobe.com/flex/201/langref/mx/messaging/messages/AsyncMessage.html>}
96
97 @ivar correlationId: Correlation id of the message.
98 @type correlationId: C{str}
99 """
100
101
102
103 SUBTOPIC_HEADER = "DSSubtopic"
104
109
111 """
112 I acknowledge the receipt of a message that was sent previously.
113
114 Every message sent within the messaging system must receive an
115 acknowledgement.
116
117 @see: U{AcknowledgeMessage on Livedocs (external)
118 <http://livedocs.adobe.com/flex/201/langref/mx/messaging/messages/AcknowledgeMessage.html>}
119 """
120
121
122
123 ERROR_HINT_HEADER = "DSErrorHint"
124
181
183 """
184 I am the Flex error message to be returned to the client.
185
186 This class is used to report errors within the messaging system.
187
188 @see: U{ErrorMessage on Livedocs (external)
189 <http://livedocs.adobe.com/flex/201/langref/mx/messaging/messages/ErrorMessage.html>}
190 """
191
192
193
194 MESSAGE_DELIVERY_IN_DOUBT = "Client.Error.DeliveryInDoubt"
195
196
197
198
199 RETRYABLE_HINT_HEADER = "DSRetryableErrorHint"
200
202 AcknowledgeMessage.__init__(self, *args, **kwargs)
203
204
205 self.extendedData = kwargs.get('extendedData', {})
206
207 self.faultCode = kwargs.get('faultCode', None)
208
209 self.faultDetail = kwargs.get('faultDetail', None)
210
211 self.faultString = kwargs.get('faultString', None)
212
213
214 self.rootCause = kwargs.get('rootCause', {})
215
217 """
218 I am used to send RPC requests to a remote endpoint.
219
220 @see: U{RemotingMessage on Livedocs (external)
221 <http://livedocs.adobe.com/flex/201/langref/mx/messaging/messages/RemotingMessage.html>}
222 """
223
225 AbstractMessage.__init__(self, *args, **kwargs)
226
227 self.operation = kwargs.get('operation', None)
228
229
230 self.source = kwargs.get('source', None)
231
232 for x in (RemotingMessage, ErrorMessage, CommandMessage, AcknowledgeMessage, AsyncMessage):
233 pyamf.register_class(x, 'flex.messaging.messages.%s' % x.__name__, metadata=['amf3'])
234 del x
235