Skip to content

NoSuchMethodError when creating SttpBackendStub #42

@goral09

Description

@goral09

Hello, I have just started using sttp. It looks promising but I am hitting the wall on the first execution.

My setup is as follows:

scala 2.11
monix 2.3.0
"com.softwaremill.sttp" %% "core" % "1.0.2"
"com.softwaremill.sttp" %% "async-http-client-backend-monix" % "1.0.2"

I have simple http client performing POST requests and I want to test it. I am providing a stub like this:

 implicit val sttpStub: SttpBackendStub[Task, Observable[ByteBuffer]] =
      SttpBackendStub(AsyncHttpClientMonixBackend())
        .whenRequestMatches(_ => true)
        .thenRespond(entityFoundHtml)

and upon execution of the test I am seeing this error:

[2017-11-08 19:32:34,257] [DEBUG] [i.n.u.i.l.InternalLoggerFactory] [] Using SLF4J as the default logging framework
[2017-11-08 19:32:34,263] [DEBUG] [io.netty.util.ResourceLeakDetector] [] -Dio.netty.leakDetection.level: simple
[2017-11-08 19:32:34,269] [DEBUG] [io.netty.util.ResourceLeakDetector] [] -Dio.netty.leakDetection.maxRecords: 4
[2017-11-08 19:32:34,275] [DEBUG] [i.n.util.internal.PlatformDependent0] [] java.nio.Buffer.address: available
[2017-11-08 19:32:34,276] [DEBUG] [i.n.util.internal.PlatformDependent0] [] sun.misc.Unsafe.theUnsafe: available
[2017-11-08 19:32:34,276] [DEBUG] [i.n.util.internal.PlatformDependent0] [] sun.misc.Unsafe.copyMemory: available
[2017-11-08 19:32:34,276] [DEBUG] [i.n.util.internal.PlatformDependent0] [] java.nio.Bits.unaligned: true
[2017-11-08 19:32:34,277] [DEBUG] [i.n.util.internal.PlatformDependent] [] Java version: 8
[2017-11-08 19:32:34,277] [DEBUG] [i.n.util.internal.PlatformDependent] [] -Dio.netty.noUnsafe: false
[2017-11-08 19:32:34,277] [DEBUG] [i.n.util.internal.PlatformDependent] [] sun.misc.Unsafe: available
[2017-11-08 19:32:34,277] [DEBUG] [i.n.util.internal.PlatformDependent] [] -Dio.netty.noJavassist: false
[2017-11-08 19:32:34,343] [DEBUG] [i.n.util.internal.PlatformDependent] [] Javassist: available
[2017-11-08 19:32:34,343] [DEBUG] [i.n.util.internal.PlatformDependent] [] -Dio.netty.tmpdir: /tmp (java.io.tmpdir)
[2017-11-08 19:32:34,344] [DEBUG] [i.n.util.internal.PlatformDependent] [] -Dio.netty.bitMode: 64 (sun.arch.data.model)
[2017-11-08 19:32:34,344] [DEBUG] [i.n.util.internal.PlatformDependent] [] -Dio.netty.noPreferDirect: false

An exception or error caused a run to abort: io.netty.handler.ssl.SslContextBuilder.protocols([Ljava/lang/String;)Lio/netty/handler/ssl/SslContextBuilder; 
java.lang.NoSuchMethodError: io.netty.handler.ssl.SslContextBuilder.protocols([Ljava/lang/String;)Lio/netty/handler/ssl/SslContextBuilder;
	at org.asynchttpclient.netty.ssl.DefaultSslEngineFactory.buildSslContext(DefaultSslEngineFactory.java:45)
	at org.asynchttpclient.netty.ssl.DefaultSslEngineFactory.init(DefaultSslEngineFactory.java:69)
	at org.asynchttpclient.netty.channel.ChannelManager.<init>(ChannelManager.java:116)
	at org.asynchttpclient.DefaultAsyncHttpClient.<init>(DefaultAsyncHttpClient.java:85)
	at com.softwaremill.sttp.asynchttpclient.AsyncHttpClientBackend$.defaultClient(AsyncHttpClientBackend.scala:314)
	at com.softwaremill.sttp.asynchttpclient.monix.AsyncHttpClientMonixBackend$.apply(AsyncHttpClientMonixBackend.scala:68)

I googled a bit and it looks like method io.netty.handler.ssl.SslContextBuilder.protocols was introduced in netty 4.1.9 (https://github.com/AsyncHttpClient/async-http-client/issues/1406). I run dependencyTree on my project and I can see that:

+-com.softwaremill.sttp:async-http-client-backend-monix_2.11:1.0.2 [S]
[info]   | +-com.softwaremill.sttp:async-http-client-backend_2.11:1.0.2 [S]
[info]   | | +-com.softwaremill.sttp:core_2.11:1.0.2 [S]
[info]   | | +-org.asynchttpclient:async-http-client:2.0.37
[info]   | |   +-com.typesafe.netty:netty-reactive-streams:1.0.8
[info]   | |   | +-io.netty:netty-handler:4.0.41.Final (evicted by: 4.0.52.Final)

what am I doing wrong? It doesn't look like I have mixed any dependency as the project just has 4 dependencies pulled in (scalatest, monix and two libraries from sttp ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions