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

Shading does not allow for multiple versions of AHC #229

Open
martin-g opened this issue Jan 26, 2018 · 4 comments
Open

Shading does not allow for multiple versions of AHC #229

martin-g opened this issue Jan 26, 2018 · 4 comments

Comments

@martin-g
Copy link

Are you looking for help?

No.

Play WS Version (2.5.x / etc)

2.6.11

API (Scala / Java / Neither / Both)

Scala

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

Linux me 4.11.8-041108-generic #201706290836 SMP Thu Jun 29 12:38:45 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.17.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

Library Dependencies

"org.asynchttpclient" % "async-http-client" % "2.0.31", // force this version because C* (Cassandra) driver 3.2 pulls in netty 4.0.44

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

  1. play.shaded.ahc.org.asynchttpclient.config.AsyncHttpClientConfigHelper.Config#parsePropertiesFile() should load its resources by using this.getClass().getClassLoader() first

Actual Behavior

Please provide a description of what actually happens, working from the same starting point.

  1. In 2.6.11 the resources are first loaded from Thread.currentThread().getContextClassLoader();

The problem is that my application has both "org.asynchttpclient" % "async-http-client" % "2.0.31" (to be compatible with Cassandra Java Driver) and the shaded one by Play WS.
The application fails with:

java.lang.NumberFormatException: null
	at java.lang.Integer.parseInt(Integer.java:542)
	at java.lang.Integer.parseInt(Integer.java:615)
	at play.shaded.ahc.org.asynchttpclient.config.AsyncHttpClientConfigHelper$Config.getInt(AsyncHttpClientConfigHelper.java:109)
	at play.shaded.ahc.org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultMaxRedirects(AsyncHttpClientConfigDefaults.java:64)
	at play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClientConfig$Builder.<init>(DefaultAsyncHttpClientConfig.java:599)
	at play.api.libs.ws.ahc.AhcConfigBuilder.<init>(AhcConfig.scala:127)
	at play.api.libs.ws.ahc.StandaloneAhcWSClient$.apply(StandaloneAhcWSClient.scala:153)
	at play.api.libs.ws.ahc.AhcWSClient$.apply(AhcWSClient.scala:68)
    ....

The reason is because play.shaded.ahc.org.asynchttpclient.config.AsyncHttpClientConfigHelper.Config#parsePropertiesFile() finds ahc-default.properties in the original jar, not in the shaded one. And because of this play.shaded.ahc.org.asynchttpclient.maxRedirects property cannot be found.

This issue is related to #87

@martin-g
Copy link
Author

Unfortunately using this.getClass().getClassLoader() doesn't help. It still loads the resource without the play.shaded prefix.

@margussipria
Copy link

We had this problem another way around... have also Dispatch in our project, can't update it to newest (using AHC 2.1.x+ (now 2.4.4)). That library didn't find new properties required by AHC.

Fun didn't stop there, we reverted to dispatch 0.13.x with AHC 2.0.39 just to find out Play Framework does not work with Netty Server. AHC 2.0.39 used Netty 4.0.x and Play Server requires 4.1.x (4.1.22 for now).

If this project isn't upgraded to use AHC 2.1+ people running play with netty backend can't upgrade to 2.6 if they are also using libraries like scalaxb or any other requiring standard AHC.

For us only thing to do is burn Play WS and forbid anybody to touch it.

I don't know what are benefits for shading but I don't see them if property files aren't also renamed and truly separated from originals.

@wsargent
Copy link
Member

wsargent commented Apr 5, 2018

I don't know what are benefits for shading but I don't see them if property files aren't also renamed and truly separated from originals.

It's for when projects have conflicting versions of Netty.

If you have conflicting version of AHC, then that's a different problem, and one that's very hard to resolve without patching AHC code itself.

@wsargent wsargent changed the title ahc-default.properties loaded from the wrong location Shading does not allow for multiple versions of AHC Apr 5, 2018
@gmethvin
Copy link
Member

A workaround for now is to create ahc.properties on your classpath and include all the properties in ahc-default.properties of Play's and any other shaded AHC versions. That way AHC will look at your ahc.properties to get the values and not whichever ahc-default.properties it finds first.

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

No branches or pull requests

5 participants