vert-x3 / vertx-examples

Vert.x examples
Apache License 2.0
3.55k stars 2.09k forks source link

java.lang.IllegalAccessError: when accessing GraphQL API from vertx #394

Closed ooxaam closed 4 years ago

ooxaam commented 4 years ago

I have a graphlQL client in Hasura (running on docker instance), which I want to access from vertex.

As per given example, following is my code:

@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();
                    }
                });
    }

But I'm getting following exception:

[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)
tsegismont commented 4 years ago

Sounds like incompatible versions of Vert.x Web and Vert.x core are on the classpath. Let's continue the conversation on SO