Solved
Forum Discussion
Cekay
7 years agoContributor
I can't tell you what is wrong but I can post our script. :X Maybe it helps.
I didn't write it, so I can't answer any questions
We added this script as Event "SubmitListener.beforeSubmit
// Import the required classes import com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade import com.eviware.soapui.support.editor.inspectors.auth.TokenType import com.eviware.soapui.model.support.ModelSupport def authProfileName = "PROFILE_NAME" if(!submit.getRequest().getAuthType().asBoolean()){ return // stop if the auth type is null, for example jdbc requests }else if(submit.getRequest().getActiveAuthProfile() == null){ return // stop if the auth profile is null }else if(authProfileName == submit.getRequest().getActiveAuthProfile().getName()){ // Set up variables def project = ModelSupport.getModelItemProject(context.getModelItem()) def authProfile = project.getAuthRepository().getEntry(authProfileName) def oldToken = authProfile.getAccessToken() def tokenType = TokenType.ACCESS // Create a facade object def oAuthFacade = new OltuOAuth2ClientFacade(tokenType) // Request an access token in headless mode oAuthFacade.requestAccessToken(authProfile, true, true) // Wait until the access token gets updated //while(oldToken == authProfile.getAccessToken()) {} //The sleep method can be used instead of a while loop //sleep(3000) for(int i = 0; i<=3000; i++){ if(oldToken != authProfile.getAccessToken()){ break } sleep(1) } // Post the info to the log //log.info("Set new token: " + authProfile.getAccessToken()) }
Cheers,
Cekay