0

I am studying vertx.io web client and I am already blocked doing a simple get... Uff. Here is what I put together (I am very new at vertx.io):

private void getUserEmail(String accessToken, Handler<AsyncResult<String>> handler) {
  String url = "https://graph.facebook.com/me";
  HttpRequest<JsonObject> req = webClient.get(url).as(BodyCodec.jsonObject());
  req.addQueryParam("access_token", accessToken);
  req.addQueryParam("fields", "name,email");
  MultiMap headers = req.headers();
  headers.set("Accept", "application/json");
  req.send(h -> {
    if (h.succeeded()) {
      log.info(h.result().toString());
      handler.handle(new FutureFactoryImpl().succeededFuture(h.result().bodyAsString()));
    } else {
      log.error(h.cause());
      handler.handle(new FutureFactoryImpl().failedFuture(h.cause()));
    }
  });
}

I think it should be enought but instead it's not. When I send request I get this error back:

io.vertx.core.json.DecodeException: Failed to decode: Unrecognized token 'Not': was expecting 'null', 'true', 'false' or NaN
at [Source: Not Found; line: 1, column: 4]

Of course if I do the same get by browser I get the expected data. I read the tutorial and examined the examples, what am I missing?

Francesco
  • 1,742
  • 5
  • 44
  • 78
  • 1
    looks like the `BodyCodec.jsonObject()` tries to parse something that isn't JSON. My guess is `Not authorized` ;) Print out the status code as well – Jochen Bedersdorfer Dec 09 '17 at 00:24
  • @JochenBedersdorfer response is `Not found`?! I have to figure out what kind of call am I doing with my client.. – Francesco Dec 09 '17 at 09:20
  • 1
    @Francesco by the way, you can replace `new FutureFactoryImpl()` just with `Future` from `io.vertx.core` package. – ledniov Dec 09 '17 at 17:23

1 Answers1

0

You're receiving a 404 error with the body: Not Found and the codec tries to parse it as JSON and fails. You need to verify if the request you're sending is correct.

Paulo Lopes
  • 5,845
  • 22
  • 31
  • Thank for your response. You are right, I'm going to debug that. But what's wrong with my code? What is the correct way to use the vertx.io httpclient? (P.S: vertx.io is awesome) – Francesco Dec 14 '17 at 13:44