def _writeFault(self, fail, request): """ fail -- failure request -- request message ex -- Exception """ response = fault.FaultFromException(fail.value, False, fail.tb).AsSOAP() self._writeResponse(response, request, status=500)
def _writeFault(self, request, ex): """ request -- request message ex -- Exception """ response = None response = fault.FaultFromException(ex, False, sys.exc_info()[2]).AsSOAP() log.err('SOAP FAULT: %s' % response) return self._writeResponse(request, response, status=500)
def _handle_POST(self, env, start_response): """Dispatch Method called by twisted render, creates a request/response handler chain. request -- twisted.web.server.Request """ input = env['wsgi.input'] data = input.read(int(env['CONTENT_LENGTH'])) mimeType = "text/xml" if self.encoding is not None: mimeType = 'text/xml; charset="%s"' % self.encoding request = None resource = self.delegate or self chain = self.factory.newInstance() try: pyobj = chain.processRequest(data, request=request, resource=resource) except Exception as ex: start_response("500 ERROR", [('Content-Type', mimeType)]) return [ fault.FaultFromException(ex, False, sys.exc_info()[2]).AsSOAP() ] try: soap = chain.processResponse(pyobj, request=request, resource=resource) except Exception as ex: start_response("500 ERROR", [('Content-Type', mimeType)]) return [ fault.FaultFromException(ex, False, sys.exc_info()[2]).AsSOAP() ] start_response("200 OK", [('Content-Type', mimeType)]) return [soap]
class SOAPApplication(WSGIApplication): """ """ factory = SOAPHandlerChainFactory def __init__(self, **kw): dict.__init__(self, **kw) self.delegate = None def _request_cb(self, env, start_response): """process request, """ if env['REQUEST_METHOD'] == 'GET': return self._handle_GET(env, start_response) if env['REQUEST_METHOD'] == 'POST': return self._handle_POST(env, start_response) start_response("500 ERROR", [('Content-Type', 'text/plain')]) s = StringIO() h = env.items() h.sort() for k, v in h: print >> s, k, '=', ` v ` return [s.getvalue()] def _handle_GET(self, env, start_response): if env['QUERY_STRING'].lower() == 'wsdl': start_response("200 OK", [('Content-Type', 'text/plain')]) r = self.delegate or self return _resourceToWSDL(r) start_response("404 ERROR", [('Content-Type', 'text/plain')]) return ['NO RESOURCE FOR GET'] def _handle_POST(self, env, start_response): """Dispatch Method called by twisted render, creates a request/response handler chain. request -- twisted.web.server.Request """ input = env['wsgi.input'] data = input.read(int(env['CONTENT_LENGTH'])) mimeType = "text/xml" if self.encoding is not None: mimeType = 'text/xml; charset="%s"' % self.encoding request = None resource = self.delegate or self chain = self.factory.newInstance() try: pyobj = chain.processRequest(data, request=request, resource=resource) except Exception, ex: start_response("500 ERROR", [('Content-Type', mimeType)]) return [ fault.FaultFromException(ex, False, sys.exc_info()[2]).AsSOAP() ] try: soap = chain.processResponse(pyobj, request=request, resource=resource) except Exception, ex: start_response("500 ERROR", [('Content-Type', mimeType)]) return [ fault.FaultFromException(ex, False, sys.exc_info()[2]).AsSOAP() ]