cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a keystore/groovy script to single request through Java

SOLVED
Highlighted
Occasional Contributor

Adding a keystore/groovy script to single request through Java

Hi all, 

I have a testsituation in which I want to have requests with and without the use of a keystore in a single testcase. I'm generating soapuiprojects through the Java package com.eviware.soapui.

 

I found a way to add a certificate in java using this code;

SoapUI.getSettings().setString(SSLSettings.KEYSTORE,
"pathToKeystore");
SoapUI.getSettings().setString(SSLSettings.KEYSTORE_PASSWORD,
"xxxxxxx");
SoapUI.getSettings().setBoolean(SSLSettings.CLIENT_AUTHENTICATION,
true);
SoapUI.saveSettings();

However, this adds the credentials to the whole project (logically), and therefore isn't usefull to me.

 

In the ReadyAPI user interface I can add credentials to a single request (with a request property), and a way to do this using the library would help me most!

 

An other option would be adding a groovy script to a testcase, and perform all the teststeps with a certificate after running this script. I did this in the user interface with this groovy script;

import com.eviware.soapui.settings.SSLSettings
import com.eviware.soapui.SoapUI

SoapUI.settings.setString( SSLSettings.KEYSTORE, "pathToKeyStore" )
SoapUI.settings.setString( SSLSettings.KEYSTORE_PASSWORD, "xxxxxxx" )

 

However, I do not know how to add this groovy script to a testcase using the package in Java Code. So any help with this would be appriaciated as well!

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super Contributor

Re: Adding a keystore/groovy script to single request through Java

Try writing the above code inside TestCase level TearDown script. Hope it helps.

View solution in original post

3 REPLIES 3
Highlighted
Super Contributor

Re: Adding a keystore/groovy script to single request through Java

Try writing the above code inside TestCase level TearDown script. Hope it helps.

View solution in original post

Highlighted
Community Manager

Re: Adding a keystore/groovy script to single request through Java

Hi @casp8,

 

Does avidCoder's suggestion help?

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Contributor

Re: Adding a keystore/groovy script to single request through Java

Hello @casp8 

 

First you need to add a keystore to your project, you can do this with the following code:

 

DefaultWssContainer wssContainer = wsdlOperation.getProject().getWssContainer();
wssContainer.addCrypto([KEYSTORE_PATH] + [certificateName],[password], CryptoType.KEYSTORE);

 

With this way you can add multiple certificates to your keystore.

After this you can select for every teststep a different keystore.

I use the following code therefore:

 

public static void addCertificateToTeststep(WsdlTestRequestStep testStep, String certificateName){
testStep.getTestRequest().setSslKeystore(certificateName);
}

  

regards,

 

CrazyFrog 🙂

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
The new challenge is here!

Create a script to сhange an XPath Match assertion to a JSONPath Match assertion for the TechCorner tag!


Scripts created in July:
- A script to generate an email when an assertion fails
- A script to change the request body before sending it to the server
Top Kudoed Authors