Exemplo n.º 1
0
    def validateAndExecuteRequest(self, input):
        '''Match a client request to the corresponding service and method on
        the server, and then call the service.'''

        # Parse and validate the client's request
        self.id = "%f" % time.time()
        RPCStatus.start_request(self.id)
        try:
            request = self.parseServiceRequest(input)
        except error.BadRequestDataError, e:
            RPCStatus.bad_request(self.id)
            return self.handleError(e)
Exemplo n.º 2
0
class RPCHandler(Handler):
    """RPC Handler
    """
    def __init__(self,rpc_server):
        self.rpc_server = rpc_server

    def handle(self,recv):
        # Evaluate and execute the request
        rpcResponse = self.validateAndExecuteRequest(recv)
        logging.debug("Response to return to client \n %s" % rpcResponse)
        return rpcResponse.SerializeToString()

    def validateAndExecuteRequest(self, input):
        '''Match a client request to the corresponding service and method on
        the server, and then call the service.'''

        # Parse and validate the client's request
        self.id = "%f" % time.time()
        RPCStatus.start_request(self.id)
        try:
            request = self.parseServiceRequest(input)
        except error.BadRequestDataError, e:
            RPCStatus.bad_request(self.id)
            return self.handleError(e)

        # Retrieve the requested service
        try:
            service = self.retrieveService(request.service_name)
        except error.ServiceNotFoundError, e:
            RPCStatus.service_not_found(request.service_name,self.id)
            return self.handleError(e)
Exemplo n.º 3
0
        except error.BadRequestDataError, e:
            RPCStatus.bad_request(self.id)
            return self.handleError(e)

        # Retrieve the requested service
        try:
            service = self.retrieveService(request.service_name)
        except error.ServiceNotFoundError, e:
            RPCStatus.service_not_found(request.service_name,self.id)
            return self.handleError(e)

        # Retrieve the requested method
        try:
            method = self.retrieveMethod(service, request.method_name)
        except error.MethodNotFoundError, e:
            RPCStatus.method_not_found(request.service_name,request.method_name,self.id)
            return self.handleError(e)

        # Retrieve the protocol message
        try:
            proto_request = self.retrieveProtoRequest(service, method, request)
        except error.BadRequestProtoError, e:
            return self.handleError(e)

        # Execute the specified method of the service with the requested params
        try:
            response = self.callMethod(service, method, proto_request)
            RPCStatus.end_request(request.service_name,request.method_name,self.id)
        except error.RpcError, e:
            return self.handleError(e)