Hflower
13 years agoOccasional Contributor
Retrieving the completed REST URL in Groovy
I'm using Template Resource Parameters on my REST Resource and I need to use the completed the URL that is sent in the HTTP Header as part of my authentication routine.
My endpoint is http://www.company.com
My Resource Path is /ws/app/search/{Query}
http://www.company.com/ws/app/search/Query
If my query string is acme
I need http://www.company.com/ws/app/search/acme
The template substitution is working ok but I was wondering if I can get the complete URL in Groovy?
I've had a look through the soapUI AP docs but get a bit lost
I've written some code that can work with QUERY type parameters, but now I want to test with a different type of URL
My endpoint is http://www.company.com
My Resource Path is /ws/app/search/{Query}
http://www.company.com/ws/app/search/Query
If my query string is acme
I need http://www.company.com/ws/app/search/acme
The template substitution is working ok but I was wondering if I can get the complete URL in Groovy?
I've had a look through the soapUI AP docs but get a bit lost
I've written some code that can work with QUERY type parameters, but now I want to test with a different type of URL
httpRequest = testStep.testRequest
propertyHolder = httpRequest.getParams()
if(propertyHolder){
queryString = getQueryString(httpRequest,propertyHolder)
}else{
queryString = ""
}
def getQueryString(httpRequest,propertyHolder){
queryString = "?"
for( properties in propertyHolder){
//log.info "Name is ${properties.key}"
value1 = properties.key
value = httpRequest.getProperty("${value1}").getValue()
if(value){
if(queryString.length() == 1){
queryString = queryString + properties.key + "=" + value
}else{
queryString = queryString + "&" + properties.key + "=" + value
}
}
}
log.info "queryString is $queryString"
return queryString
}