vertx-lang-kotlin icon indicating copy to clipboard operation
vertx-lang-kotlin copied to clipboard

sendForm method not working in VertX WebClient using Kotlin Coroutine verticle

Open JessengBijleng opened this issue 6 years ago • 7 comments

Hi,

I've encountered problems using a Kotlin Coroutine verticle. I want to make a simple post request using the VertX Webclient like so:

client.post(9443, "myurl", "/myendpoint").followRedirects(true).sendForm(form) {
   logger.debug(it.cause().toString())
}

The logger however is never reached, it looks like it's a specific problem for the CoroutineVerticle, when my Verticle extendes a AbstractVerticle i get results as expected. The following exception is thrown:

java.lang.NullPointerException
	at nl.ing.api.shepherd.verticle.BrokenClientVerticle$getAuth$1.handle(BrokenClientVerticle.kt:39)
	at nl.ing.api.shepherd.verticle.BrokenClientVerticle$getAuth$1.handle(BrokenClientVerticle.kt:18)
	at io.vertx.ext.web.client.impl.HttpContext.handleDispatchResponse(HttpContext.java:285)
	at io.vertx.ext.web.client.impl.HttpContext.execute(HttpContext.java:272)
	at io.vertx.ext.web.client.impl.HttpContext.next(HttpContext.java:250)
	at io.vertx.ext.web.client.impl.predicate.PredicateInterceptor.handle(PredicateInterceptor.java:69)
	at io.vertx.ext.web.client.impl.predicate.PredicateInterceptor.handle(PredicateInterceptor.java:32)
	at io.vertx.ext.web.client.impl.HttpContext.next(HttpContext.java:247)
	at io.vertx.ext.web.client.impl.HttpContext.fire(HttpContext.java:257)
	at io.vertx.ext.web.client.impl.HttpContext.dispatchResponse(HttpContext.java:218)
	at io.vertx.ext.web.client.impl.HttpContext.lambda$null$2(HttpContext.java:341)
	at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
	at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:466)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)

Using other send methods (like the default .send) also work as expected, it seems to be only the .sendform that's not working, using .sendForAwait makes the method wait infinitely, nothing is ever returned.

VertX Core, WebClient, Coroutine, version: 3.7.0 Kotlin Coroutine version: 1.2.0

JessengBijleng avatar Apr 19 '19 13:04 JessengBijleng

@gmariotti you tagged it as a bug, is this bug relatively easy to fix? I also have this issue and it's a combination of using web and a CoroutineVerticle.

Jofairden avatar Apr 29 '19 07:04 Jofairden

I'm actually getting this issue currently in an AbstractVerticle as well I narrowed it down to HttpContext, when it is trying to pipe the body stream:

                stream.pipeTo(req, (ar) -> {
                    if (ar.failed()) {
                        responseFuture.tryFail(ar.cause());
                        req.reset();
                    }

                });

It will complain with:

java.lang.NoSuchMethodError: io.vertx.core.streams.ReadStream.pipeTo(Lio/vertx/core/streams/WriteStream;Lio/vertx/core/Handler;)V

Which is part of Vertx.Core. When we look at the pipeTo method, we find a couple of definitions:

    void pipeTo(WriteStream<T> var1);

    void pipeTo(WriteStream<T> var1, Handler<AsyncResult<Void>> var2);

We are using the one with a handler for AsyncResult, but then why does it complain it cannot find the method? It should work because the request being piped is a WriteStream

It will transform the MultiMap into a io.vertx.ext.web.client.impl.MultipartFormUpload beforehand, is this correct behavior? Because this class has no implementation for the pipeTo methods. This is because this class implements io.vertx.core.streams.ReadStream<T>, but the pipeTo method is part of the reactive package: io.vertx.reactivex.core.streams.ReadStream<T>. Does the MultipartFormUpload maybe implement the wrong interface?

Edit: for some reason my vertx-core was outdated , it was using 3.6.3 when my other libraries were using 3.7.0 Doing a mvn clean install fixed the issues. I don't know about OP's issues, but it could be similar.

Jofairden avatar Apr 29 '19 13:04 Jofairden

Sorry @JessengBijleng, I didn't have enough time to check this bug. Did you look into @Jofairden latest post? If it's not a libraries version problem, can you create share a reproducer of it?

gmariotti avatar May 05 '19 06:05 gmariotti

Upgrading my version fixed it for AbstractVerticle but not for CoroutineVerticle. Maybe something was forgotten in the update for CoroutineVerticles?

Jofairden avatar May 05 '19 08:05 Jofairden

Hi @gmariotti, i don't feel like its an libraries version problem. So I just created a reproducer repository here: https://github.com/JessengBijleng/vertx-webclient-bug

JessengBijleng avatar May 13 '19 11:05 JessengBijleng

Hi @JessengBijleng, I just tried your project and it worked fine. I only had to change the status code check from 200 to 301 otherwise it would not print anything

gmariotti avatar May 16 '19 19:05 gmariotti

Hi @gmariotti, i'm sure I haven't created a good reproducer, didn't have enough time to look at it yet, I see this reproducer also uses different versions than the versions we used when the original problems occurred, my bad. I'll look into this later.

JessengBijleng avatar May 21 '19 08:05 JessengBijleng

Closing as outdated

tsegismont avatar Dec 08 '22 17:12 tsegismont