mizosoft / methanol

⚗️ Lightweight HTTP extensions for Java
https://mizosoft.github.io/methanol
MIT License
239 stars 12 forks source link

UnsupportedOperationException when using Methanol as part of a GraalVM native image #62

Closed preslavrachev closed 6 months ago

preslavrachev commented 1 year ago

Methanol runs perfectly fine in a JVM app, but produces the following exception when running inside a native image binary:

java.lang.UnsupportedOperationException: unsupported encoding: gzip

My assumption is that this is due to runtime class loading and reflection at play. I tried listing the class GzipDecoder as part of the standard GraalVM reflection-config.json, but it did not seem to help.

NOTE: My app is based on Quarkus

Would you have any idea how to solve that? Is there a way to register the decoder manually?

mizosoft commented 1 year ago

Hi @preslavrachev, thanks for raising this issue.

Decompression seems to be working fine when tested in a simple native image built with the GraalVM Gradle plugin. However, I'm yet to try it with Quarkus, which might be doing something differently. BTW the class you're looking for is GzipBodyDecoderFactory, does it help adding it in reflection-config.json?

It'd be good to make the claim that Methanol is automatically compatible with GraalVM, so I'll make sure to run tests in a GraalVM image as part of CI and make the necessary changes before the next release.

preslavrachev commented 1 year ago

@mizosoft - thanks, yeah, I discovered the factory a bit later. I haven't yet tried adding it instead, but I will check it early next week. In case you manage to get some positive results with Quarkus, I'd be happy to add Methanol on board, because it is a real time-saver.

mizosoft commented 1 year ago

@preslavrachev sure, I'll let you know when I give it a try. Glad Methanol could be helpful!

SingingBush commented 1 year ago

I use methanol in a Quarkus app built as native image and it works fine. Perhaps this is a config issue. Did you set quarkus.http.enable-decompression=true in the application properties?

https://quarkus.io/guides/all-config#quarkus-vertx-http_quarkus.http.enable-decompression

mizosoft commented 6 months ago

Apologies for not getting back to this sooner :)

For quarkus, you have to explicitly tell it to allow ServiceLoader usage in the native image. Check out this for how.

For plain GraalVM, it automatically picks up the META-INF/services files, so the mechanism works implicitly.