def innerResourceInstanceMethod(*args,**kwargs) : resourceInstance = args[0] completeResponse = None if logRequest : log.prettyJson( resourceInstanceMethod, 'bodyRequest', json.loads(Serializer.jsonifyIt(args[1:])), condition = logRequest, logLevel = log.DEBUG ) try : FlaskManager.validateKwargs( kwargs, resourceInstance, innerResourceInstanceMethod, requestHeaderClass = requestHeaderClass, requestParamClass = requestParamClass ) FlaskManager.validateArgs(args, requestClass, innerResourceInstanceMethod) completeResponse = resourceInstanceMethod(*args,**kwargs) FlaskManager.validateResponseClass(responseClass, completeResponse) except Exception as exception : log.warning(innerResourceInstanceMethod, 'Not posssible to complete request', exception=exception) raise exception controllerResponse = completeResponse[0] if ObjectHelper.isNotNone(completeResponse[0]) else {'message' : completeResponse[1].enumName} if logResponse : log.prettyJson( resourceInstanceMethod, 'bodyResponse', json.loads(Serializer.jsonifyIt(controllerResponse)), condition = logResponse, logLevel = log.DEBUG ) return completeResponse[0]
def innerResourceInstanceMethod(*args, **kwargs): f'''(*args, {FlaskUtil.KW_HEADERS}={{}}, {FlaskUtil.KW_PARAMETERS}={{}}, **kwargs)''' resourceInstance = args[0] clientResponse = None completeResponse = None try : FlaskManager.validateKwargs( kwargs, resourceInstance, resourceInstanceMethod, requestHeaderClass, requestParamClass ) FlaskManager.validateArgs(args, requestClass, resourceInstanceMethod) clientResponse = None httpClientEvent = getHttpClientEvent(resourceInstanceMethod, *args, **kwargs) if isinstance(httpClientEvent, ManualHttpClientEvent): completeResponse = httpClientEvent.completeResponse elif isinstance(httpClientEvent, HttpClientEvent): try : clientResponse = HTTP_CLIENT_RESOLVERS_MAP.get( httpClientEvent.verb, raiseHttpClientEventNotFoundException )( resourceInstance, *httpClientEvent.args, **httpClientEvent.kwargs ) except Exception as exception: raiseException(clientResponse, exception) raiseExceptionIfNeeded(clientResponse) completeResponse = getCompleteResponse(clientResponse, responseClass, produces) FlaskManager.validateCompleteResponse(responseClass, completeResponse) else: raise Exception('Unknown http client event') except Exception as exception: log.log(innerResourceInstanceMethod, 'Failure at client method execution', exception=exception, muteStackTrace=True) FlaskManager.raiseAndPersistGlobalException(exception, resourceInstance, resourceInstanceMethod, context=HttpDomain.CLIENT_CONTEXT) clientResponseStatus = completeResponse[-1] clientResponseHeaders = completeResponse[1] clientResponseBody = completeResponse[0] if ObjectHelper.isNotNone(completeResponse[0]) else {'message' : HttpStatus.map(clientResponseStatus).enumName} if resourceInstance.logResponse or logResponse : log.prettyJson( resourceInstanceMethod, '[CLIENT ] Response', { 'headers': clientResponseHeaders, 'body': Serializer.getObjectAsDictionary(clientResponseBody), 'status': clientResponseStatus }, condition = True, logLevel = log.INFO ) if returnOnlyBody: return completeResponse[0] else: return completeResponse