cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Occasional Contributor

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 UI response screenshot.pngSOAP ResponseWS-Security Username Screenshot.pngWS- Security Username

Tags (1)
3 ACCEPTED SOLUTIONS

Accepted Solutions
Super Contributor

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

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)
}

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal

View solution in original post

Occasional Contributor

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

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.

WS-Security COntainerScreenshot.png

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

View solution in original post

Super Contributor

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

Hi @pankajmalinda ,

 

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

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal

View solution in original post

3 REPLIES 3
Super Contributor

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

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)
}

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal

View solution in original post

Occasional Contributor

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

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.

WS-Security COntainerScreenshot.png

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

View solution in original post

Super Contributor

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

Hi @pankajmalinda ,

 

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

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal

View solution in original post