Exemplo n.º 1
0
    def setRequest(self, endPointReference, action):
        '''Call For Request
        '''
        self._action = action
        self.header_pyobjs = None
        pyobjs = []
        namespaceURI = self.wsAddressURI
        addressTo = self._addressTo
        messageID = self._messageID = "uuid:%s" % time.time()

        # Set Message Information Headers
        # MessageID
        typecode = GED(namespaceURI, "MessageID")
        pyobjs.append(typecode.pyclass(messageID))

        # Action
        typecode = GED(namespaceURI, "Action")
        pyobjs.append(typecode.pyclass(action))

        # To
        typecode = GED(namespaceURI, "To")
        pyobjs.append(typecode.pyclass(addressTo))

        # From
        typecode = GED(namespaceURI, "From")
        mihFrom = typecode.pyclass()
        mihFrom._Address = self.anonymousURI
        pyobjs.append(mihFrom)

        if endPointReference:
            if hasattr(endPointReference, 'typecode') is False:
                raise EvaluateException(
                    'endPointReference must have a typecode attribute')

            if isinstance(endPointReference.typecode, \
                GTD(namespaceURI ,'EndpointReferenceType')) is False:
                raise EvaluateException(
                    'endPointReference must be of type %s' %
                    GTD(namespaceURI, 'EndpointReferenceType'))

            ReferenceProperties = getattr(endPointReference,
                                          '_ReferenceProperties', None)
            if ReferenceProperties is None:  # In recent WS-A attribute name changed
                ReferenceProperties = getattr(endPointReference,
                                              '_ReferenceParameters', None)
            if ReferenceProperties is not None:
                for v in getattr(ReferenceProperties, '_any', ()):
                    if not hasattr(v, 'typecode'):
                        raise EvaluateException(
                            '<any> element, instance missing typecode attribute'
                        )

                    pyobjs.append(v)

        self.header_pyobjs = tuple(pyobjs)
Exemplo n.º 2
0
    def setResponseFromWSAddress(self, address, localURL):
        '''Server-side has to set these fields in response.
        address -- Address instance, representing a WS-Address
        '''
        self.From = localURL
        self.header_pyobjs = None
        pyobjs = []
        namespaceURI = self.wsAddressURI

        for nsuri,name,value in (\
             (namespaceURI, "Action", self._action),
             (namespaceURI, "MessageID","uuid:%s" %time.time()),
             (namespaceURI, "RelatesTo", address.getMessageID()),
             (namespaceURI, "To", self.anonymousURI),):

            typecode = GED(nsuri, name)
            pyobjs.append(typecode.pyclass(value))

        typecode = GED(nsuri, "From")
        pyobj = typecode.pyclass()
        pyobj._Address = self.From
        pyobjs.append(pyobj)
        self.header_pyobjs = tuple(pyobjs)
Exemplo n.º 3
0
        def call_closure(*args, **kwargs):
            """Call the named remote web service method."""
            if len(args) and len(kwargs):
                raise TypeError, 'Use positional or keyword argument only.'
                
            if len(args) > 0:
                raise TypeError, 'Not supporting SOAPENC:Arrays or XSD:List'
            
            if len(kwargs): 
                args = kwargs

            callinfo = getattr(self, name).callinfo
    
            # go through the list of defined methods, and look for the one with
            # the same number of arguments as what was passed.  this is a weak
            # check that should probably be improved in the future to check the
            # types of the arguments to allow for polymorphism
            for method in self._methods[name]:
                if len(method.callinfo.inparams) == len(kwargs):
                    callinfo = method.callinfo
    
            binding = _Binding(url=self._url or callinfo.location,
                              soapaction=callinfo.soapAction,
                              **self._kw)
    
            kw = dict(unique=True)
            if callinfo.use == 'encoded':
                kw['unique'] = False
    
            if callinfo.style == 'rpc':
                request = TC.Struct(None, ofwhat=[], 
                                 pname=(callinfo.namespace, name), **kw)
                
                response = TC.Struct(None, ofwhat=[], 
                                 pname=(callinfo.namespace, name+"Response"), **kw)
                
                if len(callinfo.getInParameters()) != len(args):
                    raise RuntimeError('expecting "%s" parts, got %s' %(
                           str(callinfo.getInParameters(), str(args))))
                
                for msg,pms in ((request,callinfo.getInParameters()), 
                                (response,callinfo.getOutParameters())):
                    msg.ofwhat = []
                    for part in pms:
                        klass = GTD(*part.type)
                        if klass is None:
                            if part.type:
                                klass = filter(lambda gt: part.type==gt.type,TC.TYPES)
                                if len(klass) == 0:
                                    klass = filter(lambda gt: part.type[1]==gt.type[1],TC.TYPES)
                                    if not len(klass):klass = [TC.Any]
                                if len(klass) > 1: #Enumerations, XMLString, etc
                                    klass = filter(lambda i: i.__dict__.has_key('type'), klass)
                                klass = klass[0]
                            else:
                                klass = TC.Any
                    
                        msg.ofwhat.append(klass(part.name))
                        
                    msg.ofwhat = tuple(msg.ofwhat)
                if not args: args = {}
            else:
                # Grab <part element> attribute
                ipart,opart = callinfo.getInParameters(),callinfo.getOutParameters()
                if ( len(ipart) != 1 or not ipart[0].element_type or 
                    ipart[0].type is None ):
                    raise RuntimeError, 'Bad Input Message "%s"' %callinfo.name
        
                if ( len(opart) not in (0,1) or not opart[0].element_type or 
                    opart[0].type is None ):
                    raise RuntimeError, 'Bad Output Message "%s"' %callinfo.name
                
#                if ( len(args) > 1 ):
#                    raise RuntimeError, 'Message has only one part:  %s' %str(args)
                
                ipart = ipart[0]
                request,response = GED(*ipart.type),None
                if opart: response = GED(*opart[0].type)
    
            msg = args
            if self._asdict: 
                if not msg: msg = dict()
                self._nullpyclass(request)
            elif request.pyclass is not None:
                if type(args) is dict:
                    msg = request.pyclass()
                    msg.__dict__.update(args)
                elif type(args) is list and len(args) == 1: 
                    msg = request.pyclass(args[0])
                else: 
                    msg = request.pyclass()
                    
            binding.Send(None, None, msg,
                         requesttypecode=request,
                         soapheaders=soapheaders,
                         encodingStyle=callinfo.encodingStyle)
            
            if response is None: 
                return None
            
            if self._asdict: self._nullpyclass(response)
            return binding.Receive(replytype=response,
                         encodingStyle=callinfo.encodingStyle)