コード例 #1
0
 def retrieveProtoRequest(self, service, method, request):
     ''' Retrieve the users protocol message from the RPC message'''
     proto_request = service.GetRequestClass(method)()
     try:
         proto_request.ParseFromString(request.request_proto)
     except Exception, e:
         raise error.BadRequestProtoError(unicode(e))
コード例 #2
0
    def validateRequest(self, request):
        '''Validate the client request against the protocol file.'''

        # Check the request is correctly initialized
        if not request.IsInitialized():
            raise error.BadRequestProtoError('Client request is missing\
                                              mandatory fields')
コード例 #3
0
    def test_BadRequestProtoError(self):
        expected_error_code = rpc_pb2.BAD_REQUEST_PROTO

        e = error.BadRequestProtoError(self.msg)

        self.assertEqual(e.message, self.msg, 'BadRequestProtoError - message')
        self.assertEqual(e.rpc_error_code, expected_error_code,
                         'BadRequestProtoError - error code')
コード例 #4
0
                   % (method_name, service.DESCRIPTOR.name)
            raise error.MethodNotFoundError(msg)

        return method

    def retrieveProtoRequest(self, service, method, request):
        ''' Retrieve the users protocol message from the RPC message'''
        proto_request = service.GetRequestClass(method)()
        try:
            proto_request.ParseFromString(request.request_proto)
        except Exception, e:
            raise error.BadRequestProtoError(unicode(e))

        # Check the request parsed correctly
        if not proto_request.IsInitialized():
            raise error.BadRequestProtoError('Invalid protocol request \
                                              from client')

        return proto_request

    def callMethod(self, service, method, proto_request):
        '''Execute a service method request.'''
        log.debug('Calling service %s' % service)
        log.debug('Calling method %s' % method)

        # Create the controller (initialised to success) and callback
        controller = SocketRpcController()
        callback = Callback()
        try:
            service.CallMethod(method, controller, proto_request, callback)
        except Exception, e:
            raise error.RpcError(unicode(e))