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

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

Open
aleksandr-vin opened this issue Jan 13, 2023 · 3 comments

Comments

@aleksandr-vin
Copy link
Contributor

aleksandr-vin commented Jan 13, 2023

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)
@aleksandr-vin aleksandr-vin changed the title java.lang.NullPointerException: flowPublisher in HttpClientZioBackend when using httpClient with proxy java.lang.NullPointerException: flowPublisher in HttpClientZioBackend when proxy requires authentication Jan 13, 2023
@VKFisher
Copy link

Any updates on this?

@UnknownNPC
Copy link

UnknownNPC commented Jul 14, 2023

+1
Proxy auth doesn't work on sttp3 (3.8.16) & sttp4 (v4.0.0-M2). It seems somehow related to the next comment:

// TODO not sure if it works
private class ProxyAuthenticator(auth: BackendOptions.ProxyAuth) extends Authenticator {
override def getPasswordAuthentication: PasswordAuthentication =
new PasswordAuthentication(auth.username, auth.password.toCharArray)
}

@AlixBa
Copy link

AlixBa commented Dec 21, 2023

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)

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

No branches or pull requests

4 participants