13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js">// @tag enterprise
<span id='Ext-direct-AmfRemotingProvider'>/**
</span> * @class Ext.direct.AmfRemotingProvider
 * 
 * &lt;p&gt;The {@link Ext.direct.AmfRemotingProvider AmfRemotingProvider}
 * allows making RPC calls to a Java object on a BlazeDS or ColdFusion using either the AMFX or the AMF protocols.&lt;/p&gt;
 * 
 * &lt;p&gt;The default protocol is AMFX which works on all browsers. If you choose AMF, a flash plugin might be loaded in certain browsers that do not support posting binary data to the server, e.g. Internet Explorer version 9 or less. To choose AMF, set the {@link Ext.direct.AmfRemotingProvider#binary binary} property to true.&lt;/p&gt;
 * &lt;p&gt;For AMFX, the server must be configured to expose the desired services via an HTTPEndpoint. For example, the following configuration snippet adds an HTTPEndpoint (AMFX endpoint) to the BlazeDS services-config.xml file:&lt;/p&gt;
 * &lt;pre&gt;&lt;code&gt;
&amp;lt;channel-definition id=&quot;my-http&quot; class=&quot;mx.messaging.channels.HTTPChannel&quot;&amp;gt;
 &amp;lt;endpoint url=&quot;http://{server.name}:{server.port}/{context.root}/messagebroker/http&quot; class=&quot;flex.messaging.endpoints.HTTPEndpoint&quot;/&amp;gt;
&amp;lt;/channel-definition&amp;gt;
 &lt;/code&gt;&lt;/pre&gt;
 *
 * &lt;p&gt;Once the HTTPEndpoint is configured, make sure the service is exposed via the channel by adding the channel (e.g. my-http) to your remoting-services.xml file.
 * For example this allows services to be accessed remotely by both AMF and AMFX:&lt;/p&gt;
 * &lt;pre&gt;&lt;code&gt;
&amp;lt;default-channels&amp;gt;
 &amp;lt;channel ref=&quot;my-amf&quot;/&amp;gt;
 &amp;lt;channel ref=&quot;my-http&quot;/&amp;gt;
&amp;lt;/default-channels&amp;gt;
 * &lt;/code&gt;&lt;/pre&gt;
 * 
 * &lt;p&gt;In order to make a call, you first need to declare the API to Ext direct. The following example defines local methods to the services provided by the sample Products application provided by Adobe as part of the BlazeDS 4.x binary turnkey distribution's testdrive (Sample 5: Updating Data):&lt;/p&gt;
 * &lt;pre&gt;&lt;code&gt;
    Ext.direct.Manager.addProvider({
        &quot;url&quot;:&quot;/samples/messagebroker/http&quot;, // URL for the HTTPEndpoint
        &quot;type&quot;:&quot;amfremoting&quot;,
        &quot;endpoint&quot;: &quot;my-http&quot;, // the name of the HTTPEndpoint channel as defined in the server's services-config.xml
        &quot;actions&quot;:{
        &quot;product&quot;:[{ // name of the destination as defined in remoting-config.xml on the server
            &quot;name&quot;:&quot;getProducts&quot;, // method name of the method to call
            &quot;len&quot;:0 // number of parameters
        },{
            &quot;name&quot;:&quot;add&quot;,
            &quot;len&quot;:1
        },{
            &quot;name&quot;:&quot;bad&quot;,
            &quot;len&quot;:0
        }]
        }
    });
 
 * &lt;/code&gt;&lt;/pre&gt;
 * &lt;p&gt;You can now call the service as follows:&lt;/p&gt;
 &lt;pre&gt;&lt;code&gt;
product.getProducts((function(provider, response) {
    // do something with the response
    console.log(&quot;Got &quot; + response.data.length + &quot; objects&quot;);
});
&lt;/code&gt;&lt;/pre&gt;
 * 
 * Note that in case server methods require parameters of a specific class (e.g. flex.samples.product.Product), you should make sure the passed parameter has a field called $flexType set to the class name (in this case flex.Samples.product.Product). This is similar to the remote class alias definition in ActionScript.
 * 
 * 
 * &lt;p&gt;The following example shows how to define a binary AMF-based call:&lt;/p&gt;
 * &lt;pre&gt;&lt;code&gt;
    Ext.direct.Manager.addProvider({
        &quot;url&quot;:&quot;/samples/messagebroker/amf&quot;, // URL for the AMFEndpoint
        &quot;type&quot;:&quot;amfremoting&quot;,
        &quot;endpoint&quot;: &quot;my-amf&quot;, // the name of the AMFEndpoint channel as defined in the server's services-config.xml
        &quot;binary&quot;: true, // chooses AMF encoding
        &quot;actions&quot;:{
        &quot;product&quot;:[{ // name of the destination as defined in remoting-config.xml on the server
            &quot;name&quot;:&quot;getProducts&quot;, // method name of the method to call
            &quot;len&quot;:0 // number of parameters
        },{
            &quot;name&quot;:&quot;add&quot;,
            &quot;len&quot;:1
        },{
            &quot;name&quot;:&quot;bad&quot;,
            &quot;len&quot;:0
        }]
        }
    });
 
 * &lt;/code&gt;&lt;/pre&gt;
 * &lt;p&gt;Calling the server is done the same way as for the AMFX-based definition.&lt;/p&gt;
 
 */
Ext.define('Ext.direct.AmfRemotingProvider', {
    
    /* Begin Definitions */
   
    alias: 'direct.amfremotingprovider',
    
    extend: 'Ext.direct.Provider', 
    
    requires: [
        'Ext.util.MixedCollection', 
        'Ext.util.DelayedTask', 
        'Ext.direct.Transaction',
        'Ext.direct.RemotingMethod',
        'Ext.data.amf.XmlEncoder',
        'Ext.data.amf.XmlDecoder',
        'Ext.data.amf.Encoder',
        'Ext.data.amf.Packet',
        'Ext.data.amf.RemotingMessage',
        'Ext.direct.ExceptionEvent'
    ],
   
    /* End Definitions */
   
<span id='Ext-direct-AmfRemotingProvider-cfg-actions'>   /**
</span>     * @cfg {Object} actions
     * Object literal defining the server side actions and methods. For example, if
     * the Provider is configured with:
     * &lt;pre&gt;&lt;code&gt;
&quot;actions&quot;:{ // each property within the 'actions' object represents a server side Class 
    &quot;TestAction&quot;:[ // array of methods within each server side Class to be   
    {              // stubbed out on client
        &quot;name&quot;:&quot;doEcho&quot;, 
        &quot;len&quot;:1            
    },{
        &quot;name&quot;:&quot;multiply&quot;,// name of method
        &quot;len&quot;:2           // The number of parameters that will be used to create an
                          // array of data to send to the server side function.
                          // Ensure the server sends back a Number, not a String. 
    },{
        &quot;name&quot;:&quot;doForm&quot;,
        &quot;formHandler&quot;:true, // direct the client to use specialized form handling method 
        &quot;len&quot;:1
    }]
}
     * &lt;/code&gt;&lt;/pre&gt;
     * &lt;p&gt;Note that a Store is not required, a server method can be called at any time.
     * In the following example a &lt;b&gt;client side&lt;/b&gt; handler is used to call the
     * server side method &quot;multiply&quot; in the server-side &quot;TestAction&quot; Class:&lt;/p&gt;
     * &lt;pre&gt;&lt;code&gt;
TestAction.multiply(
    2, 4, // pass two arguments to server, so specify len=2
    // callback function after the server is called
    // result: the result returned by the server
    //      e: Ext.direct.RemotingEvent object
    function(result, e) {
        var t = e.getTransaction();
        var action = t.action; // server side Class called
        var method = t.method; // server side method called
        if(e.status) {
            var answer = Ext.encode(result); // 8
    
        } else {
            var msg = e.message; // failure message
        }
    }
);
     * &lt;/code&gt;&lt;/pre&gt;
     * In the example above, the server side &quot;multiply&quot; function will be passed two
     * arguments (2 and 4).  The &quot;multiply&quot; method should return the value 8 which will be
     * available as the &lt;tt&gt;result&lt;/tt&gt; in the example above. 
     */
    
<span id='Ext-direct-AmfRemotingProvider-cfg-namespace'>    /**
</span>     * @cfg {String/Object} namespace
     * Namespace for the Remoting Provider (defaults to the browser global scope of &lt;i&gt;window&lt;/i&gt;).
     * Explicitly specify the namespace Object, or specify a String to have a
     * {@link Ext#namespace namespace created} implicitly.
     */
    
<span id='Ext-direct-AmfRemotingProvider-cfg-url'>    /**
</span>     * @cfg {String} url
     * &lt;b&gt;Required&lt;/b&gt;. The URL to connect to the Flex remoting server (LCDS, BlazeDS, etc).
     * This should include the /messagebroker/amf suffix as defined in the services-config.xml and remoting-config.xml files.
     */
    
<span id='Ext-direct-AmfRemotingProvider-cfg-endpoint'>    /**
</span>     * @cfg {String} endpoint
     * &lt;b&gt;Requred&lt;/b&gt;. This is the channel id defined in services-config.xml on the server (e.g. my-amf or my-http).
     */
 
<span id='Ext-direct-AmfRemotingProvider-cfg-enableUrlEncode'>    /**
</span>     * @cfg {String} enableUrlEncode
     * Specify which param will hold the arguments for the method.
     * Defaults to &lt;tt&gt;'data'&lt;/tt&gt;.
     */
    
<span id='Ext-direct-AmfRemotingProvider-cfg-binary'>    /**
</span>     * @cfg {String} binary
     * If true, use AMF binary encoding instead of AMFX XML-based encoding. Note that on some browsers, this will load a flash plugin to handle binary communication with the server. Important: If using binary encoding with older browsers, see notes in {@link Ext.data.flash.BinaryXhr BinaryXhr} regarding packaging the Flash plugin for use in older browsers.
     */
    binary: false,
    
<span id='Ext-direct-AmfRemotingProvider-cfg-maxRetries'>    /**
</span>     * @cfg {Number} maxRetries
     * Number of times to re-attempt delivery on failure of a call.
     */
    maxRetries: 1,
    
<span id='Ext-direct-AmfRemotingProvider-cfg-timeout'>    /**
</span>     * @cfg {Number} timeout
     * The timeout to use for each request.
     */
    timeout: undefined,
    
<span id='Ext-direct-AmfRemotingProvider-method-constructor'>    constructor : function(config){
</span>        var me = this;
        me.callParent(arguments);
        me.addEvents(
<span id='Ext-direct-AmfRemotingProvider-event-beforecall'>            /**
</span>             * @event beforecall
             * Fires immediately before the client-side sends off the RPC call.
             * By returning false from an event handler you can prevent the call from
             * executing.
             * @param {Ext.direct.AmfRemotingProvider} provider
             * @param {Ext.direct.Transaction} transaction
             * @param {Object} meta The meta data
             */            
            'beforecall',            
<span id='Ext-direct-AmfRemotingProvider-event-call'>            /**
</span>             * @event call
             * Fires immediately after the request to the server-side is sent. This does
             * NOT fire after the response has come back from the call.
             * @param {Ext.direct.AmfRemotingProvider} provider
             * @param {Ext.direct.Transaction} transaction
             * @param {Object} meta The meta data
             */            
            'call'
        );
        me.namespace = (Ext.isString(me.namespace)) ? Ext.ns(me.namespace) : me.namespace || window;
        me.transactions = new Ext.util.MixedCollection();
        me.callBuffer = [];
    },
 
<span id='Ext-direct-AmfRemotingProvider-method-initAPI'>    /**
</span>     * Initialize the API
     * @private
     */
    initAPI : function(){
        var actions = this.actions,
            namespace = this.namespace,
            action,
            cls,
            methods,
            i,
            len,
            method;
        
        for (action in actions) {
            if (actions.hasOwnProperty(action)) {
                cls = namespace[action];
                if (!cls) {
                    cls = namespace[action] = {};
                }
                methods = actions[action];
                
                for (i = 0, len = methods.length; i &lt; len; ++i) {
                    method = new Ext.direct.RemotingMethod(methods[i]);
                    cls[method.name] = this.createHandler(action, method);
                }
            }
        }
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-createHandler'>    /**
</span>     * Create a handler function for a direct call.
     * @private
     * @param {String} action The action the call is for
     * @param {Object} method The details of the method
     * @return {Function} A JS function that will kick off the call
     */
    createHandler : function(action, method){
        var me = this,
            handler;
        
        if (!method.formHandler) {
            handler = function(){
                me.configureRequest(action, method, Array.prototype.slice.call(arguments, 0));
            };
        } else {
            handler = function(form, callback, scope){
                me.configureFormRequest(action, method, form, callback, scope);
            };
        }
        handler.directCfg = {
            action: action,
            method: method
        };
        return handler;
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-isConnected'>    // inherit docs
</span>    isConnected: function(){
        return !!this.connected;
    },
 
<span id='Ext-direct-AmfRemotingProvider-method-connect'>    // inherit docs
</span>    connect: function(){
        var me = this;
        
        if (me.url) {
            // Generate a unique ID for this client
            me.clientId = Ext.data.amf.XmlEncoder.generateFlexUID();
            me.initAPI();
            me.connected = true;
            me.fireEvent('connect', me);
            me.DSId = null;
        } else if(!me.url) {
            //&lt;debug&gt;
            Ext.Error.raise('Error initializing RemotingProvider, no url configured.');
            //&lt;/debug&gt;
        }
    },
 
<span id='Ext-direct-AmfRemotingProvider-method-disconnect'>    // inherit docs
</span>    disconnect: function(){
        var me = this;
        
        if (me.connected) {
            me.connected = false;
            me.fireEvent('disconnect', me);
        }
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-runCallback'>    /**
</span>     * Run any callbacks related to the transaction.
     * @private
     * @param {Ext.direct.Transaction} transaction The transaction
     * @param {Ext.direct.Event} event The event
     */
    runCallback: function(transaction, event){
        var success = !!event.status,
            funcName = success ? 'success' : 'failure',
            callback,
            result;
        if (transaction &amp;&amp; transaction.callback) {
            callback = transaction.callback;
            result = Ext.isDefined(event.result) ? event.result : event.data;
            
            if (Ext.isFunction(callback)) {
                callback(result, event, success);
            } else {
                Ext.callback(callback[funcName], callback.scope, [result, event, success]);
                Ext.callback(callback.callback, callback.scope, [result, event, success]);
            }
        }
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-onData'>    /**
</span>     * React to the ajax request being completed
     * @private
     */
    onData: function(options, success, response){
        var me = this,
            i = 0,
            len,
            events,
            event,
            transaction,
            transactions;
        
        if (success) {
            events = me.createEvents(response);
            for (len = events.length; i &lt; len; ++i) {
                event = events[i];
                transaction = me.getTransaction(event);
                me.fireEvent('data', me, event);
                if (transaction) {
                    me.runCallback(transaction, event, true);
                    Ext.direct.Manager.removeTransaction(transaction);
                }
            }
        } else {
            transactions = [].concat(options.transaction);
            for (len = transactions.length; i &lt; len; ++i) {
                transaction = me.getTransaction(transactions[i]);
                if (transaction &amp;&amp; transaction.retryCount &lt; me.maxRetries) {
                    transaction.retry();
                } else {
                    event = new Ext.direct.ExceptionEvent({
                        data: null,
                        transaction: transaction,
                        code: Ext.direct.Manager.exceptions.TRANSPORT,
                        message: 'Unable to connect to the server.',
                        xhr: response
                    });
                    me.fireEvent('data', me, event);
                    if (transaction) {
                        me.runCallback(transaction, event, false);
                        Ext.direct.Manager.removeTransaction(transaction);
                    }
                }
            }
        }
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-getTransaction'>    /**
</span>     * Get transaction from XHR options
     * @private
     * @param {Object} options The options sent to the Ajax request
     * @return {Ext.direct.Transaction} The transaction, null if not found
     */
    getTransaction: function(options){
        return options &amp;&amp; options.tid ? Ext.direct.Manager.getTransaction(options.tid) : null;
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-configureRequest'>    /**
</span>     * Configure a direct request
     * @private
     * @param {String} action The action being executed
     * @param {Object} method The method being executed
     */
    configureRequest: function(action, method, args){
        var me = this,
            callData = method.getCallData(args),
            data = callData.data, 
            callback = callData.callback, 
            scope = callData.scope,
            transaction;
 
        transaction = new Ext.direct.Transaction({
            provider: me,
            args: args,
            action: action,
            method: method.name,
            data: data,
            callback: scope &amp;&amp; Ext.isFunction(callback) ? Ext.Function.bind(callback, scope) : callback
        });
 
        if (me.fireEvent('beforecall', me, transaction, method) !== false) {
            Ext.direct.Manager.addTransaction(transaction);
            me.queueTransaction(transaction);
            me.fireEvent('call', me, transaction, method);
        }
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-getCallData'>    /**
</span>     * Gets the Flex remoting message info for a transaction
     * @private
     * @param {Ext.direct.Transaction} transaction The transaction
     * @return {Object} The Flex remoting message structure ready to encode in an AMFX RemoteMessage
     */
    getCallData: function(transaction){
        if (this.binary) {
            return {
                targetUri: transaction.action + &quot;.&quot; + transaction.method,
                responseUri: '/' + transaction.id,
                body: transaction.data || []
            };
        } else {
            return new Ext.data.amf.RemotingMessage( 
                              {
                                  body: transaction.data || [],
                                  clientId: this.clientId,
                                  destination: transaction.action,
                                  headers: {
                                      DSEndpoint: this.endpoint,
                                      DSId: this.DSId || &quot;nil&quot; // if unknown yet, use &quot;nil&quot;
                                  },
                                  messageId: Ext.data.amf.XmlEncoder.generateFlexUID(transaction.id), // encode as first 4 bytes of UID
                                  operation: transaction.method,
                                  timestamp: 0,
                                  timeToLive: 0
                              });
        }
        /*
         return {
         action: transaction.action,
         method: transaction.method,
         data: transaction.data,
         type: 'rpc',
         tid: transaction.id
         };
         */
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-sendRequest'>    /**
</span>     * Sends a request to the server
     * @private
     * @param {Object/Array} data The data to send
     */
    sendRequest : function(data){
        var me = this,
            request = {
                url: me.url,
                callback: me.onData,
                scope: me,
                transaction: data,
                timeout: me.timeout
            }, callData,
            i = 0,
            len,
            params,
            encoder,
            amfMessages = [],
            amfHeaders = [];
        
 
        // prepare AMFX messages
        if (Ext.isArray(data)) {
            //&lt;debug&gt;
            if (!me.binary) {
                Ext.Error.raise(&quot;Mutltiple messages in the same call are not supported in AMFX&quot;);
            }
            //&lt;/debug&gt;
            for (len = data.length; i &lt; len; ++i) {
                amfMessages.push(me.getCallData(data[i]));
            }
        } else {
            amfMessages.push(me.getCallData(data));
        }
        
        if (me.binary) {
            encoder = new Ext.data.amf.Encoder( {format: 0}); // AMF message sending always uses AMF0
            // encode packet
            encoder.writeAmfPacket(amfHeaders, amfMessages);
            request.binaryData = encoder.bytes;
            request.binary = true; // Binary response
            request.headers = {'Content-Type': 'application/x-amf'};
        } else {
            encoder = new Ext.data.amf.XmlEncoder();
            // encode packet
            encoder.writeAmfxRemotingPacket(amfMessages[0]);
            request.xmlData = encoder.body;
        }
        
        
        // prepare Ajax request
        Ext.Ajax.request(request);
 
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-queueTransaction'>    /**
</span>     * Add a new transaction to the queue
     * @private
     * @param {Ext.direct.Transaction} transaction The transaction
     */
    queueTransaction: function(transaction){
        var me = this,
            enableBuffer = false; // no queueing for AMFX
        
        if (transaction.form) {
            me.sendFormRequest(transaction);
            return;
        }
        
        me.callBuffer.push(transaction);
        if (enableBuffer) {
            if (!me.callTask) {
                me.callTask = new Ext.util.DelayedTask(me.combineAndSend, me);
            }
            me.callTask.delay(Ext.isNumber(enableBuffer) ? enableBuffer : 10);
        } else {
            me.combineAndSend();
        }
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-combineAndSend'>    /**
</span>     * Combine any buffered requests and send them off
     * @private
     */
    combineAndSend : function(){
        var buffer = this.callBuffer,
            len = buffer.length;
        
        if (len &gt; 0) {
            this.sendRequest(len == 1 ? buffer[0] : buffer);
            this.callBuffer = [];
        }
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-configureFormRequest'>    /**
</span>     * Configure a form submission request
     * @private
     * @param {String} action The action being executed
     * @param {Object} method The method being executed
     * @param {HTMLElement} form The form being submitted
     * @param {Function} callback (optional) A callback to run after the form submits
     * @param {Object} scope (optional) A scope to execute the callback in
     */
    configureFormRequest : function(action, method, form, callback, scope){
        //&lt;debug&gt;
        Ext.Error.raise(&quot;Form requests are not supported for AmfRemoting&quot;);
        //&lt;/debug&gt;
        /*
         var me = this,
         transaction = new Ext.direct.Transaction({
         provider: me,
         action: action,
         method: method.name,
         args: [form, callback, scope],
         callback: scope &amp;&amp; Ext.isFunction(callback) ? Ext.Function.bind(callback, scope) : callback,
         isForm: true
         }),
         isUpload,
         params;
 
         if (me.fireEvent('beforecall', me, transaction, method) !== false) {
         Ext.direct.Manager.addTransaction(transaction);
         isUpload = String(form.getAttribute(&quot;enctype&quot;)).toLowerCase() == 'multipart/form-data';
         
         params = {
         extTID: transaction.id,
         extAction: action,
         extMethod: method.name,
         extType: 'rpc',
         extUpload: String(isUpload)
         };
         
         // change made from typeof callback check to callback.params
         // to support addl param passing in DirectSubmit EAC 6/2
         Ext.apply(transaction, {
         form: Ext.getDom(form),
         isUpload: isUpload,
         params: callback &amp;&amp; Ext.isObject(callback.params) ? Ext.apply(params, callback.params) : params
         });
         me.fireEvent('call', me, transaction, method);
         me.sendFormRequest(transaction);
         }
         */
    },
    
<span id='Ext-direct-AmfRemotingProvider-method-sendFormRequest'>    /**
</span>     * Sends a form request
     * @private
     * @param {Ext.direct.Transaction} transaction The transaction to send
     */
    sendFormRequest: function(transaction){
        //&lt;debug&gt;
        Ext.Error.raise(&quot;Form requests are not supported for AmfRemoting&quot;);
        //&lt;/debug&gt;
        /*
         Ext.Ajax.request({
         url: this.url,
         params: transaction.params,
         callback: this.onData,
         scope: this,
         form: transaction.form,
         isUpload: transaction.isUpload,
         transaction: transaction
         });
         */
    },
 
<span id='Ext-direct-AmfRemotingProvider-method-createEvents'>    /**
</span>     * Creates a set of events based on the XHR response
     * @private
     * @param {Object} response The XHR response
     * @return {Ext.direct.Event[]} An array of Ext.direct.Event
     */
    createEvents: function(response){
        var data = null,
            rawBytes = [],
            events = [],
            event,
            i = 0,
            len,
            decoder;
        try {
            if (this.binary) {
                decoder = new Ext.data.amf.Packet();
                data = decoder.decode(response.responseBytes);
            } else {
                decoder = new Ext.data.amf.XmlDecoder();
                data = decoder.readAmfxMessage(response.responseText);
            }
            /*
             // This won't be sent back unless we use a ping message, so ignore for now
             // if we don't have the server ID yet, check for it here
             if (!this.DSId) {
             if (data.message.headers &amp;&amp; data.message.headers.DSId) {
             this.DSId = data.message.headers.DSId;
             }
             }
             */
        } catch(e) {
 
            event = new Ext.direct.ExceptionEvent({
                data: e,
                xhr: response,
                code: Ext.direct.Manager.exceptions.PARSE,
                message: 'Error parsing AMF response: \n\n ' + data
            });
            return [event];
        }
 
        if (this.binary) {
            for (i=0; i &lt; data.messages.length; i++) {
                events.push(this.createEvent(data.messages[i]));
            }
        } else {
            // AMFX messages have one response per message
            events.push(this.createEvent(data));
        }
        return events;
    },
 
<span id='Ext-direct-AmfRemotingProvider-method-createEvent'>    /**
</span>     * Create an event from an AMFX response object
     * @param {Object} response The AMFX response object
     * @return {Ext.direct.Event} The event
     */
    createEvent: function(response){
        // Check targetUri to identify transaction ID and status
        var status = response.targetURI.split(&quot;/&quot;),
            tid,
            event,
            data, statusIndex,
            me = this;
        if (me.binary) {
            tid = status[1];
            statusIndex = 2;
        } else {
            tid = Ext.data.amf.XmlDecoder.decodeTidFromFlexUID(response.message.correlationId);
            statusIndex = 1;
        }
        // construct data structure
        if (status[statusIndex] == &quot;onStatus&quot;) {
            // The call failed
            data = {
                tid: tid,
                data: (me.binary ? response.body : response.message)
            };
            event = Ext.create('direct.exception', data);
        } else if(status[statusIndex] == &quot;onResult&quot;) {
            // Call succeeded
            data = {
                tid: tid,
                data: (me.binary ? response.body : response.message.body)
            };
            event = Ext.create('direct.rpc', data);
        } else {
            //&lt;debug&gt;
            Ext.Error.raise(&quot;Unknown AMF return status: &quot; + status[statusIndex]);
            //&lt;/debug&gt;
        }
        
        return event;
    }
 
    
});
</pre>
</body>
</html>