Forum Discussion

Aravamudhan's avatar
Aravamudhan
New Contributor
8 years ago

java.lang.RuntimeException: Unable to refresh expired access token.

Hi all.

 

I am trying to Automate the REST APIs (Services) that uses User Level Token Authentication using using Groovy Script and TestRunner.bat file in SoapUI.

 

Groovy Script: where I am generating and hitting the request.

NOTE: The below are passed as parameters to this method.

strTestStepName, strPathforResp, profilename, respTimepath

 

try
{
def authContainer = testRunner.testCase.testSuite.project.OAuth2ProfileContainer

def profileName = context.expand( '${#Project#profileName}' )

def authProfile = authContainer.getProfileByName(profilename)

def oAuthClientFacade = new OltuOAuth2ClientFacade()

oAuthClientFacade.requestAccessToken(authProfile)

Thread.sleep(1000)

def accessToken = authProfile.getAccessToken()
log.info accessToken


def validate = testRunner.runTestStepByName(strTestStepName);

resptime(validate,respTimepath);
def httpResponseHeaders = context.testCase.testSteps[strTestStepName].testRequest.response.responseHeaders

def strhttpStatus = httpResponseHeaders["#status#"].toString()

strResponseXML = testRunner.testCase.testSteps[strTestStepName].testRequest.response.getContentAsString();
strResponseXML = strResponseXML.trim();
log.info strResponseXML

fWriteToFile(strPathforResp+".txt",strResponseXML) //--> Writing Response to Local for Further validations

}

catch(Exception e)
{
log.info e.message;
}

 

 

 

The User Token is generated without any issues when I try it manually.

But, when I try to run/generate the User Level Token via Groovy Script with TestRunner.bat, I am getting inconsistent Errors - Please see below.

 

Instance#1: Error

2017-08-17 20:45:21,909 INFO [OAuth2RequestFilter] The access token has expired, trying to refresh it.
2017-08-17 20:45:22,586 ERROR [WsdlSubmit] Exception in request: java.lang.RuntimeException: Unable to refresh expired access token.
2017-08-17 20:45:22,587 ERROR [SoapUI] An error occurred [Unable to refresh expired access token.], see error log for details
2017-08-17 20:45:22,589 ERROR [errorlog] java.lang.RuntimeException: Unable to refresh expired access token.
java.lang.RuntimeException: Unable to refresh expired access token.
at com.eviware.soapui.impl.wsdl.submit.filters.OAuth2RequestFilter.reloadAccessToken(OAuth2RequestFilter.java:140)
at com.eviware.soapui.impl.wsdl.submit.filters.OAuth2RequestFilter.filterRestRequest(OAuth2RequestFilter.java:68)
at com.eviware.soapui.impl.wsdl.submit.filters.AbstractRequestFilter.filterAbstractHttpRequest(AbstractRequestFilter.java:41)
at com.eviware.soapui.impl.wsdl.submit.filters.AbstractRequestFilter.filterRequest(AbstractRequestFilter.java:33)
at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:172)
at com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:119)
at com.eviware.soapui.impl.wsdl.WsdlSubmit.submitRequest(WsdlSubmit.java:79)
at com.eviware.soapui.impl.rest.RestRequest.submit(RestRequest.java:192)
at com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep.run(RestTestRequestStep.java:794)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStepByName(AbstractTestCaseRunner.java:200)
at com.eviware.soapui.model.testsuite.TestCaseRunner$runTestStepByName.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at Script1.fRunandAPICResponse(Script1.groovy:113)
at Script1$fRunandAPICResponse.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:153)
at Script1.run(Script1.groovy:58)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
at com.eviware.soapui.model.testsuite.TestStep$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at Script1.run(Script1.groovy:7)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:138)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:46)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:129)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.start(AbstractTestRunner.java:77)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:595)
at com.eviware.soapui.tools.SoapUITestCaseRunner.runTestCase(SoapUITestCaseRunner.java:565)
at com.eviware.soapui.tools.SoapUITestCaseRunner.runRunner(SoapUITestCaseRunner.java:397)
at com.eviware.soapui.tools.AbstractSoapUIRunner.run(AbstractSoapUIRunner.java:204)
at com.eviware.soapui.tools.AbstractSoapUIRunner.run(AbstractSoapUIRunner.java:139)
at com.eviware.soapui.tools.AbstractSoapUIRunner.runFromCommandLine(AbstractSoapUIRunner.java:114)
at com.eviware.soapui.tools.SoapUITestCaseRunner.main(SoapUITestCaseRunner.java:120)
Caused by: org.apache.oltu.oauth2.common.exception.OAuthSystemException: org.apache.http.client.ClientProtocolException
at org.apache.oltu.oauth2.httpclient4.HttpClient4.execute(HttpClient4.java:119)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:65)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:55)
at com.eviware.soapui.impl.rest.actions.oauth.OAuth2TokenExtractor.refreshAccessToken(OAuth2TokenExtractor.java:192)
at com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade.refreshAccessToken(OltuOAuth2ClientFacade.java:72)
at com.eviware.soapui.impl.wsdl.submit.filters.OAuth2RequestFilter.reloadAccessToken(OAuth2RequestFilter.java:119)
... 42 more
Caused by: org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:822)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at org.apache.oltu.oauth2.httpclient4.HttpClient4.execute(HttpClient4.java:103)
... 47 more
Caused by: org.apache.http.auth.MalformedChallengeException: Authentication challenge is empty
at org.apache.http.impl.auth.RFC2617Scheme.parseChallenge(RFC2617Scheme.java:71)
at org.apache.http.impl.auth.AuthSchemeBase.processChallenge(AuthSchemeBase.java:115)
at org.apache.http.impl.auth.BasicScheme.processChallenge(BasicScheme.java:89)
at org.apache.http.impl.client.DefaultRequestDirector.processChallenges(DefaultRequestDirector.java:1183)
at org.apache.http.impl.client.DefaultRequestDirector.handleResponse(DefaultRequestDirector.java:1078)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:482)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
... 50 more

 

Instance#2: Error

2017-08-17 17:37:26,559 INFO [log]
2017-08-17 17:37:27,229 WARN [HttpClientSupport$SoapUIHttpClient] Authentication error: Unable to respond to any of these challenges: {bearer=WWW-Authenticate: Bearer}

 

It would help if anyone could assist me in resolving this (or) let me know if there are any workarounds for this issue

 

Note: Due to Security Reasons I cannot share the API details/project files here.

 

No RepliesBe the first to reply