示例#1
0
 def test_portypes(self):
     app = Application([TestService], 'tns')
     _wsdl = app.get_wsdl('')
     wsdl = etree.fromstring(_wsdl)
     porttype = wsdl.find('{http://schemas.xmlsoap.org/wsdl/}portType')
     srv = TestService()
     self.assertEquals(
         len(srv.public_methods), len(porttype.getchildren()))
示例#2
0
    def test_multiple_return(self):
        app = Application([MultipleReturnService], 'tns')
        app.get_wsdl('')
        srv = MultipleReturnService()
        message = srv.public_methods[0].out_message()

        self.assertEquals(len(message._type_info), 3)

        sent_xml = etree.Element('test')
        message.to_parent_element( ('a','b','c'), srv.get_tns(), sent_xml )
        sent_xml = sent_xml[0]

        response_data = message.from_xml(sent_xml)

        self.assertEquals(len(response_data), 3)
        self.assertEqual(response_data[0], 'a')
        self.assertEqual(response_data[1], 'b')
        self.assertEqual(response_data[2], 'c')
示例#3
0
    def test_wsdl(self):
        app = Application([TestService],'tns')
        wsdl = app.get_wsdl('punk')
        elt = etree.fromstring(wsdl)
        simple_type = elt.xpath('//xs:simpleType', namespaces=app.nsmap)[0]

        # Avoid printing debug output during test runs.
        #print etree.tostring(elt, pretty_print=True)
        #print simple_type

        self.assertEquals(simple_type.attrib['name'], 'DaysOfWeekEnum')
        self.assertEquals(simple_type[0].tag, "{%s}restriction" % namespaces.ns_xsd)
        self.assertEquals([e.attrib['value'] for e in simple_type[0]], vals)
示例#4
0
    def test_wsdl(self):
        app = Application([TestService], 'tns')
        wsdl = app.get_wsdl('punk')
        elt = etree.fromstring(wsdl)
        simple_type = elt.xpath('//xs:simpleType', namespaces=app.nsmap)[0]

        # Avoid printing debug output during test runs.
        #print etree.tostring(elt, pretty_print=True)
        #print simple_type

        self.assertEquals(simple_type.attrib['name'], 'DaysOfWeekEnum')
        self.assertEquals(simple_type[0].tag,
                          "{%s}restriction" % namespaces.ns_xsd)
        self.assertEquals([e.attrib['value'] for e in simple_type[0]], vals)
示例#5
0
文件: zope2.py 项目: PArun/soaplib
class SoapFolder(DefinitionBase):
    """Mix-In Class to Make a Folder into a SOAP Service Point

    Import this class into your Zope2 folder classes to make them SOAP-aware.
    Any methods in your folder class decorated with @soapmethod() will become
    callable over SOAP and the signature and docstring of that method will be
    reported as WSDL by a call to the index_html() method of that folder.

    Your class should also define a class attribute indicating the 'toplevel
    namespace' of your SOAP Service Point.  This name is arbitrary as far as
    this code goes, but appears in the SOAP response and the WSDL description
    generated.  This attribute looks like:   __tns__ = "PatientServices"
    """

    _v_soap_methods = None
    _v_cached_wsdl = None
    __wsdl__ = None


    def __init__(self, tns, environ=None):
        super(DefinitionBase, self).__init__(environ)
        self.soap_app = Application(self, tns, False)
        self.soap_handler = BaseServer(self.soap_app)


    def methods(self):
        """Returns a list of method descriptors for this object"""
        if self._v_soap_methods is None:
            self._v_soap_methods = self.build_public_methods()
        return self._v_soap_methods


    def service_description(self, REQUEST, RESPONSE):
        """ """

        if getattr(self, '__tns__', None) is None:
            self.__tns__ = self.get_tns(self.__class__)

        if self._v_soap_methods is None:
            self._v_soap_methods = self.build_public_methods()

        if self._v_cached_wsdl is None:
            self._v_cached_wsdl = self.soap_app.get_wsdl(self.absolute_url())
            self.__wsdl__ = None

        RESPONSE.setHeader('Content-Type', 'text/xml')
        return self._v_cached_wsdl

    def index_html(self, REQUEST, RESPONSE):
        """Handle an incoming SOAP request or a non-SOAP WSDL query."""

        if REQUEST.get('SOAPXML', None) == None:  # Not a SOAP Request, return WSDL
            return self.service_description(REQUEST, RESPONSE)

        try:
            # Deserialize the Body of the SOAP Request
            from soaplib.core._base import _from_soap
            header, payload = _from_soap(REQUEST.SOAPXML)

            # TODO: At this point I need dispatch method calls to the soaplib.Application
            # somehow....... :)
            ctx = MethodContext()

            content_type  = cgi.parse_header(REQUEST.get("Content-Type"))
            charset = content_type[1].get('charset',None)
            length = REQUEST.get("Content-Length")
            http_payload = REQUEST.read(int(length))

            if not charset:
                charset = "ascii"

            in_string = collapse_swa(content_type, http_payload)
            in_obj = self.soap_handler.get_in_object(ctx, in_string, charset)
            out_obj = self.soap_handler.get_out_object(ctx, in_obj)
            out_string = self.soap_handler.get_out_string(ctx, out_obj)
            
            return out_string

        except Exception, e:

            fault = Fault(faultstring=str(e))
            resp = etree.tostring(fault, encoding=string_encoding)

            RESPONSE.setStatus('InternalServerError', reason=faultstring)
            RESPONSE.setHeader('Content-Type', 'text/xml')
            return resp
示例#6
0
 def test_multiple_ns(self):
     svc = Application([MultipleNamespaceService], 'tns')
     wsdl = svc.get_wsdl("URL")
示例#7
0
 def test_override_param_names(self):
     app = Application([TestService], 'tns')
     _wsdl = app.get_wsdl('')
     for n in ['self', 'import', 'return', 'from']:
         self.assertTrue(n in _wsdl, '"%s" not in _wsdl' % n)
示例#8
0
class SoapFolder(DefinitionBase):
    """Mix-In Class to Make a Folder into a SOAP Service Point

    Import this class into your Zope2 folder classes to make them SOAP-aware.
    Any methods in your folder class decorated with @soapmethod() will become
    callable over SOAP and the signature and docstring of that method will be
    reported as WSDL by a call to the index_html() method of that folder.

    Your class should also define a class attribute indicating the 'toplevel
    namespace' of your SOAP Service Point.  This name is arbitrary as far as
    this code goes, but appears in the SOAP response and the WSDL description
    generated.  This attribute looks like:   __tns__ = "PatientServices"
    """

    _v_soap_methods = None
    _v_cached_wsdl = None
    __wsdl__ = None

    def __init__(self, tns, environ=None):
        super(DefinitionBase, self).__init__(environ)
        self.soap_app = Application(self, tns, False)
        self.soap_handler = BaseServer(self.soap_app)

    def methods(self):
        """Returns a list of method descriptors for this object"""
        if self._v_soap_methods is None:
            self._v_soap_methods = self.build_public_methods()
        return self._v_soap_methods

    def service_description(self, REQUEST, RESPONSE):
        """ """

        if getattr(self, '__tns__', None) is None:
            self.__tns__ = self.get_tns(self.__class__)

        if self._v_soap_methods is None:
            self._v_soap_methods = self.build_public_methods()

        if self._v_cached_wsdl is None:
            self._v_cached_wsdl = self.soap_app.get_wsdl(self.absolute_url())
            self.__wsdl__ = None

        RESPONSE.setHeader('Content-Type', 'text/xml')
        return self._v_cached_wsdl

    def index_html(self, REQUEST, RESPONSE):
        """Handle an incoming SOAP request or a non-SOAP WSDL query."""

        if REQUEST.get('SOAPXML',
                       None) == None:  # Not a SOAP Request, return WSDL
            return self.service_description(REQUEST, RESPONSE)

        try:
            # Deserialize the Body of the SOAP Request
            from soaplib.core._base import _from_soap
            header, payload = _from_soap(REQUEST.SOAPXML)

            # TODO: At this point I need dispatch method calls to the soaplib.Application
            # somehow....... :)
            ctx = MethodContext()

            content_type = cgi.parse_header(REQUEST.get("Content-Type"))
            charset = content_type[1].get('charset', None)
            length = REQUEST.get("Content-Length")
            http_payload = REQUEST.read(int(length))

            if not charset:
                charset = "ascii"

            in_string = collapse_swa(content_type, http_payload)
            in_obj = self.soap_handler.get_in_object(ctx, in_string, charset)
            out_obj = self.soap_handler.get_out_object(ctx, in_obj)
            out_string = self.soap_handler.get_out_string(ctx, out_obj)

            return out_string

        except Exception, e:

            fault = Fault(faultstring=str(e))
            resp = etree.tostring(fault, encoding=string_encoding)

            RESPONSE.setStatus('InternalServerError', reason=faultstring)
            RESPONSE.setHeader('Content-Type', 'text/xml')
            return resp