play-ws icon indicating copy to clipboard operation
play-ws copied to clipboard

Wrong 'ahc-default.properties' resource file loaded when there's a non-shaded version of asynchttpclient in the class path.

Open noisypants opened this issue 8 years ago • 5 comments

Are you looking for help?

Play WS Version (2.5.x / etc)

2.6.2

API (Scala / Java / Neither / Both)

Both

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

Windows 10

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

java version "1.8.0_77" Java(TM) SE Runtime Environment (build 1.8.0_77-b03) Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

Library Dependencies

Expected Behavior

When there is a non-shaded version of asynchttpclient in the class path, depending on the order of jars in the classpath, the non-shaded version of the ahc-default.properties file can get loaded. This in turn makes config queries fail with using the prefix 'play.shaded.ahc'. I would expect the shaded library to specifically load the shaded properties files by renaming the shaded property files.

Actual Behavior

NumberFomatException occurs when trying to instantiate the AsyncHttpClientProvider class when launching a play application.

Caused by: 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.AsyncHttpClientProvider.<init>(AhcWSModule.scala:64)
        at play.api.libs.ws.ahc.AsyncHttpClientProvider$$FastClassByGuice$$68dd0aee.newInstance(<generated>)
        at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)

noisypants avatar Jul 25 '17 17:07 noisypants

Hi @noisypants,

Is this a duplicate of #87?

marcospereira avatar Jul 25 '17 17:07 marcospereira

It's got the same original behavior, however i'm not convinced the workaround solves the issue. By adding the original keys to the shaded properties file, it works if the non-shaded library loads the shaded properties file. But i have the shaded library loading the non-shaded properties.

@marcospereira, am i reading that correctly?

noisypants avatar Jul 25 '17 17:07 noisypants

I am seeing the same issue (see version details below) on the Guardian frontend repo with Play 2.6.3 and above. Here is the branch that exhibits the issue. Confirming the fix in https://github.com/playframework/play-ws/issues/87 has not resolved the problem as mentioned by @noisypants.

Play WS Version (2.5.x / etc)

2.6.3+

API (Scala / Java / Neither / Both)

Both

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

macOS Sierra 10.12.5 Darwin 34480 16.6.0 Darwin Kernel Version 16.6.0

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

java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

Stack Trace

Caused by: 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.AsyncHttpClientProvider.<init>(AhcWSModule.scala:64)
	at play.api.libs.ws.ahc.AhcWSComponents$class.wsClient(AhcWSComponents.scala:31)
	at AppLoader$$anon$1.wsClient$lzycompute(AppLoader.scala:25)
	at AppLoader$$anon$1.wsClient(AppLoader.scala:25)
	at AppComponents$class.ophanApi(AppLoader.scala:32)
	at AppLoader$$anon$1.ophanApi$lzycompute(AppLoader.scala:25)
	at AppLoader$$anon$1.ophanApi(AppLoader.scala:25)
	at AppComponents$class.lifecycleComponents(AppLoader.scala:42)
	at AppLoader$$anon$1.lifecycleComponents$lzycompute(AppLoader.scala:25)
	at AppLoader$$anon$1.lifecycleComponents(AppLoader.scala:25)
	at app.LifecycleComponents$class.startLifecycleComponents(FrontendApplicationLoader.scala:61)
	at AppLoader$$anon$1.startLifecycleComponents(AppLoader.scala:25)
	at app.FrontendApplicationLoader$class.load(FrontendApplicationLoader.scala:23)
	at AppLoader.load(AppLoader.scala:24)
	at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$1.apply(DevServerStart.scala:174)
	at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$1.apply(DevServerStart.scala:171)
	at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
	at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1.reload(DevServerStart.scala:171)

The code corresponding to the line indicated in the stack trace (AsyncHttpClientConfigDefaults.defaultMaxRedirects(AsyncHttpClientConfigDefaults.java:64)) references code from the non-shaded version of the asynchttp client even if the package name matches the shaded version.

annebyrne avatar Oct 03 '17 16:10 annebyrne

Same issue on 2.6.7

an-tex avatar Nov 22 '17 13:11 an-tex

The problem still persists. A solution is to copy the ahc.properties file from the jar file into the conf/ path of the application, thus making sure that the application finds this one in the classpath (the file from the jar already contains the correct keys for shaded+non-shaded versions). We should add a note somewhere in the documentation about this.

domdorn avatar Nov 23 '17 22:11 domdorn