Test Flash Remoting Services w/ ARP

If you are developing service calls, but the back-end (Java, .NET, ColdFusion, etc.) isn’t done yet, you can still be productive by setting up test services. Utilizing what the ServiceLocator in ARP does best, you can point to your test service class instead of the real service, which would be a server gateway.

Your test service is merely an ActionScript class that has all of the methods that your back-end service would have. So, if you plan on calling “createItem” and passing a string as the only parameter to some Java method on the backend, you merely mirror that in ActionScript.

You do this for all of your methods. That way, you can continue writing your Commands and Business Delegate server calls as normal with plans to use them as is. When the back-end is ready, you change 2 lines of code in your ServiceLocator from this:

var CreateItemsService = new TestService("", null, "CreateItemsService", null, null);
addService("CreateItemsService", CreateItemsService);

to this:

var CreateItemsService = new Service("http://server.com/gateway", null, "CreateItemsService", null, null);
addService("CreateItemsService", CreateItemsService);

Notice the only thing that changes is you instantiate a real Flash Remoting Service class (Flex RemoteObject’ish), and put in a real gateway URL.

That’s it!

Here’s an example of the TestService.as file. This class extends the mx.remoting.Service class so it operates like a real remoting class. It’ll create Operations, return PendingCalls to server method calls, etc. All you do is make an interval so the method call “waits” 2 seconds before responding so it “feels” like it’s taking some time to talk to the server, where in reality there is no server at all, just ActionScript acting like it.

Bottom line, to avoid the waterfall effect where a client developer is waiting on a server-side developer before she/he can proceed, this allows you to continue coding without a server, and if the server gets fubarred during development, you can merely toggle this back on to continue testing.

I reckon this would work in Cairngorm too if you chose to use straight ActionScript instead of RemoteObject tags.

import mx.remoting.Service;
import mx.remoting.PendingCall;
import mx.services.Log;
import mx.remoting.Connection;
import mx.rpc.Responder;

class com.company.project.model.testing.TestService
{
        private var speed:Number = 2 * 1000; // milliseconds
        
        private var createItemID:Number;
        private var createItemPC:PendingCall;
        
        function TestService(gatewayURI:String, logger:Log, serviceName:String, conn:Connection, resp:Responder)
        {
                super.apply(this, arguments);
        }
        
        public function createItem(itemName:String):PendingCall
        {
                clearInterval(createItemID);
                createItemID = setInterval(this, "onCreatedItem", speed);
                createItemPC = new PendingCall(Service(this), "createItem");
                return createItemPC;
        }
        
        private function onCreatedItem():Void
        {
                clearInterval(createItemID);
                createItemID = null;
                delete createItemID;
                
                createItemPC.onResult(true);
                createItemPC = null;
                delete createItemPC;
        }
}

3 Replies to “Test Flash Remoting Services w/ ARP”

  1. That’s a great idea! I’ve got a couple of projects where we’re going to have to develop to a back end that doesn’t exist yet. We were thinking to develop a false back-end in .NET and then switch over, but this even eliminates that trouble.

    Thanks!

    Satori

  2. To be honest, I was doing the exact same thing in PHP for the 3rd time, and had had it. WHY can’t I write this in a language I’m more comfortable with, and NOT need a frikin server? Oh… I can.

Comments are closed.