Can Vertx Web client synchronize

424 views
Skip to first unread message

crazyliu

unread,
Apr 25, 2017, 3:11:30 AM4/25/17
to vert.x
I'd like to nest Vert.x Web Client in Vertx-web and get the results.

Clement Escoffier

unread,
Apr 25, 2017, 8:40:37 AM4/25/17
to ve...@googlegroups.com
Hi,

Do you mean something like this:

package io.vertx.hello;

import io.vertx.core.AbstractVerticle;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.Router;

public class HelloVerticle extends AbstractVerticle {

WebClient client;

@Override
public void start() {
client = WebClient.create(vertx);
Router router = Router.router(vertx);
router.get("/").handler(this::getHelloMessage);
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}

private void getHelloMessage(RoutingContext routingContext) {
client.get(80, "perdu.com", "/")
.send(ar -> {
if (ar.succeeded()) {
routingContext.response().end(ar.result().bodyAsBuffer());
} else {
routingContext.fail(ar.cause());
}
});
}
}


Clement

On 25 Apr 2017, at 04:11, crazyliu <9143...@qq.com> wrote:

I'd like to nest Vert.x Web Client in Vertx-web and get the results.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/2a7d96a1-0adb-4f15-a8e6-092cc3c9806e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

crazyliu

unread,
Apr 26, 2017, 4:23:26 AM4/26/17
to vert.x
Thank you very much, I've tried your Java code.
But when I try to put it in the JavaScript, I fail, the request can't end, this is my Code:

   
var Router = require("vertx-web-js/router");
var LoggerHandler = require("vertx-web-js/logger_handler");
var BodyHandler = require("vertx-web-js/body_handler");
var WebClient = require("vertx-web-client-js/web_client");
var server = vertx.createHttpServer();
var client = WebClient.create(vertx);
var router = Router.router(vertx);
router.route().handler(LoggerHandler.create().handle);
router.route().handler(BodyHandler.create().handle);
router.post("/sendMessage").handler(function (ctx) {
 
client.post(80, "127.0.0.1", "/helloWorld").sendForm(ctx.request().params(), function (ar, ar_err) {
   
if (ar_err == null) {
     
console.log("Received response with status code: " + ar.statusCode() + " with body: " + ar.body());
      ctx
.response().end(ar.result().bodyAsBuffer());
   
} else {
     
console.log("Something went wrong: " + ar_err.getMessage());
      ctx
.fail(ar.cause());
   
}
 
});
});
server.requestHandler(router.accept).listen(8058);


在 2017年4月25日星期二 UTC+8下午8:40:37,clement escoffier写道:

Thomas SEGISMONT

unread,
May 3, 2017, 11:20:32 AM5/3/17
to ve...@googlegroups.com
Can you create a reproducer on GitHub ? Thanks

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

crazyliu

unread,
May 4, 2017, 2:07:51 AM5/4/17
to vert.x
Thanks for attention, the program has been successfully run, the error is due to the return value format

在 2017年5月3日星期三 UTC+8下午11:20:32,Thomas Segismont写道:
Reply all
Reply to author
Forward
0 new messages