Skip to content

Instantly share code, notes, and snippets.

@hartsock
Created September 20, 2012 15:39
Show Gist options
  • Save hartsock/3756665 to your computer and use it in GitHub Desktop.
Save hartsock/3756665 to your computer and use it in GitHub Desktop.
mirror a WSDL from a server using Groovy
File mirrorWsdl(URL firstUrl, File dest) {
assert firstUrl.getText(), "Can't read from ${firstUrl} "
assert dest.mkdir() || dest.exists() && dest.isDirectory(), "Can't read/write to directory ${dest}"
def file = firstUrl.getFile()
def parentPath = file.substring(0,file.lastIndexOf('/') + 1)
def files = [:]
def urls = [firstUrl]
while(urls) {
URL url = urls.pop()
def path = url.getFile()
def name = path.substring(path.lastIndexOf('/')+1,path.length())
new groovy.util.XmlSlurper()
.parse(url.toString())
.depthFirst()
.findAll {
it.name()=='import' || it.name()=='include'
} .each { node ->
String location = node?.@location?.toString() ?: node?.@schemaLocation?.toString()
if(location && !location.startsWith('http') ) {
urls << new URL(firstUrl.protocol,firstUrl.host,firstUrl.port,parentPath + location)
}
}
files[name] = url // stash this file for download
}
files.each { name, URL url ->
new File(dest,name).text = url.text
}
return new File(dest,file.substring(file.lastIndexOf('/')+1,file.length()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment