Retrieve binding properties/values with groovy script
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Retrieve binding properties/values with groovy script
I would like to get the WSDL Definition Namespace in a Groovy script. I tried looking at the code completion to see if I could find anything useful and this is the best I could get.
def iList = runner.project.getInterfaceList() log.info iList for ( i in iList ) { log.info i.name }
I didn't really see anything else that was useful. I have just 1 interface in my project.
If anyone knows how to do this it would help me out.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
From project, use getInterfaceByName, from there you have getWsdlContext(), and then from there, getDefinitionParts().first().content is the actual wsdl definition as xml.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@JHunt Thanks for your response. That is getting me about halfway. Inside of the wsdl definition there is a 'targetNamespace=' and this is what I want to get. Either that or the 'namespace' returned inside of the schema list.
I wish I could share my wsdl but it's for work and they won't allow me to share that on a public forum like this. Here is a editedup version of what I am talking about.
<wsdl:definitions name="ServiceName" targetNamespace="http://www.targetNamespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.tns/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:sas="http://www.sas" xmlns:hdr="http://www.hdr" xmlns:ex="http://www.Exception"> <wsdl:types> <xs:schema elementFormDefault="qualified"> <xs:import namespace="http://www.namespace" schemaLocation="https://schemaLocation?xsd=../xsd/schemaLocation.xsd"/> <xs:import namespace="http://www.Exception" schemaLocation="https://Exception/?xsd=..xsd/Exception.xsd"/> <xs:import namespace="http://Header" schemaLocation="https://Header?xsd=../xsd/Header.xsd"/> </xs:schema>
Is there a way to return those values by name?
Or if you look at the Project tab in SoapUI and you open the 'Interface Viewer' it lists all the parts of the interface. At the top it shows 'WSDL Definitions' and it lists the attributes by name.
- WSDL Definition
- WSDL URL
- Namespace
- Binding
- SOAP Version
- Style
- WS-A version
Do you know of a way to access these?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I don't know much about how SoapUI stores WSDLs internally (it seems there's some library being used). Mostly I can help you to get what you need out of the WSDL XML...
testRunner.testCase.project.getInterfaceByName('SampleServiceSoapBinding')
.getWsdlContext()
.getDefinitionParts()[0]
.getContent()
.with { new XmlSlurper().parseText(it)}
.with { definitions ->
assert definitions.@targetNamespace.text() ==
'http://www.soapui.org/sample/'
assert definitions.binding.collect { it.@name.text() } ==
['SampleServiceSoapBinding']
assert definitions.binding.operation.collect { it.@name.text() } ==
['login', 'logout', 'search', 'buy']
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, I modified your script a little but it returns an error. You had the targetNameSpace explicitly in your script. I want to be able to get it without having to know it. Unless I am misunderstanding what you were doing?
I made the following change.
testRunner.testCase.project.getInterfaceByName('ServiceActivationRouter') .getWsdlContext() .getDefinitionParts()[0] .getContent() .with { new XmlSlurper().parseText(it)} .with { definitions -> def tns = definitions.@targetNamespace.text() log.info tns }
The error returned is
groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.NodeChildren.info() is applicable for argument types: (java.lang.String) values: [http://www.targetNameSpace.com/target/name/space/] Possible solutions: init(), min(), find(), any(), find(groovy.lang.Closure), find(groovy.lang.Closure)
I changed the value of the targetNameSpace here but it is showing the valid namespace that I want to get.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try it like this:
String tns = testRunner.testCase.project.getInterfaceByName('ServiceActivationRouter') .getWsdlContext() .getDefinitionParts()[0] .getContent() .with { new XmlSlurper().parseText(it)} .with { definitions -> definitions.@targetNamespace.text() }
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had to make a small change to actually log the namespace but this works.
log.info testRunner.testCase.project.getInterfaceByName('ServiceActivationRouter') .getWsdlContext() .getDefinitionParts()[0] .getContent() .with { new XmlSlurper().parseText(it)} .with { definitions -> definitions.@targetNamespace.text() }
Thanks for your help!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hah!, I just realized you had it right actually. I started thinking about how I was going to use this unnamed variable and saw what I did wrong.
String tns = testRunner.testCase.project.getInterfaceByName('ServiceActivationRouter') .getWsdlContext() .getDefinitionParts()[0] .getContent() .with { new XmlSlurper().parseText(it)} .with { definitions -> definitions.@targetNamespace.text() } log.info tns
