tags:

views:

9

answers:

0

Hy!

When I send a message from the login in the flex 4 app, the server side receive it. If in the login.py it would be True in the place of that string, the onResult on the client side is triggered, while with the string is not! :s why?

My server side looks like this:

index.py

#from google.appengine.ext.webapp.util import run_wsgi_app
#from google.appengine.ext import webapp
from TottysGateway import TottysGateway
import logging
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

def main():
    services_root = 'services'
    services = ['users.login']

    gateway = TottysGateway(services, services_root, '', logging, True)

    app = webapp.WSGIApplication([('/API', gateway)], debug=True)

    run_wsgi_app(app)

if __name__ == "__main__":
    main()

TottysGateway.py

import logging
from pyamf.remoting.gateway.google import WebAppGateway


class TottysGateway(WebAppGateway):
    def __init__(self, services_available, root_path, not_found_service, logger, debug):
        # override the contructor and then call the super
        self.services_available = services_available
        self.root_path = root_path
        self.not_found_service = not_found_service
        WebAppGateway.__init__(self, {}, logger=logging, debug=True)


    def getServiceRequest(self, request, target_p):
        # target edit:
        #target = target.rsplit('.')
        target = target_p[2:]
        # override the original getServiceRequest method
        try:
            # try looking for the service in the services list
            return WebAppGateway.getServiceRequest(self, request, target)
        except:
            pass

        try:
            # don't know what it does but is an error for now
            service_func = self.router(target)
        except:
            if(target in self.services_available):
                # only if is an available service import it's module
                # so it doesn't access services that should be hidden
                try:
                    paths = target.rsplit('.')
                    module_path = self.root_path + '.' + target
                    func_name = paths[-1]
                    #import_as = '_'.join(paths) + '_' + func_name
                    import_string = "from " + module_path + " import " + func_name + ' as service_func'
                    exec import_string
                except:
                    service_func = False

        if not service_func:
            # if is not found load the default not found service
            module_path = self.rootPath + '.' + self.not_found_service
            import_string = "from " + module_path + " import " + func_name + ' as service_func'

        # add the service loaded above
        self.addService(service_func, target)
        #assign_string = "self.addService(service_func, target)"
        #exec assign_string

        return WebAppGateway.getServiceRequest(self, request, target)

login.py

def login(input): 'reply from pyamf'

My Client side looks like this (only the parts that matter with communicating with the server):

UsersService.as extends Service

input is just a value object instance

package com.totty.app.services
{
    import com.totty.app.Settings;
    import com.totty.app.VO.LoginVO;
    import com.totty.app.events.RemoteServiceEvent;
    import com.totty.app.services.IServices.IUsersService;
    import com.totty.app.services.supportClasses.RemoteService;
    import com.totty.app.services.supportClasses.Service;

    import mx.controls.Alert;
    import mx.messaging.ChannelSet;
    import mx.messaging.channels.AMFChannel;
    import mx.rpc.AbstractOperation;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.remoting.RemoteObject;

    import org.robotlegs.mvcs.Actor;

    public class UsersService extends Service implements IUsersService
    {



        public function logout():void{}

        public function login(input:LoginVO):void{
            send(input, 'users.login', _login_resultHandler, _login_faultHandler);
        }



        protected function _login_resultHandler(event:RemoteServiceEvent):void{
            Alert.show(event.data);
        }

        protected function _login_faultHandler(event:RemoteServiceEvent):void{
            Alert.show('error');
        }
    }
}

Service.as

package com.totty.app.services.supportClasses{
    import com.totty.app.Settings;

    import org.robotlegs.mvcs.Actor;

    public class Service extends Actor{
        protected var _rs:RemoteService = new RemoteService();

        public function Service()
        {
            super();
        }

        protected function send(input:*, service:String, resultHandler:Function, faultHandler:Function):void{
            _rs.resultHandler = resultHandler;
            _rs.faultHandler = faultHandler;
            _rs.endpoint = Settings.SERVICES_URL;
            _rs.destination = 'a';
            _rs.source = 'String';
            _rs.send(service, input);
        }
    }
}

RemoteService.as

package com.totty.app.services.supportClasses{
    import com.totty.app.events.RemoteServiceEvent;

    import flash.events.EventDispatcher;

    import mx.messaging.ChannelSet;
    import mx.messaging.channels.AMFChannel;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.remoting.RemoteObject;

    public class RemoteService extends EventDispatcher {

        protected var remoting:RemoteObject;
        protected var _resultHandler:Function;
        protected var _faultHandler:Function;
        protected var _source:String;
        protected var _destination:String;
        protected var _endpoint:String;

        public function RemoteService (endpoint:String = null) {
            super();
            if(endpoint) {
                _endpoint = endpoint;
                initializeRemoteObject();
            }
        }

        protected function initializeRemoteObject():void {
            try {
                remoting = new RemoteObject();
                addEventListener(RemoteServiceEvent.RESULT, _resultHandler);
                addEventListener(RemoteServiceEvent.FAULT, _faultHandler);
                remoting.addEventListener(ResultEvent.RESULT, onResult);
                remoting.addEventListener(FaultEvent.FAULT, onFault);
                var channelSet:ChannelSet = new ChannelSet();
                var amfChannel:AMFChannel = new AMFChannel();
                amfChannel.uri = _endpoint;
                channelSet.channels = [amfChannel];
                remoting.channelSet = channelSet;
                remoting.source = _source;
                remoting.destination = _destination;
            }catch(e:Error) {
                //removeHandlersListeners();
            }
        }

        public function send(method:String, param:Object = null):void {
            if(!remoting) {
                initializeRemoteObject();
            }
            if(param) {
                remoting.getOperation(method).send(param);
            }else {
                remoting.getOperation(method).send();
            }
        }

        public function removeHandlersListeners2():void{
            removeEventListener(RemoteServiceEvent.RESULT, _resultHandler);
            removeEventListener(RemoteServiceEvent.FAULT, _faultHandler);
        }

        private function onResult(event:ResultEvent):void {
            dispatchEvent(new RemoteServiceEvent(RemoteServiceEvent.RESULT, event.result));
            //removeHandlersListeners()
        }

        private function onFault(fault:FaultEvent):void {
            dispatchEvent(new RemoteServiceEvent(RemoteServiceEvent.FAULT, fault.fault));
            //removeHandlersListeners()
        }

        public function set endpoint(_g:String):void {
            _endpoint = _g;
        }

        public function get endpoint ():String {
            return _endpoint;
        }

        public function set destination(_g:String):void {
            _destination = _g;
        }

        public function get destination ():String {
            return _destination;
        }

        public function set source(_g:String):void {
            _source = _g;
        }

        public function get source ():String {
            return _source;
        }

        public function set resultHandler(value:Function):void{
            _resultHandler = value;
        }

        public function set faultHandler(value:Function):void{
            _faultHandler = value;
        }
    }
};

When I send a message from the login in the flex 4 app, the server side receive it. If in the login.py it would be True in the place of that string, the onResult on the client side is triggered, while with the string is not! :s why?