Forum Discussion

pankajmalinda's avatar
pankajmalinda
Occasional Contributor
6 years ago

Groovy Script to send response value to username in Outgoing WS Security Configurations

Hi,

 

I need help with sending response value to username in Outgoing WS-Security Configurtions, see attached SOAP UI Screenshot for more clarification.

 

I want to send the highlighted value in response to WS-Security Username field

SOAP ResponseWS- Security Username

  • Hi pankajmalinda ,

     

    Written below code hope it will help you to set desired values :

     

    def project = testRunner.testCase.testSuite.project;
    def WssC = project.getWssContainer();
    def outgoingWSSName = "APPService"
    def userName = "testUserName";
    def password= "testPassword";
    def passwordType = "PasswordText"
    def entityName = "Username"
    def outgoingObj;
    def list = WssC.getOutgoingWssList()
    if(list.size() == 0){		
    	outgoingObj = WssC.addOutgoingWss(outgoingWSSName);
    	addEntry(outgoingObj , entityName, userName, password, passwordType);
    }
    list.each{
    	if(it.name.toString() != outgoingWSSName){
    		log.info "test"
    		outgoingObj = WssC.addOutgoingWss(outgoingWSSName);
    		addEntry(outgoingObj , entityName, userName, password, passwordType);
    	}
    	else{
    		log.info "tesT"
    		test1 = WssC.removeOutgoingWssAt(0);
    		outgoingObj = WssC.addOutgoingWss(outgoingWSSName);
    		outgoingObj = WssC.getOutgoingWssByName(outgoingWSSName);
    		addEntry(outgoingObj, entityName, userName, password, passwordType);
    	}
    }	
    
    def addEntry(outgoingConfObj, entryName, userName, password, passwordType){
    	def signature = outgoingConfObj.getEntries()
    	def signatureAdd = outgoingConfObj.addEntry(entryName)
    	signatureAdd.setPassword(password);
    	signatureAdd.setUsername(userName);
    	signatureAdd.setPasswordType(passwordType)
    }
  • pankajmalinda's avatar
    pankajmalinda
    6 years ago

    Hi HimanshuTayal 

     

    It is adding  new Outgoing Wss Configuration 'APPservice', I am trying to set the Username field in existing Outgoing Wss Configuration 'APPservice' from response value of a test step as mentioned in the original query.

    I tried to remove the addOutgoingWss and replace it with getOutgoingWss in if-else condition but it didn't work out well.

  • Hi pankajmalinda ,

     

    Written below code hope it will help you to set desired values :

     

    def project = testRunner.testCase.testSuite.project;
    def WssC = project.getWssContainer();
    def outgoingWSSName = "APPService"
    def userName = "testUserName";
    def password= "testPassword";
    def passwordType = "PasswordText"
    def entityName = "Username"
    def outgoingObj;
    def list = WssC.getOutgoingWssList()
    if(list.size() == 0){		
    	outgoingObj = WssC.addOutgoingWss(outgoingWSSName);
    	addEntry(outgoingObj , entityName, userName, password, passwordType);
    }
    list.each{
    	if(it.name.toString() != outgoingWSSName){
    		log.info "test"
    		outgoingObj = WssC.addOutgoingWss(outgoingWSSName);
    		addEntry(outgoingObj , entityName, userName, password, passwordType);
    	}
    	else{
    		log.info "tesT"
    		test1 = WssC.removeOutgoingWssAt(0);
    		outgoingObj = WssC.addOutgoingWss(outgoingWSSName);
    		outgoingObj = WssC.getOutgoingWssByName(outgoingWSSName);
    		addEntry(outgoingObj, entityName, userName, password, passwordType);
    	}
    }	
    
    def addEntry(outgoingConfObj, entryName, userName, password, passwordType){
    	def signature = outgoingConfObj.getEntries()
    	def signatureAdd = outgoingConfObj.addEntry(entryName)
    	signatureAdd.setPassword(password);
    	signatureAdd.setUsername(userName);
    	signatureAdd.setPasswordType(passwordType)
    }
    • pankajmalinda's avatar
      pankajmalinda
      Occasional Contributor

      Hi HimanshuTayal 

       

      It is adding  new Outgoing Wss Configuration 'APPservice', I am trying to set the Username field in existing Outgoing Wss Configuration 'APPservice' from response value of a test step as mentioned in the original query.

      I tried to remove the addOutgoingWss and replace it with getOutgoingWss in if-else condition but it didn't work out well.

      • HimanshuTayal's avatar
        HimanshuTayal
        Community Hero

        Hi pankajmalinda ,

         

        Try to remove both Outgoing WS Security and then run the code. Hope it will work fine.