예제 #1
0
  def Handle(self, body):
    body = str(body)
    obj = soap.Parse(body)
    request_id = obj.Header.get('ID', None)
    req = obj.Body[0]
    method = req.name
    with soap.Envelope(request_id, None) as xml:
      try:
        responder = self._GetResponder(method)
        result = responder(xml, req)
      except api.SetParameterErrors as e:
        faults = self._ExceptionListToFaultList(e.error_list)
        result = soap.SetParameterValuesFault(xml, faults)
      except KeyError as e:
        result = soap.SimpleFault(
            xml, cpefault=soap.CpeFault.INVALID_PARAM_NAME,
            faultstring='No such parameter: %s' % e.args[0])
      except IndexError as e:
        result = soap.SimpleFault(
            xml, cpefault=soap.CpeFault.INVALID_ARGUMENTS,
            faultstring=str(e))
      except NotImplementedError:
        cpefault = soap.CpeFault.METHOD_NOT_SUPPORTED
        faultstring = 'Unsupported RPC method: %s' % method
        result = soap.SimpleFault(xml, cpefault, faultstring)
      except:
        result = soap.SimpleFault(
            xml, cpefault=soap.CpeFault.INTERNAL_ERROR,
            faultstring=traceback.format_exc())

    if result is not None:
      return xml
    else:
      return None
예제 #2
0
    def Handle(self, body):
        """Dispatch the given XML request to the implementation.

    Args:
      body: the xml string of the request.
    Returns:
      an xml string for the response, or None if no response is expected.
    """
        # Data arriving from tornado web server should be non-decoded utf-8
        body = bytes(body)
        obj = soap.Parse(body)  # decodes as utf-8, via ElementTree
        request_id = obj.Header.get('ID', None)
        req = obj.Body[0]
        method = req.name
        with soap.Envelope(request_id, None) as xml:
            try:
                responder = self._GetResponder(method)
                result = responder(xml, req)
            except api.SetParameterErrors as e:
                faults = self._ExceptionListToFaultList(e.error_list)
                result = soap.SetParameterValuesFault(xml, faults)
            except api.AddObjectsErrors as e:
                faults = self._ExceptionListToFaultList(e.error_list)
                result = soap.AddObjectsFault(xml, faults)
            except api.ParameterNameError as e:
                result = soap.SimpleFault(
                    xml,
                    cpefault=soap.CpeFault.INVALID_PARAM_NAME,
                    faultstring='No such parameter: %s' % unicode(e.parameter))
            except KeyError as e:
                result = soap.SimpleFault(
                    xml,
                    cpefault=soap.CpeFault.INVALID_PARAM_NAME,
                    faultstring='No such parameter: %s' % unicode(e.args[0]))
            except IndexError as e:
                result = soap.SimpleFault(
                    xml,
                    cpefault=soap.CpeFault.INVALID_ARGUMENTS,
                    faultstring=unicode(e))
            except NotImplementedError:
                cpefault = soap.CpeFault.METHOD_NOT_SUPPORTED
                faultstring = 'Unsupported RPC method: %s' % method
                result = soap.SimpleFault(xml, cpefault, faultstring)
            except:  # pylint:disable=bare-except
                result = soap.SimpleFault(
                    xml,
                    cpefault=soap.CpeFault.INTERNAL_ERROR,
                    faultstring=traceback.format_exc())
                traceback.print_exc()

        if result is not None:
            return bytes(xml)  # the utf-8 encoded XML response (pass or fail)
        else:
            return None  # no response generated
예제 #3
0
 def _Envelope(self):
     return soap.Envelope(self.request_id, self.hold_requests)