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

mod download issue #1373

Closed
PhilipJFryFAF opened this issue Jul 29, 2019 · 6 comments · Fixed by #1398
Closed

mod download issue #1373

PhilipJFryFAF opened this issue Jul 29, 2019 · 6 comments · Fixed by #1398
Labels
bug S2 major severity 2 - major - major loss of function
Milestone

Comments

@PhilipJFryFAF
Copy link
Collaborator

PhilipJFryFAF commented Jul 29, 2019

when trying to download the common mod tools mod i (and another user who reported the bug) receive the following error

java.util.concurrent.CompletionException: java.io.IOException: Server returned HTTP response code: 400 for URL: http://content.faforever.com/mods/Common Mod Tools.v0001.zip
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture$UniRun.tryFire(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source)
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source)
	at com.faforever.client.task.CompletableTask.lambda$new$1(CompletableTask.java:17)
	at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
	at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
	at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
	at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
	at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
	at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
	at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
	at javafx.base/javafx.event.Event.fireEvent(Unknown Source)
	at javafx.graphics/javafx.concurrent.EventHelper.fireEvent(Unknown Source)
	at javafx.graphics/javafx.concurrent.Task.fireEvent(Unknown Source)
	at javafx.graphics/javafx.concurrent.Task.setState(Unknown Source)
	at javafx.graphics/javafx.concurrent.Task$TaskCallable.lambda$call$2(Unknown Source)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
	at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
	at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: http://content.faforever.com/mods/Common Mod Tools.v0001.zip
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	at com.faforever.client.mod.InstallModTask.call(InstallModTask.java:66)
	at com.faforever.client.mod.InstallModTask.call(InstallModTask.java:32)
	at javafx.graphics/javafx.concurrent.Task$TaskCallable.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	... 1 more
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: http://content.faforever.com/mods/Common Mod Tools.v0001.zip
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)
	at java.base/java.net.URLConnection.getHeaderFieldLong(Unknown Source)
	at java.base/java.net.URLConnection.getContentLengthLong(Unknown Source)
	at java.base/java.net.URLConnection.getContentLength(Unknown Source)
	at com.faforever.client.mod.InstallModTask.call(InstallModTask.java:63)
	... 6 more

downloading the mod works when doing so via the http://content.faforever.com/mods/Common Mod Tools.v0001.zip or via the legacy client
i assume the client

@Wizek
Copy link

Wizek commented Aug 3, 2019

I have the same issue. I think the issue is that " " (whitespace) is not encoded to be "%20" in the request URL.

@PhilipJFryFAF
Copy link
Collaborator Author

https://cdn.discordapp.com/attachments/202928463076786176/607247319678713897/unknown.png
another user on discord ran into that issue today

@Wizek
Copy link

Wizek commented Aug 3, 2019

It seems this is the critical part in the code:

protected Void call() throws Exception {
Objects.requireNonNull(url, "url has not been set");
Path tempFile = Files.createTempFile(preferencesService.getCacheDirectory(), "mod", null);
logger.info("Downloading mod {} to {}", url, tempFile);
updateTitle(i18n.get("downloadingModTask.downloading", url));
Files.createDirectories(tempFile.getParent());
URLConnection urlConnection = url.openConnection();
int contentLength = urlConnection.getContentLength();

I don't have much Java experience -- but I do have some with other languages, and maybe all we need here is to use encode? https://www.geeksforgeeks.org/java-net-urlencoder-class-java/

I gave it a try in a repl, and as expected, the spaces are encoded, but not to "%20"s, instead they turned to "+"es. Which would be fine if the server conformed to url decoding standards, which it seems it doesn't do, since:

Okay, so I'm onto a bit more hacky solution to do search and replace of white-spaces.

This might do the trick:

System.out.println(URLEncoder.encode(url).replaceAll("\\+", "%20"));

This way everything is encoded, and we give special consideration to whitespace to be %20 and not +.

Maybe I can try to send in a pull request based on this.

Wizek added a commit to Wizek/downlords-faf-client that referenced this issue Aug 3, 2019
@Wizek
Copy link

Wizek commented Aug 3, 2019

Started a PR here: #1381

@Katharsas
Copy link
Collaborator

Katharsas commented Aug 4, 2019

Since Guava is already used, you could use UrlEscapers.urlFragmentEscaper().escape(input);.
And i think we also use Apache commons, so URIUtil.encodeQuery(input) would probably work too.
(see https://stackoverflow.com/questions/4737841/urlencoder-not-able-to-translate-space-character)

I think the real underlying problem is that com.faforever.client.api.dto.ModVersion uses URL incorrectly (or whatever code does the dto conversion to the dto object), since URL.encode was never meant to encode non query parameter part of a URL. This is maybe a cross-cutting issue with all DTO classes that use URL.
@Brutus5000

Whereever the URL object gets created from string (maybe some preconfigured converter), there is the actual bug.

@Katharsas
Copy link
Collaborator

Katharsas commented Aug 19, 2019

This is a cross-cutting issue im pretty sure. Most likely, all classes inside com.faforever.client.api.dto are affected by wrong URL object from json conversion.

@1-alex98 1-alex98 added S2 major severity 2 - major - major loss of function bug labels Aug 28, 2019
1-alex98 pushed a commit that referenced this issue Aug 28, 2019
Properly encode URLs for all jackson objects

Fixes #1373
@1-alex98 1-alex98 added this to the v1.0.0 milestone Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug S2 major severity 2 - major - major loss of function
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants