async def execute(self): result = '' try: pass except: log(traceback.format_exc()) return result
def __init__(self, url='', method='GET', headers=None, body=None, params=None): try: self.url = url self.method = method self.headers = headers self.body = body self.params = params except: log(traceback.format_exc())
def execute(self): try: service = self.requestDict.get('service', '') serviceModulePath = 'service' + service.replace('/', '.') importedModule = importlib.import_module(serviceModulePath) serviceModuleNames = serviceModulePath.split('.') serviceNameTail = serviceModuleNames[len(serviceModuleNames) - 1] className = serviceNameTail[0].upper() + serviceNameTail[1:] serviceClass = getattr(importedModule, className) self.response = yield from serviceClass(self.requestDict).execute() except: log(traceback.format_exc()) return self.response
async def index(self, request): method = request.method path = request.path requestContentType = request.headers.get('Content-Type') accept = request.headers.get('ACCEPT', 'application/json') acceptEncoding = request.headers.get('ACCEPT-ENCODING') referer = request.headers.get('Referer') responseHeader = multidict.MultiDict( { 'Content-Type': accept, 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Cookie, Accept,X-PINGOTHER', 'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS', 'Access-Control-Max-Age': '3600', 'Access-Control-Allow-Credentials': 'true' }, ) # Check method # if method not in ('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'): # Read, Create, Update, Delete, if method not in ('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'): # Read, Create, Update, Delete, responseBody = '[%s] is not allowed method' % method # Check data type elif method != 'GET' and requestContentType not in ('application/json', 'application/xml', 'text/xml'): responseBody = '[%s] is not allowed Content-Type' % requestContentType # Health check elif path == '/healthCheck': responseBody = '200' # Business logic else: if method == 'GET': parameters = dict(request.GET) else: body = await request.text() requestData = {} if body: requestData = ujson.loads(body) parameters = requestData.get('parameters', {}) # Print request payload log(str(ujson.dumps(parameters))) requestDict = { 'method': method, 'service': path, 'parameters': parameters } # Service response (Business logic) serviceResponse = await serviceHandler( serverInstance=self, requestDict=requestDict).execute() # response responseBody = { 'response': serviceResponse, 'request': requestDict } responseBody = ujson.dumps(responseBody) response = Response(text=responseBody, headers=responseHeader) return response
async def close(self): try: pass except: log(traceback.format_exc())
async def execute(self): try: pass except: log(traceback.format_exc(s))
def __init__(self): try: pass except: log(traceback.format_exc())