softwaremill / sttp

The Scala HTTP client you always wanted!
https://sttp.softwaremill.com
Apache License 2.0
1.44k stars 301 forks source link

NoSuchMethodError using AkkaHttpBackend #1773

Open jonathan-neufeld-asurion opened 1 year ago

jonathan-neufeld-asurion commented 1 year ago
java.lang.NoSuchMethodError: sttp.model.Uri.host()Ljava/lang/String;
    at sttp.client.akkahttp.AkkaHttpBackend.connectionSettings(AkkaHttpBackend.scala:177)
    at sttp.client.akkahttp.AkkaHttpBackend.$anonfun$send$3(AkkaHttpBackend.scala:88)
    at scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:307)
    at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:41)
    at scala.concurrent.impl.CallbackRunnable.run$$$capture(Promise.scala:64)

I've traced this to a binary incompatibility introduced by sttp.model:core @ v1.3.4, there does not appear to be an updated version of akka-http-backend to compensate though.

This is because actual host method on Uri returns an Option[String] as of v.1.3.4.

Method where the issue is raised from:

  private def connectionSettings(r: Request[_, _]): ConnectionPoolSettings = {
    val connectionPoolSettingsWithProxy = opts.proxy match {
      case Some(p) if !p.ignoreProxy(r.uri.host) =>
        val clientTransport = p.auth match {
          case Some(proxyAuth) =>
            ClientTransport.httpsProxy(
              p.inetSocketAddress,
              BasicHttpCredentials(proxyAuth.username, proxyAuth.password)
            )
          case None => ClientTransport.httpsProxy(p.inetSocketAddress)
        }
        connectionPoolSettings.withTransport(clientTransport)
      case _ => connectionPoolSettings
    }
    connectionPoolSettingsWithProxy
      .withUpdatedConnectionSettings(_.withIdleTimeout(r.options.readTimeout))
  }
adamw commented 1 year ago

Which versions of sttp & akka are you using? What kind of entries do you have in your build file?