Using vertx.io web client with no success

1.1k Views Asked by At

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?

1

There are 1 best solutions below

1
On

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.