Corrupted downloaded file
mauromol opened this issue · 4 comments
Describe the bug
When downloading a WSDL with this plugin, I get the contents of that WSDL different from the result I get if I download the file with a browser or with a simple Java script in JShell.
Consider the build script reported below and run: gradle downloadArubaPecEmailManagerWsdl
.
Then look at build/EmailManager.wsdl
.
After doing this, try to execute the following script in JShell:
var url = new URL("https://areaclienti.arubapec.it/arubapec/rpc/EmailManager?wsdl");
var dest = Paths.get("/tmp/EmailManager.wsdl");
try(var in = url.openStream()) { Files.copy(in, dest); }
Then, do a diff between the two files. There are two differences:
4c4
< <xsd:import namespace="http://email.service.rpc.arubapec.it" schemaLocation="http://areaclienti.arubapec.it:443/arubapec/rpc/EmailManager?xsd=1"/>
---
> <xsd:import namespace="http://email.service.rpc.arubapec.it" schemaLocation="https://areaclienti.arubapec.it/arubapec/rpc/EmailManager?xsd=1"/>
580c580
< <soap:address location="http://areaclienti.arubapec.it:443/arubapec/rpc/EmailManager"/>
---
> <soap:address location="https://areaclienti.arubapec.it/arubapec/rpc/EmailManager"/>
In particular, the file downloaded with this plugin shows an imported schema location with http
scheme on port 443, instead of https
. This makes a subsequent call to JAXB XJC fail when trying to retrieve the referred schema, because that URL is invalid.
I'm pretty sure there's some flaky server-side processing here which is altering the WSDL output, however it must be due to some kind of unusual client behavior, because all my attempts to download that WSDL result in a correct schemaLocation
being output (I even tried wget, curl, etc.).
Sample build script
plugins {
id "de.undercouch.download" version "5.1.1"
}
task downloadArubaPecEmailManagerWsdl(type: Download) {
src 'https://areaclienti.arubapec.it/arubapec/rpc/EmailManager?wsdl'
dest new File(buildDir, 'EmailManager.wsdl')
onlyIfModified true
}
Thanks for reporting this. I can reproduce the issue.
If you enable debug mode in Gradle, you can see that gradle-download-task sends a Host
header with a port:
> GET /arubapec/rpc/EmailManager?wsdl
> Accept-Encoding: gzip, x-gzip, deflate
> Host: areaclienti.arubapec.it:443
> Connection: keep-alive
According to this thread, other clients do not include the port in the host header (unless it is a non-default port, i.e. not 80 for HTTP and 443 for HTTPS), so gradle-download-task shouldn't do that either.
I will fix this and get back to you. In the meantime you can specify the Host
header yourself to work around this issue:
task downloadArubaPecEmailManagerWsdl(type: Download) {
src 'https://areaclienti.arubapec.it/arubapec/rpc/EmailManager?wsdl'
dest new File(buildDir, 'EmailManager.wsdl')
header "Host", "areaclienti.arubapec.it"
onlyIfModified true
}
Thanks for the analysis and workaround. Well... you never stop learning... :-)
I've fixed the issue and published a new version 5.1.2. Please test again.
Version 5.1.2 works fine in this scenario, thank you very much!