示例#1
0
    def deserialize_and_reply(self, request):

        start_working = datetime.datetime.now()

        if not ZMQUtils.is_valid_envelop(request):
            print 'Invalid Request:', TypeError
            res = error_response(ERROR_INVALID_ENVELOP)
        else:
            if self.verbose:
                print "raw_request", request
            pboreq = PBOneRequest()
            res = ''
            try:
                pboreq = PBOneRequest()
                pboreq.ParseFromString(request[0])
                pboresp = self.handle_request(pboreq)
                end_working = datetime.datetime.now()
                delta = end_working - start_working
                pboresp.gresp.computetime = delta.total_seconds()
                res = pboresp.SerializeToString()
            except TypeError:
                print 'Exception:', TypeError
                traceback.print_exc()
                res = error_response(ERROR_PARSING_EXCEPTION)
            except Exception:
                print 'General Exception:', Exception
                traceback.print_exc()
                res = error_response(ERROR_PARSING_EXCEPTION)
            finally:
                if self.verbose:
                    print 'raw_reply:', res
                return [res]
def search_food_request_handler(oreq):
    oresp = PBOneResponse()
    try:
        pbrealreq = oreq.searchfoodreq
        processor = SearchFoodProcessor(pbrealreq)

        oresp.etype = ERROR_NONE
        oresp.rtype = SEARCH_FOOD_RESPONSE
        # a partir de la si il y a une erreur elle est fonctionnelle
        processor.process(oresp.searchfoodresp)

    except Exception:
        traceback.print_exc()
        oresp = error_response(ERROR_REQUEST_HANDLER)
    finally:
        return oresp
示例#3
0
def another_request_handler(oreq):
    oresp = PBOneResponse()
    try:
        pbrealreq = oreq.anotherreq
        processor = AnotherProcessor(pbrealreq)

        oresp.rtype = ANOTHER_RESPONSE
        processor.process(oresp.anotherresp)
        # a partir de la si il y a une erreur elle est fonctionnelle
        oresp.etype = ERROR_NONE

    except Exception:
        print "another_request: ", Exception
        traceback.print_exc()
        oresp = error_response(ERROR_REQUEST_HANDLER)
    finally:
        return oresp
示例#4
0
def simple_request_handler(oreq):

    oresp = PBOneResponse()
    try:
        pbsimplereq = oreq.simplereq
        processor = SimpleProcessor(pbsimplereq)

        oresp.rtype = SIMPLE_RESPONSE
        processor.process(oresp.simpleresp)
        # a partir de la si il y a une erreur elle est fonctionnelle
        oresp.etype = ERROR_NONE

    except Exception:
        print "simple_request: ", Exception
        traceback.print_exc()
        oresp = error_response(ERROR_REQUEST_HANDLER)
    finally:
        return oresp
示例#5
0
    def handle_request(self, oreq):

        # prepare response
        oresp = PBOneResponse()
        if self.verbose:
            print "handle:", PBRequestType.values_by_number[oreq.rtype].name

        # if exists
        if oreq.rtype in self.existing_services.keys():
            # do the job
            oresp = self.existing_services[oreq.rtype](oreq)
        else:
            oresp = error_response(ERROR_UNKNOWN_SERVICE)
            print "dispatch: Unknown service:", oreq.rtype

        # Fill in Generic Response
        fillOneResponseGenericFields(oresp, oreq)

        return oresp