예제 #1
0
def getClient():
    try:
        code = Element('UserName').setText('admin')
        pwd = Element('PassWord').setText('123abc')
        en = ('RequestSOAPHeader', 'http://com.appScan.cxf/')
        e = Element('auth', ns=en)
        e.insert(code)
        e.insert(pwd)
        c = Client(url, cache=None)
        c.set_options(soapheaders=e)
        return c
    except urllib2.URLError:  #no internet connection
        print "[*]no internet connection. try again[*]"
        time.sleep(2)
        getClient()
    except TransportError:  #HTTP Error 500: Internal Server Error
        print "[*]Auth failed. try again[*]"
        time.sleep(2)
        getClient()
    except (KeyboardInterrupt) as Exit:
        print("[*]\nExit[*]")
        sys.exit(0)
    except Exception as e:
        print str(e)
        sys.exit(0)
예제 #2
0
def testWSDL(wsdlURL):
  replyURL = 'http://wsamplification.appspot.com/?webservice=' + wsdlURL
  try:
    client = Client(wsdlURL)    
    wsans = ('wsa', 'http://schemas.xmlsoap.org/ws/2004/08/addressing')
    wsaReply = Element('ReplyTo', ns=wsans)
    wsaAddress = Element('Address', ns=wsans).setText(replyURL)
    wsaReply.insert(wsaAddress)
  except:
    print 'Moving on...'
    return
  try:
    client.set_options(soapheaders=wsaReply) 
    #impl = getattr(client.service, 'submitOrderNoAck')
    #print impl()
    for method in client.wsdl.services[0].ports[0].methods.values():
      print method.name
      result = getattr(client.service, method.name)()
      #print result()
  except suds.WebFault as detail:
    print 'Invoking method failed'
    print client
  except:
    print 'Derping...'
    print client
예제 #3
0
    def payuMeaGetTransactionApiCall(self, args):

        #urlToQuery = 'https://secure.payu.co.za/service/PayUAPI?wsdl'
        if (args['store']['environment'] == 'staging'):
            urlToQuery = 'https://staging.payu.co.za/service/PayUAPI?wsdl'
        else:
            urlToQuery = 'https://secure.payu.co.za/service/PayUAPI?wsdl'
        plugin = MyPlugin()
        client = Client(urlToQuery, plugins=[plugin])
        #client = Client(urlToQuery, faults=False)
        #------------------------------------- CREATING CUSTOM HEADER--------------------------------------
        wsse = (
            'wsse',
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
        )

        mustAttributeSecurity = Attribute('SOAP-ENV:mustUnderstand', '1')
        addressAttributeSecurity = Attribute(
            'xmlns:wsse',
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
        )
        AttributeUsernameToken1 = Attribute('wsu:Id', 'UsernameToken-9')
        addressAttributeUsernameToken = Attribute(
            'xmlns:wsu',
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
        )
        addressAttributePassword = Attribute(
            'Type',
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
        )

        msgUsername = Element('Username',
                              ns=wsse).setText(args['store']['soapUsername'])
        msgPassword = Element('Password', ns=wsse).setText(
            args['store']['soapPassword']).append(addressAttributePassword)

        msgUsernameToken = Element('UsernameToken', ns=wsse)
        msgUsernameToken.append(AttributeUsernameToken1)
        msgUsernameToken.append(addressAttributeUsernameToken)
        msgUsernameToken.insert(msgPassword).insert(msgUsername)

        msgSecurity = Element('Security', ns=wsse).addPrefix(
            p='SOAP-ENC', u='http://www.w3.org/2003/05/soap-encoding')
        msgSecurity.append(mustAttributeSecurity)
        msgSecurity.append(addressAttributeSecurity)
        msgSecurity.insert(msgUsernameToken)

        client.set_options(soapheaders=[msgSecurity])

        #------------------------------------- CREATING SOAP CALL DETAILS HERE--------------------------------------
        transaction = {}
        transaction['Api'] = 'ONE_ZERO'
        transaction['Safekey'] = args['store']['safekey']
        transaction['AdditionalInformation'] = args['additionalInformation']
        #------------------------------------- DOING SOAP CALL HERE--------------------------------------
        try:
            setTransaction = client.service.getTransaction(**transaction)
        except Exception, e:
            print_exc()
예제 #4
0
 def _build_mouser_header(self):
     header_partnerid = Element('PartnerID').setText(self._api_key)
     header_accountinfo = Element('AccountInfo')
     header_accountinfo.insert(header_partnerid)
     header = Element('MouserHeader')
     header.insert(header_accountinfo)
     header.set('xmlns', 'http://api.mouser.com/service')
     return header
예제 #5
0
파일: mouser.py 프로젝트: chintal/tendril
 def _build_mouser_header(self):
     header_partnerid = Element('PartnerID').setText(self._api_key)
     header_accountinfo = Element('AccountInfo')
     header_accountinfo.insert(header_partnerid)
     header = Element('MouserHeader')
     header.insert(header_accountinfo)
     header.set('xmlns', 'http://api.mouser.com/service')
     return header
    def __init__(self, url, username, password):
        self._client = Client(url)
        wsse_ns = ("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
        mustAttribute = Attribute('SOAP-ENV:mustUnderstand', '1')
        security_header = Element("Security", ns=wsse_ns).append(mustAttribute)

        message_header = Element("UsernameToken", ns=wsse_ns)
        message_header.insert(Element("Username", ns=wsse_ns).setText(username))
        message_header.insert(Element("Password", ns=wsse_ns).setText(password))
        security_header.insert(message_header)
        self._client.set_options(soapheaders = security_header)

        self.mappingUtils = MappingUtils(self._client)
예제 #7
0
def call_service(action, address=JMMServer_Address, port=JMMServer_Port):
    binding.envns = ('s', 'http://www.w3.org/2003/05/soap-envelope')
    client = Client(
        format_url(address, port),
        headers={'Content-Type': 'application/soap+msbin1'},
        transport=HttpAuthenticatedBinary(),
        plugins=[BinaryMessagePlugin()]
    )

    ssnns = ('a', 'http://www.w3.org/2005/08/addressing')
    element_action = Element('Action', ns=ssnns).setText('http://tempuri.org/IJMMServer/{0}'.format(action))
    element_action.set('s:mustUnderstand', "1")
    element_reply_to = Element('ReplyTo', ns=ssnns)
    element_address = Element('Address', ns=ssnns).setText('http://www.w3.org/2005/08/addressing/anonymous')
    element_reply_to.insert(element_address, 0)
    element_to = Element('To', ns=ssnns).setText('http://{0}:{1}/JMMServerBinary'.format(address, port))
    element_to.set('s:mustUnderstand', "1")
    client.set_options(soapheaders=(element_action, element_reply_to, element_to))
    func = getattr(client.service, action)
    func()
예제 #8
0
파일: views.py 프로젝트: thony19cr/wawared
def json_response(num_dni):
    objServicio = ServicioReniec.objects.get(id=1)

    ns = objServicio.namespace  # 'http://tempuri.org/'
    url = objServicio.urlwsdlservice  # 'http://ws_min.minsa.gob.pe/wsreniecmq/serviciomq.asmx?wsdl'
    app = objServicio.appservice  # 'WAWARED'
    usuario = objServicio.userservice  # '05353734'
    clave = objServicio.passservice  # '/*_waw@r3d+$'

    tem_ns = ('tem', ns)
    cliente = suds.client.Client(url)

    h_app = Element('app', ns=tem_ns)
    h_usuario = Element('usuario', ns=tem_ns)
    h_clave = Element('clave', ns=tem_ns)

    h_app.setText(app)
    h_usuario.setText(usuario)
    h_clave.setText(clave)

    h_credentialmq = Element('Credencialmq', ns=tem_ns)
    h_credentialmq.insert(h_app)
    h_credentialmq.insert(h_usuario)
    h_credentialmq.insert(h_clave)

    cliente.set_options(soapheaders=h_credentialmq)
    resultado = cliente.service.obtenerDatosCompletos(num_dni)

    return JsonResponse(resultado[0], safe=False)
예제 #9
0
    def _build_security_header(self, username, password):
        """ Alternative method for building security header elements to use
            in the SOAP calls.  This method is *not* being used currently, but
            is left here for reference.
        """
        usernameElement = Element('Username', ns=WSSE_NS)
        usernameElement.setText(username)

        passwordElement = Element('Password', ns=WSSE_NS)
        passwordElement.setText(password)
        passwordElement.append(Attribute('Type', WSU_UN_URI))

        userCreds = Element('UsernameToken', ns=WSSE_NS)
        userCreds.append(Attribute('wsu:Id', 'UsernameToken-9'))
        userCreds.append(Attribute('xmlns:wsu', WSSE_URI))
        userCreds.insert(usernameElement)
        userCreds.insert(passwordElement)

        security = Element('Security', ns=WSSE_NS)
        security.addPrefix(p='SOAP-ENC', u=SOAP_ENC_URI)
        security.append(Attribute('SOAP-ENV:mustUnderstand', '1'))
        security.append(Attribute('xmlns:wsse', WSSE_URI))
        security.insert(userCreds)
        return security
예제 #10
0
    def __init__(self, url, username, password):
        self._client = Client(url)
        wsse_ns = (
            "wsse",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
        )
        mustAttribute = Attribute('SOAP-ENV:mustUnderstand', '1')
        security_header = Element("Security", ns=wsse_ns).append(mustAttribute)

        message_header = Element("UsernameToken", ns=wsse_ns)
        message_header.insert(
            Element("Username", ns=wsse_ns).setText(username))
        message_header.insert(
            Element("Password", ns=wsse_ns).setText(password))
        security_header.insert(message_header)
        self._client.set_options(soapheaders=security_header)

        self.mappingUtils = MappingUtils(self._client)
예제 #11
0
from suds.client import Client as SudsClient
from suds.sax.element import Element

"""
    default "UsernameToken" in suds produces "Password" element without a "Type" field
    https://fedorahosted.org/suds/ticket/402
    so need to build it manually, specifying namespaces
"""

wsse = ('wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd')
security = Element('Security', ns=wsse)
usernametoken = Element('UsernameToken', ns=wsse)
uname = Element('Username', ns=wsse).setText('myusername')
passwd = Element('Password', ns=wsse).setText('mypassword')
passwd.set('Type', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')

usernametoken.insert(uname)
usernametoken.insert(passwd)
security.insert(usernametoken)

url = 'http://127.0.0.1:5000/soap/someservice?wsdl'
client = SudsClient(url=url, cache=None)
client.set_options(soapheaders=security)

r = client.service.echo(str='hello world', cnt=3)

print(r)
예제 #12
0
"""
    default "UsernameToken" in suds produces "Password" element without a "Type" field
    https://fedorahosted.org/suds/ticket/402
    so need to build it manually, specifying namespaces
"""

wsse = (
    'wsse',
    'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
)
security = Element('Security', ns=wsse)
usernametoken = Element('UsernameToken', ns=wsse)
uname = Element('Username', ns=wsse).setText('myusername')
passwd = Element('Password', ns=wsse).setText('mypassword')
passwd.set(
    'Type',
    'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
)

usernametoken.insert(uname)
usernametoken.insert(passwd)
security.insert(usernametoken)

url = 'http://127.0.0.1:5000/soap/someservice?wsdl'
client = SudsClient(url=url, cache=None)
client.set_options(soapheaders=security)

r = client.service.echo(str='hello world', cnt=3)

print(r)
예제 #13
0
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
        )
        addressAttributePassword = Attribute(
            'Type',
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
        )

        msgUsername = Element('Username',
                              ns=wsse).setText(args['store']['soapUsername'])
        msgPassword = Element('Password', ns=wsse).setText(
            args['store']['soapPassword']).append(addressAttributePassword)

        msgUsernameToken = Element('UsernameToken', ns=wsse)
        msgUsernameToken.append(AttributeUsernameToken1)
        msgUsernameToken.append(addressAttributeUsernameToken)
        msgUsernameToken.insert(msgPassword).insert(msgUsername)

        msgSecurity = Element('Security', ns=wsse).addPrefix(
            p='SOAP-ENC', u='http://www.w3.org/2003/05/soap-encoding')
        msgSecurity.append(mustAttributeSecurity)
        msgSecurity.append(addressAttributeSecurity)
        msgSecurity.insert(msgUsernameToken)

        client.set_options(soapheaders=[msgSecurity])

        #------------------------------------- CREATING SOAP CALL DETAILS HERE--------------------------------------
        transaction = {}
        transaction['Api'] = 'ONE_ZERO'
        transaction['Safekey'] = args['store']['safekey']
        transaction['TransactionType'] = 'PAYMENT'
        transaction['AdditionalInformation'] = args['additionalInformation']
예제 #14
0
    def payuMeaGetTransactionApiCall(self, args):
        if (args['store']['environment'] == 'prod'):
            urlToQuery = 'https://secure.payu.co.za/service/PayUAPI?wsdl'
        else:
            urlToQuery = 'https://staging.payu.co.za/service/PayUAPI?wsdl'
        plugin = MyPlugin()
        client = Client(urlToQuery, plugins=[plugin])

        # client = Client(urlToQuery, faults=False)
        # ------------------------------------- CREATING CUSTOM HEADER--------------------------------------
        wsse = ('wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd')

        mustAttributeSecurity = Attribute('SOAP-ENV:mustUnderstand', '1')
        addressAttributeSecurity = Attribute('xmlns:wsse',
                                             'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd')
        AttributeUsernameToken1 = Attribute('wsu:Id', 'UsernameToken-9')
        addressAttributeUsernameToken = Attribute('xmlns:wsu',
                                                  'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd')
        addressAttributePassword = Attribute('Type',
                                             'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')

        msgUsername = Element('Username', ns=wsse).setText(args['store']['soapUsername'])
        msgPassword = Element('Password', ns=wsse).setText(args['store']['soapPassword']).append(
            addressAttributePassword)

        msgUsernameToken = Element('UsernameToken', ns=wsse)
        msgUsernameToken.append(AttributeUsernameToken1)
        msgUsernameToken.append(addressAttributeUsernameToken)
        msgUsernameToken.insert(msgPassword).insert(msgUsername)

        msgSecurity = Element('Security', ns=wsse).addPrefix(p='SOAP-ENC', u='http://www.w3.org/2003/05/soap-encoding')
        msgSecurity.append(mustAttributeSecurity)
        msgSecurity.append(addressAttributeSecurity)
        msgSecurity.insert(msgUsernameToken)

        client.set_options(soapheaders=[msgSecurity])

        # ------------------------------------- CREATING SOAP CALL DETAILS HERE--------------------------------------
        transaction = {}
        transaction['Api'] = 'ONE_ZERO'
        transaction['Safekey'] = args['store']['safekey']
        transaction['AdditionalInformation'] = args['additionalInformation']
        # ------------------------------------- DOING SOAP CALL HERE--------------------------------------
        try:
            setTransaction = client.service.getTransaction(**transaction)
        except Exception as e:
            print_exc()
        s = plugin.last_received_raw
        transactionState = ''
        successful_status = False
        if s:
            dic = xmltodict.parse(str(s[2:-1]))
            dic['soap:Envelope']['soap:Body']['ns2:getTransactionResponse']['return']['displayMessage']
            payUReference = dic['soap:Envelope']['soap:Body']['ns2:getTransactionResponse']['return']['payUReference']
            successful_status = dic['soap:Envelope']['soap:Body']['ns2:getTransactionResponse']['return']['successful']
            transactionState = dic['soap:Envelope']['soap:Body']['ns2:getTransactionResponse']['return'][
                'transactionState']
        if transactionState == 'SUCCESSFUL' and successful_status:
            return dic['soap:Envelope']['soap:Body']['ns2:getTransactionResponse']['return']
        elif transactionState == 'AWAITING_PAYMENT':
            return dic['soap:Envelope']['soap:Body']['ns2:getTransactionResponse']['return']
        else:
            return False
예제 #15
0
    def payuMeaSetTransactionApiCall(self, args):
        if (args['store']['environment'] == 'prod'):
            urlToQuery = 'https://secure.payu.co.za/service/PayUAPI?wsdl'
        else:
            urlToQuery = 'https://staging.payu.co.za/service/PayUAPI?wsdl'
        try:
            plugin = MyPlugin()
            client = Client(urlToQuery, plugins=[plugin])
        except Exception as e:
            return "/shop/unsuccessful"
        # ------------------------------------- CREATING CUSTOM HEADER--------------------------------------
        wsse = ('wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd')

        mustAttributeSecurity = Attribute('SOAP-ENV:mustUnderstand', '1')
        addressAttributeSecurity = Attribute('xmlns:wsse',
                                             'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd')
        AttributeUsernameToken1 = Attribute('wsu:Id', 'UsernameToken-9')
        addressAttributeUsernameToken = Attribute('xmlns:wsu',
                                                  'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd')
        addressAttributePassword = Attribute('Type',
                                             'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')

        msgUsername = Element('Username', ns=wsse).setText(args['store']['soapUsername'])
        msgPassword = Element('Password', ns=wsse).setText(args['store']['soapPassword']).append(
            addressAttributePassword)

        msgUsernameToken = Element('UsernameToken', ns=wsse)
        msgUsernameToken.append(AttributeUsernameToken1)
        msgUsernameToken.append(addressAttributeUsernameToken)
        msgUsernameToken.insert(msgPassword).insert(msgUsername)

        msgSecurity = Element('Security', ns=wsse).addPrefix(p='SOAP-ENC', u='http://www.w3.org/2003/05/soap-encoding')
        msgSecurity.append(mustAttributeSecurity)
        msgSecurity.append(addressAttributeSecurity)
        msgSecurity.insert(msgUsernameToken)

        client.set_options(soapheaders=[msgSecurity])

        # ------------------------------------- CREATING SOAP CALL DETAILS HERE--------------------------------------
        transaction = {}
        transaction['Api'] = 'ONE_ZERO'
        transaction['Safekey'] = args['store']['safekey']
        transaction['TransactionType'] = 'PAYMENT'
        transaction['AdditionalInformation'] = args['additionalInformation']
        transaction['Basket'] = args['basket']
        transaction['Customer'] = args['customer']

        # ------------------------------------- DOING SOAP CALL HERE--------------------------------------
        try:
            setTransaction = client.service.setTransaction(**transaction)
        except Exception as e:
            print_exc()
        s = plugin.last_received_raw
        dic = xmltodict.parse(str(s[2:-1]))
        response = dic['soap:Envelope']['soap:Body']['ns2:setTransactionResponse']['return']
        if response['successful'] == 'true':
            number = response['payUReference']
            if (args['store']['environment'] == 'prod'):
                url = 'https://secure.payu.co.za/rpp.do' + '?PayUReference=' + str(number)
            else:
                url = 'https://staging.payu.co.za/rpp.do' + '?PayUReference=' + str(number)

        else:
            error_message = response['resultMessage']
            failuer = response['pointOfFailure']
            resultCode = response['resultCode']
            status = '%s - %s', (failuer, resultCode)
            return request.render('website.http_error', {'status_code': status, 'status_message': error_message})
        return url
def payuMeaDoTransactionApiCall(args):	

	urlToQuery = 'https://secure.payu.co.za/service/PayUAPI?wsdl'
	if	(args['store']['environment'] == 'staging')	:
		urlToQuery = 'https://staging.payu.co.za/service/PayUAPI?wsdl'

	client = Client(urlToQuery, faults=False)
	
	# print client

	# Logging:
	#logging.basicConfig(level=logging.DEBUG)
	#handler = logging.StreamHandler(sys.stderr)
	#logger = logging.getLogger('suds.transport.http')
	#logger.setLevel(logging.DEBUG), handler.setLevel(logging.DEBUG)
	#logger.addHandler(handler)
	# class OutgoingFilter(logging.Filter):
	# 	def filter(self, record):
	# 		return record.msg.startswith('sending:')
	# 	handler.addFilter(OutgoingFilter())

	#------------------------------------- CREATING CUSTOM HEADER--------------------------------------
	wsse = ('wsse','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd')

	mustAttributeSecurity = Attribute('SOAP-ENV:mustUnderstand', '1')
	addressAttributeSecurity = Attribute('xmlns:wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd')
	AttributeUsernameToken1 = Attribute('wsu:Id','UsernameToken-9')
	addressAttributeUsernameToken = Attribute('xmlns:wsu','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd')
	addressAttributePassword = Attribute('Type','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')

	msgUsername = Element('Username', ns=wsse).setText(args['store']['soapUsername'])
	msgPassword = Element('Password', ns=wsse).setText(args['store']['soapPassword']).append(addressAttributePassword)

	msgUsernameToken = Element('UsernameToken', ns=wsse)
	msgUsernameToken.append(AttributeUsernameToken1)
	msgUsernameToken.append(addressAttributeUsernameToken)
	msgUsernameToken.insert(msgPassword).insert(msgUsername)
	
	msgSecurity = Element('Security', ns=wsse).addPrefix(p='SOAP-ENC', u='http://www.w3.org/2003/05/soap-encoding')
	msgSecurity.append(mustAttributeSecurity)
	msgSecurity.append(addressAttributeSecurity)
	msgSecurity.insert(msgUsernameToken)

	client.set_options(soapheaders=[msgSecurity])

	#------------------------------------- CREATING SOAP CALL DETAILS HERE--------------------------------------	
	transaction = {}
	transaction['Api'] = 'ONE_ZERO';
	transaction['Safekey'] = args['store']['safekey'];
	transaction['TransactionType'] = 'FINALIZE';	
	transaction['AdditionalInformation'] = args['additionalInformation']			
	transaction['Basket'] = args['basket']	
	#transaction['Customer'] = args['customer']	
	
	#------------------------------------- DOING SOAP CALL HERE--------------------------------------
	try:
		setTransaction = client.service.doTransaction(** transaction)
	except Exception, e:
		print "----------------"		
		print 'type is:', e.__class__.__name__
		print_exc()
		print "----------------"