Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupted downloaded file #241

Closed
mauromol opened this issue Aug 16, 2022 · 4 comments
Closed

Corrupted downloaded file #241

mauromol opened this issue Aug 16, 2022 · 4 comments
Assignees

Comments

@mauromol
Copy link

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
}
@michel-kraemer michel-kraemer self-assigned this Aug 16, 2022
@michel-kraemer
Copy link
Owner

michel-kraemer commented Aug 17, 2022

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
}

@mauromol
Copy link
Author

Thanks for the analysis and workaround. Well... you never stop learning... :-)

@michel-kraemer
Copy link
Owner

I've fixed the issue and published a new version 5.1.2. Please test again.

@mauromol
Copy link
Author

Version 5.1.2 works fine in this scenario, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants