我在 Hasura 中有一个 graphlQL 客户端(在 docker 实例上运行),我想从顶点访问它。
以下是我的代码:
public class MyFirstVerticle extends AbstractVerticle {
@Override
public void start(Future<Void> fut) {
WebClient client = WebClient.create(vertx);
JsonObject request = new JsonObject().put("query", "query { user { username } }");
client.post(8080, "http://192.168.99.100","/v1/graphql")
.putHeader("content-type", "application/json")
.putHeader("x-hasura-admin-secret","somekey")
.expect(ResponsePredicate.SC_OK)
.expect(ResponsePredicate.JSON)
.as(BodyCodec.jsonObject()).
sendJsonObject(request, ar -> {
if (ar.succeeded()) {
JsonObject response = ar.result().body();
System.out.println("response = " + response.encodePrettily());
} else {
ar.cause().printStackTrace();
}
});
}
}
但我得到以下异常:
[INFO] SEVERE: Failed in deploying verticle
[INFO] java.lang.IllegalAccessError: tried to access method io.vertx.core.http.impl.HttpClientImpl.getVertx()Lio/vertx/core/impl/VertxInternal; from class io.vertx.ext.web.client.impl.WebClientBase
[INFO] at io.vertx.ext.web.client.impl.WebClientBase.createContext(WebClientBase.java:288)
[INFO] at io.vertx.ext.web.client.impl.HttpRequestImpl.send(HttpRequestImpl.java:330)
[INFO] at io.vertx.ext.web.client.impl.HttpRequestImpl.sendJsonObject(HttpRequestImpl.java:311)
[INFO] at ooxaam.io.justgifit.vertx.MyFirstVerticle.start(MyFirstVerticle.java:35)
[INFO] at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$10(DeploymentManager.java:481)
[INFO] at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:344)
[INFO] at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
[INFO] at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
[INFO] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
[INFO] at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
[INFO] at java.lang.Thread.run(Thread.java:745)
我被卡住了,知道这里出了什么问题。