softwaremill / sttp

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

java.lang.NullPointerException: flowPublisher in HttpClientZioBackend when proxy requires authentication #1697

Open aleksandr-vin opened 1 year ago

aleksandr-vin commented 1 year ago

If proxy requires authentication (replies with 407 status), then NPE arises.

The stack trace:

[info] java.lang.NullPointerException: flowPublisher
[info]  at java.base/java.util.Objects.requireNonNull(Objects.java:246)
[info]  at org.reactivestreams.FlowAdapters.toPublisher(FlowAdapters.java:28)
[info]  at sttp.client3.httpclient.zio.HttpClientZioBackend.publisherToBody(HttpClientZioBackend.scala:49)
[info]  at sttp.client3.httpclient.zio.HttpClientZioBackend.publisherToBody(HttpClientZioBackend.scala:26)
[info]  at sttp.client3.HttpClientAsyncBackend.$anonfun$sendRegular$3(HttpClientAsyncBackend.scala:51)
[info]  at sttp.client3.HttpClientAsyncBackend.$anonfun$sendRegular$3$adapted(HttpClientAsyncBackend.scala:49)
[info]  at sttp.client3.internal.SttpToJavaConverters$$anon$2.accept(SttpToJavaConverters.scala:12)
[info]  at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
[info]  at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
[info]  at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
[info]  at java.base/java.util.concurrent.CompletableFuture.postFire(CompletableFuture.java:610)
[info]  at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:840)
[info]  at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
[info]  at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
[info]  at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
[info]  at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
[info]  at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
[info]  at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

For:

val httpClient = HttpClient
      .newBuilder()
      .followRedirects(HttpClient.Redirect.NEVER)
      .connectTimeout(Duration.ofSeconds(timeout.toSeconds))
      .proxy(ProxySelector.of(new InetSocketAddress(proxyConfig.host, proxyConfig.port)))
      .build()

val backend = HttpClientZioBackend.usingClient(httpClient)
...
response <- backend.send(request.response(asJsonAlways[A]))

Same if proxy configured following the example https://sttp.softwaremill.com/en/latest/conf/proxy.html?highlight=proxy:

SttpBackendOptions.httpProxy(proxyConfig.host, proxyConfig.port)
VKFisher commented 1 year ago

Any updates on this?

UnknownNPC commented 1 year ago

+1 Proxy auth doesn't work on sttp3 (3.8.16) & sttp4 (v4.0.0-M2). It seems somehow related to the next comment: https://github.com/softwaremill/sttp/blob/fbc6f7e6ae222471fbae65c043bf6e15de74e84f/core/src/main/scalajvm/sttp/client4/httpclient/HttpClientBackend.scala#L128-L132

AlixBa commented 10 months ago

https://bugs.openjdk.org/browse/JDK-8229962

Adding

-Djdk.http.auth.tunneling.disabledSchemes=""
-Djdk.http.auth.proxying.disabledSchemes=""

to your JVM OPTS should work. At least it did for me (using Cats+HttpClient)