def __call__(self, req_env, start_response, wsgi_url=None): """ This method conforms to the WSGI spec for callable wsgi applications (PEP 333). It looks in environ['wsgi.input'] for a fully formed soap request envelope, will deserialize the request parameters and call the method on the object returned by the get_handler() method. @param the http environment @param a callable that begins the response message @param the optional url @returns the string representation of the soap call """ url = wsgi_url if url is None: url = reconstruct_url(req_env).split(".wsdl")[0] if self.__is_wsdl_request(req_env): return self.__handle_wsdl_request(req_env, start_response, url) elif req_env["REQUEST_METHOD"].lower() != "post": start_response(HTTP_405, [("Allow", "POST")]) return [""] else: return self.__handle_soap_request(req_env, start_response)
def __call__(self, req_env, start_response, wsgi_url=None): ''' This method conforms to the WSGI spec for callable wsgi applications (PEP 333). It looks in environ['wsgi.input'] for a fully formed soap request envelope, will deserialize the request parameters and call the method on the object returned by the get_handler() method. @param the http environment @param a callable that begins the response message @param the optional url @returns the string representation of the soap call ''' url = wsgi_url if url is None: url = reconstruct_url(req_env).split('.wsdl')[0] if self.__is_wsdl_request(req_env): return self.__handle_wsdl_request(req_env, start_response, url) else: return self.__handle_soap_request(req_env, start_response, url)
def __call__(self, environ, start_response, address_url=None): ''' This method conforms to the WSGI spec for callable wsgi applications (PEP 333). It looks in environ['wsgi.input'] for a fully formed soap request envelope, will deserialize the request parameters and call the method on the object returned by the getHandler() method. @param the http environment @param a callable that begins the response message @returns the string representation of the soap call ''' methodname = '' try: reset_request() request.environ = environ # implementation hook self.onCall(environ) serviceName = environ['PATH_INFO'].split('/')[-1] service = self.getHandler(environ) if ((environ['QUERY_STRING'].endswith('wsdl') or environ['PATH_INFO'].endswith('wsdl')) and environ['REQUEST_METHOD'].lower() == 'get'): # get the wsdl for the service # # Assume path_info matches pattern # /stuff/stuff/stuff/serviceName.wsdl or ?WSDL # serviceName = serviceName.split('.')[0] if address_url: url = address_url else: url = reconstruct_url(environ).split('.wsdl')[0] start_response('200 OK', [('Content-type', 'text/xml')]) try: wsdl_content = service.wsdl(url) # implementation hook self.onWsdl(environ, wsdl_content) except Exception, e: # implementation hook buffer = cStringIO.StringIO() traceback.print_exc(file=buffer) buffer.seek(0) stacktrace = str(buffer.read()) faultStr = ElementTree.tostring(make_soap_fault(str(e), detail=stacktrace), encoding=string_encoding) exceptions(faultStr) self.onWsdlException(environ, e, faultStr) # initiate the response start_response('500 Internal Server Error', [('Content-type', 'text/xml'), ('Content-length', str(len(faultStr)))]) return [faultStr] reset_request() return [wsdl_content] if environ['REQUEST_METHOD'].lower() != 'post': start_response('405 Method Not Allowed', [('Allow', 'POST')]) return '' input = environ.get('wsgi.input') length = environ.get("CONTENT_LENGTH") body = input.read(int(length)) methodname = environ.get("HTTP_SOAPACTION") debug('\033[92m'+ methodname +'\033[0m') debug(body) body = collapse_swa(environ.get("CONTENT_TYPE"), body) # deserialize the body of the message try: payload, header = from_soap(body) except SyntaxError, e: payload = None header = None
def __call__(self, environ, start_response, address_url=None): ''' This method conforms to the WSGI spec for callable wsgi applications (PEP 333). It looks in environ['wsgi.input'] for a fully formed soap request envelope, will deserialize the request parameters and call the method on the object returned by the getHandler() method. @param the http environment @param a callable that begins the response message @returns the string representation of the soap call ''' methodname = '' try: reset_request() request.environ = environ # implementation hook self.onCall(environ) serviceName = environ['PATH_INFO'].split('/')[-1] service = self.getHandler(environ) if ((environ['QUERY_STRING'].endswith('wsdl') or environ['PATH_INFO'].endswith('wsdl')) and environ['REQUEST_METHOD'].lower() == 'get'): # get the wsdl for the service # # Assume path_info matches pattern # /stuff/stuff/stuff/serviceName.wsdl or ?WSDL # serviceName = serviceName.split('.')[0] if address_url: url = address_url else: url = reconstruct_url(environ).split('.wsdl')[0] start_response('200 OK', [('Content-type', 'text/xml')]) try: wsdl_content = service.wsdl(url) # implementation hook self.onWsdl(environ, wsdl_content) except Exception, e: # implementation hook buffer = cStringIO.StringIO() traceback.print_exc(file=buffer) buffer.seek(0) stacktrace = str(buffer.read()) faultStr = ElementTree.tostring(make_soap_fault( str(e), detail=stacktrace), encoding=string_encoding) exceptions(faultStr) self.onWsdlException(environ, e, faultStr) # initiate the response start_response('500', [('Content-type', 'text/xml'), ('Content-length', str(len(faultStr)))]) return [faultStr] reset_request() return [wsdl_content] if environ['REQUEST_METHOD'].lower() != 'post': start_response('405 Method Not Allowed', [('Allow', 'POST')]) return '' input = environ.get('wsgi.input') length = environ.get("CONTENT_LENGTH") body = input.read(int(length)) debug(body) body = collapse_swa(environ.get("CONTENT_TYPE"), body) # deserialize the body of the message try: payload, header = from_soap(body) except SyntaxError, e: payload = None header = None
def __call__(self, environ, start_response): ''' This method conforms to the WSGI spec for callable wsgi applications (PEP 333). This method looks in environ['wsgi.input'] for a fully formed soap request envelope, will deserialize the request parameters and call the method on the object returned by the getHandler() method. @param the http environment @param a callable that begins the response message @returns the string representation of the soap call ''' methodname = '' try: reset_request() request.environ = environ # implementation hook self.onCall(environ) serviceName = environ['PATH_INFO'].split('/')[-1] service = self.getHandler(environ) if serviceName.lower().endswith('wsdl'): # get the wsdl for the service # # Assume path_info matches pattern # /stuff/stuff/stuff/serviceName.wsdl or ?WSDL # serviceName = serviceName.split('.')[0] url = reconstruct_url(environ).split('.wsdl')[0] start_response('200 OK',[('Content-type','text/xml')]) try: wsdl_content = service.wsdl(url) # implementation hook self.onWsdl(environ,wsdl_content) except Exception, e: # implementation hook buffer = cStringIO.StringIO() traceback.print_exc(file=buffer) buffer.seek(0) stacktrace = str(buffer.read()) faultStr = ElementTree.tostring(make_soap_fault( str(e), detail=stacktrace), encoding=string_encoding) exceptions(faultStr) self.onWsdlException(environ,e,faultStr) # initiate the response start_response('500',[('Content-type','text/xml'),('Content-length',str(len(faultStr)))]) return [faultStr] reset_request() return [wsdl_content] if environ['REQUEST_METHOD'].lower() != 'post': start_response('405 Method Not Allowed',[('Allow','POST')]) return '' input = environ.get('wsgi.input') length = environ.get("CONTENT_LENGTH") body = input.read(int(length)) debug(body) body = collapse_swa( environ.get("CONTENT_TYPE"), body) # deserialize the body of the message payload, header = from_soap(body) if payload: methodname = payload.tag.split('}')[-1] else: # check HTTP_SOAPACTION methodname = environ.get("HTTP_SOAPACTION") if methodname.startswith('"') and methodname.endswith('"'): methodname = methodname[1:-1] request.header = header # call the method func = getattr(service, methodname) # retrieve the method descriptor descriptor = func(_soap_descriptor=True) if payload: params = descriptor.inMessage.from_xml(*[payload]) else: params = () # implementation hook self.onMethodExec(environ,body,params,descriptor.inMessage.params) # call the method retval = func(*params) # transform the results into an element # only expect a single element results = None if not (descriptor.isAsync or descriptor.isCallback): results = descriptor.outMessage.to_xml(*[retval]) # implementation hook self.onResults(environ,results,retval) # grab any headers that were included in the request response_headers = None if hasattr(request,'response_headers'): response_headers = request.response_headers # construct the soap response, and serialize it envelope = make_soap_envelope(results,tns=service.__tns__,header_elements=response_headers) resp = ElementTree.tostring(envelope, encoding=string_encoding) headers = {'Content-Type': 'text/xml'} if descriptor.mtom: headers, resp = apply_mtom( headers, resp, descriptor.outMessage.params, (retval,) ) if environ.has_key('CONTENT_LENGTH'): del(environ['CONTENT_LENGTH']) # initiate the response start_response('200 OK',headers.items()) self.onReturn(environ,resp) debug(resp) # return the serialized results reset_request() return [resp]
def __call__(self, environ, start_response): ''' This method conforms to the WSGI spec for callable wsgi applications (PEP 333). This method looks in environ['wsgi.input'] for a fully formed soap request envelope, will deserialize the request parameters and call the method on the object returned by the getHandler() method. @param the http environment @param a callable that begins the response message @returns the string representation of the soap call ''' methodname = '' try: reset_request() request.environ = environ # implementation hook self.onCall(environ) serviceName = environ['PATH_INFO'].split('/')[-1] service = self.getHandler(environ) if serviceName.lower().endswith('wsdl'): # get the wsdl for the service # # Assume path_info matches pattern # /stuff/stuff/stuff/serviceName.wsdl or ?WSDL # serviceName = serviceName.split('.')[0] url = reconstruct_url(environ).split('.wsdl')[0] start_response('200 OK',[('Content-type','text/xml')]) try: wsdl_content = service.wsdl(url) # implementation hook self.onWsdl(environ,wsdl_content) except Exception, e: # implementation hook buffer = cStringIO.StringIO() traceback.print_exc(file=buffer) buffer.seek(0) stacktrace = str(buffer.read()) faultStr = ElementTree.tostring(make_soap_fault( str(e), detail=stacktrace), encoding=string_encoding) exceptions(faultStr) self.onWsdlException(environ,e,faultStr) # initiate the response start_response('500',[('Content-type','text/xml'),('Content-length',str(len(faultStr)))]) return [faultStr] reset_request() return [wsdl_content] if environ['REQUEST_METHOD'].lower() != 'post': start_response('405 Method Not Allowed',[('Allow','POST')]) return '' input = environ.get('wsgi.input') length = environ.get("CONTENT_LENGTH") body = input.read(int(length)) debug(body) body = collapse_swa( environ.get("CONTENT_TYPE"), body) # deserialize the body of the message payload, header = from_soap(body) methodname = payload.tag.split('}')[-1] request.header = header # call the method func = getattr(service, methodname) # retrieve the method descriptor descriptor = func(_soap_descriptor=True) params = descriptor.inMessage.from_xml(*[payload]) # implementation hook self.onMethodExec(environ,body,params,descriptor.inMessage.params) # call the method retval = func(*params) # transform the results into an element # only expect a single element results = None if not (descriptor.isAsync or descriptor.isCallback): results = descriptor.outMessage.to_xml(*[retval]) # implementation hook self.onResults(environ,results,retval) # grab any headers that were included in the request response_headers = None if hasattr(request,'response_headers'): response_headers = request.response_headers # construct the soap response, and serialize it envelope = make_soap_envelope(results,tns=service.__tns__,header_elements=response_headers) resp = ElementTree.tostring(envelope, encoding=string_encoding) headers = {'Content-Type': 'text/xml'} if descriptor.mtom: headers, resp = apply_mtom( headers, resp, descriptor.outMessage.params, (retval,) ) if environ.has_key('CONTENT_LENGTH'): del(environ['CONTENT_LENGTH']) # initiate the response start_response('200 OK',headers.items()) self.onReturn(environ,resp) debug(resp) # return the serialized results reset_request() return [resp]
def post(self): ''' This method conforms to the WSGI spec for callable wsgi applications (PEP 333). This method looks in environ['wsgi.input'] for a fully formed soap request envelope, will deserialize the request parameters and call the method on the object returned by the getHandler() method. @param the http environment @param a callable that begins the response message @returns the string representation of the soap call ''' methodname = '' container = tornado.wsgi.WSGIContainer(self.application) environ = container.environ(self.request) try: # implementation hook self.onCall(environ) serviceName = environ['PATH_INFO'].split('/')[-1] service = self.getHandler(environ) if (environ['QUERY_STRING'].endswith('wsdl') or environ['PATH_INFO'].endswith('wsdl') ) and environ['REQUEST_METHOD'].lower() == 'get': # get the wsdl for the service # # Assume path_info matches pattern # /stuff/stuff/stuff/serviceName.wsdl or ?WSDL # serviceName = serviceName.split('.')[0] url = reconstruct_url(environ).split('.wsdl')[0] try: wsdl_content = service.wsdl(url) # implementation hook self.onWsdl(environ, wsdl_content) except Exception, e: # implementation hook buffer = cStringIO.StringIO() traceback.print_exc(file=buffer) buffer.seek(0) stacktrace = str(buffer.read()) faultStr = ElementTree.tostring(make_soap_fault( str(e), detail=stacktrace), encoding=string_encoding) exceptions(faultStr) self.onWsdlException(environ, e, faultStr) # initiate the response #return Response(faultStr, '500 Internal Server Error', [('Content-type','text/xml;charset=utf-8')]) self.set_header('Content-Type', 'text/xml;charset=utf-8') return self.write(faultStr) #return Response(wsdl_content, '200 OK', [('Content-type','text/xml;charset=utf-8')]) self.set_header('Content-Type', 'text/xml;charset=utf-8') return self.write(wsdl_content) if environ['REQUEST_METHOD'].lower() != 'post': #return Response('', '405 Method Not Allowed',[('Allow','POST')]) self.set_header('Content-Type', 'text/html;charset=utf-8') return self.write_error(status_code=405) input = environ.get('wsgi.input') length = environ.get("CONTENT_LENGTH") body = input.read(int(length)) debug(body) # body, _unmentioned_attachs = collapse_swa( environ.get("CONTENT_TYPE"), body) # collapse_swa has some problem try: body, _unmentioned_attachs = collapse_swa( environ.get("CONTENT_TYPE"), body) except: body = collapse_swa(environ.get("CONTENT_TYPE"), body) _unmentioned_attachs = [] pass # deserialize the body of the message try: payload, header = from_soap(body) except SyntaxError, e: payload = None header = None
def post(self): ''' This method conforms to the WSGI spec for callable wsgi applications (PEP 333). This method looks in environ['wsgi.input'] for a fully formed soap request envelope, will deserialize the request parameters and call the method on the object returned by the getHandler() method. @param the http environment @param a callable that begins the response message @returns the string representation of the soap call ''' methodname = '' container = tornado.wsgi.WSGIContainer(self.application) environ = container.environ(self.request) try: # implementation hook self.onCall(environ) serviceName = environ['PATH_INFO'].split('/')[-1] service = self.getHandler(environ) if (environ['QUERY_STRING'].endswith('wsdl') or environ['PATH_INFO'].endswith('wsdl')) and environ['REQUEST_METHOD'].lower() == 'get': # get the wsdl for the service # # Assume path_info matches pattern # /stuff/stuff/stuff/serviceName.wsdl or ?WSDL # serviceName = serviceName.split('.')[0] url = reconstruct_url(environ).split('.wsdl')[0] try: wsdl_content = service.wsdl(url) # implementation hook self.onWsdl(environ,wsdl_content) except Exception, e: # implementation hook buffer = cStringIO.StringIO() traceback.print_exc(file=buffer) buffer.seek(0) stacktrace = str(buffer.read()) faultStr = ElementTree.tostring(make_soap_fault( str(e), detail=stacktrace), encoding=string_encoding) exceptions(faultStr) self.onWsdlException(environ,e,faultStr) # initiate the response #return Response(faultStr, '500 Internal Server Error', [('Content-type','text/xml;charset=utf-8')]) self.set_header('Content-Type', 'text/xml;charset=utf-8') return self.write(faultStr) #return Response(wsdl_content, '200 OK', [('Content-type','text/xml;charset=utf-8')]) self.set_header('Content-Type', 'text/xml;charset=utf-8') return self.write(wsdl_content) if environ['REQUEST_METHOD'].lower() != 'post': #return Response('', '405 Method Not Allowed',[('Allow','POST')]) self.set_header('Content-Type', 'text/html;charset=utf-8') return self.write_error(status_code=405) input = environ.get('wsgi.input') length = environ.get("CONTENT_LENGTH") body = input.read(int(length)) debug(body) # body, _unmentioned_attachs = collapse_swa( environ.get("CONTENT_TYPE"), body) # collapse_swa has some problem try: body, _unmentioned_attachs = collapse_swa( environ.get("CONTENT_TYPE"), body) except: body = collapse_swa( environ.get("CONTENT_TYPE"), body) _unmentioned_attachs = [] pass # deserialize the body of the message try: payload, header = from_soap(body) except SyntaxError,e: payload = None header = None