Example #1
0
 def _checkAction(self, action, value):
     '''WS-Address Action
     action -- Action value expecting.
     value  -- Action value server returned.
     '''
     if action is None:
         raise WSActionException('Response missing WSAddress Action')
     if not value:
         raise WSActionException('missing WSAddress Action, expecting %s' %action)
     if value != action:
         raise WSActionException('wrong WSAddress Action(%s), expecting %s'%(value,action))
Example #2
0
    def _getWSAddressTypeCodes(self, **kw):
        '''kw -- namespaceURI keys with sequence of element names.
        '''
        typecodes = []
        try:
            for nsuri,elements in list(kw.items()):
                for el in elements:
                    typecode = GED(nsuri, el)
                    if typecode is None:
                        raise WSActionException('Missing namespace, import "%s"' %nsuri)

                    typecodes.append(typecode)
            else:
                pass
        except EvaluateException as ex:
            raise EvaluateException('To use ws-addressing register typecodes for namespace(%s)' %self.wsAddressURI)
        return typecodes
Example #3
0
    def _checkFrom(self, pyobj):
        '''WS-Address From,
        XXX currently not checking the hostname, not forwarding messages.
        pyobj  -- From server returned.
        '''
        if pyobj is None: return
        value = pyobj._Address
        if value != self._addressTo:
            scheme,netloc,path,query,fragment = urlparse.urlsplit(value)
            schemeF,netlocF,pathF,queryF,fragmentF = urlparse.urlsplit(self._addressTo)
            if scheme==schemeF and path==pathF and query==queryF and fragment==fragmentF:
                netloc = netloc.split(':') + ['80']
                netlocF = netlocF.split(':') + ['80']
                if netloc[1]==netlocF[1] and (socket.gethostbyname(netlocF[0]) in
                    ('127.0.0.1', socket.gethostbyname(netloc[0]))):
                    return

            raise WSActionException('wrong WS-Address From(%s), expecting %s'%(value,self._addressTo))
Example #4
0
    def Send(self,
             url,
             opname,
             obj,
             nsdict={},
             soapaction=None,
             wsaction=None,
             endPointReference=None,
             soapheaders=(),
             **kw):
        '''Send a message.  If url is None, use the value from the
        constructor (else error). obj is the object (data) to send.
        Data may be described with a requesttypecode keyword, the default 
        is the class's typecode (if there is one), else Any.

        Try to serialize as a Struct, if this is not possible serialize an Array.  If 
        data is a sequence of built-in python data types, it will be serialized as an
        Array, unless requesttypecode is specified.

        arguments:
            url -- 
            opname -- struct wrapper
            obj -- python instance

        key word arguments:
            nsdict -- 
            soapaction --
            wsaction -- WS-Address Action, goes in SOAP Header.
            endPointReference --  set by calling party, must be an 
                EndPointReference type instance.
            soapheaders -- list of pyobj, typically w/typecode attribute.
                serialized in the SOAP:Header.
            requesttypecode -- 

        '''
        url = url or self.url
        endPointReference = endPointReference or self.endPointReference

        # Serialize the object.
        d = {}
        d.update(self.nsdict)
        d.update(nsdict)

        sw = SoapWriter(
            nsdict=d,
            header=True,
            outputclass=self.writerclass,
            encodingStyle=kw.get('encodingStyle'),
        )

        requesttypecode = kw.get('requesttypecode')
        if '_args' in kw:  #NamedParamBinding
            tc = requesttypecode or TC.Any(pname=opname, aslist=False)
            sw.serialize(kw['_args'], tc)
        elif not requesttypecode:
            tc = getattr(obj, 'typecode', None) or TC.Any(pname=opname,
                                                          aslist=False)
            try:
                if type(obj) in _seqtypes:
                    obj = dict([(i.typecode.pname, i) for i in obj])
            except AttributeError:
                # can't do anything but serialize this in a SOAP:Array
                tc = TC.Any(pname=opname, aslist=True)
            else:
                tc = TC.Any(pname=opname, aslist=False)

            sw.serialize(obj, tc)
        else:
            sw.serialize(obj, requesttypecode)

        for i in soapheaders:
            sw.serialize_header(i)

        #
        # Determine the SOAP auth element.  SOAP:Header element
        if self.auth_style & AUTH.zsibasic:
            sw.serialize_header(_AuthHeader(self.auth_user, self.auth_pass),
                                _AuthHeader.typecode)

        #
        # Serialize WS-Address
        if self.wsAddressURI is not None:
            if self.soapaction and wsaction.strip('\'"') != self.soapaction:
                raise WSActionException('soapAction(%s) and WS-Action(%s) must match'\
                    %(self.soapaction,wsaction))

            self.address = Address(url, self.wsAddressURI)
            self.address.setRequest(endPointReference, wsaction)
            self.address.serialize(sw)

        #
        # WS-Security Signature Handler
        if self.sig_handler is not None:
            self.sig_handler.sign(sw)

        scheme, netloc, path, nil, nil, nil = urllib.parse.urlparse(url)
        transport = self.transport
        if transport is None and url is not None:
            if scheme == 'https':
                transport = self.defaultHttpsTransport
            elif scheme == 'http':
                transport = self.defaultHttpTransport
            else:
                raise RuntimeError(
                    'must specify transport or url startswith https/http')

        # Send the request.
        if issubclass(transport, http.client.HTTPConnection) is False:
            raise TypeError('transport must be a HTTPConnection')

        soapdata = str(sw)
        self.h = transport(netloc, None, **self.transdict)
        self.h.connect()
        self.SendSOAPData(soapdata, url, soapaction, **kw)
Example #5
0
 def _checkReplyTo(self, value):
     '''WS-Address From
     value  -- From server returned in wsa:To
     '''
     if value != self._replyTo:
         raise WSActionException('wrong WS-Address ReplyTo(%s), expecting %s'%(value,self._replyTo))
Example #6
0
 def _checkRelatesTo(self, value):
     '''WS-Address From
     value  -- From server returned.
     '''
     if value != self._messageID:
         raise WSActionException('wrong WS-Address RelatesTo(%s), expecting %s'%(value,self._messageID))