Search in sources :

Example 1 with HeaderBuilder

use of io.smallrye.graphql.client.impl.typesafe.HeaderBuilder in project smallrye-graphql by smallrye.

the class VertxTypesafeGraphQLClientProxy method invoke.

Object invoke(MethodInvocation method) {
    if (method.isDeclaredInObject()) {
        return method.invoke(this);
    }
    MultiMap headers = HeadersMultiMap.headers().addAll(new HeaderBuilder(api, method, additionalHeaders).build());
    JsonObject request = request(method);
    if (method.getReturnType().isUni()) {
        if (executeSingleOperationsOverWebsocket) {
            return executeSingleResultOperationOverWebsocket(method, request);
        } else {
            return executeSingleResultOperationOverHttpAsync(method, request, headers);
        }
    } else if (method.getReturnType().isMulti()) {
        return executeSubscriptionOverWebsocket(method, request);
    } else {
        if (executeSingleOperationsOverWebsocket) {
            return executeSingleResultOperationOverWebsocket(method, request).await().indefinitely();
        } else {
            return executeSingleResultOperationOverHttpSync(method, request, headers);
        }
    }
}
Also used : MultiMap(io.vertx.core.MultiMap) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) HeaderBuilder(io.smallrye.graphql.client.impl.typesafe.HeaderBuilder) JsonObject(javax.json.JsonObject)

Example 2 with HeaderBuilder

use of io.smallrye.graphql.client.impl.typesafe.HeaderBuilder in project smallrye-graphql by smallrye.

the class VertxTypesafeGraphQLClientProxy method webSocketHandler.

private Uni<WebSocketSubprotocolHandler> webSocketHandler() {
    return webSocketHandler.updateAndGet(currentValue -> {
        if (currentValue == null) {
            return Uni.createFrom().<WebSocketSubprotocolHandler>emitter(handlerEmitter -> {
                List<String> subprotocolIds = subprotocols.stream().map(i -> i.getProtocolId()).collect(toList());
                MultiMap headers = HeadersMultiMap.headers().addAll(new HeaderBuilder(api, null, additionalHeaders).build());
                httpClient.webSocketAbs(websocketUrl, headers, WebsocketVersion.V13, subprotocolIds, result -> {
                    if (result.succeeded()) {
                        WebSocket webSocket = result.result();
                        WebSocketSubprotocolHandler handler = BuiltinWebsocketSubprotocolHandlers.createHandlerFor(webSocket.subProtocol(), webSocket, subscriptionInitializationTimeout, () -> {
                            webSocketHandler.set(null);
                        });
                        handlerEmitter.complete(handler);
                        log.debug("Using websocket subprotocol handler: " + handler);
                    } else {
                        handlerEmitter.fail(result.cause());
                    }
                });
            }).memoize().indefinitely();
        } else {
            return currentValue;
        }
    });
}
Also used : WebSocketSubprotocolHandler(io.smallrye.graphql.client.vertx.websocket.WebSocketSubprotocolHandler) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) JsonArrayBuilder(javax.json.JsonArrayBuilder) HttpResponse(io.vertx.ext.web.client.HttpResponse) WebClient(io.vertx.ext.web.client.WebClient) Date(java.util.Date) JsonBuilderFactory(javax.json.JsonBuilderFactory) Logger(org.jboss.logging.Logger) MultiMap(io.vertx.core.MultiMap) HashMap(java.util.HashMap) WebsocketVersion(io.vertx.core.http.WebsocketVersion) AtomicReference(java.util.concurrent.atomic.AtomicReference) Multi(io.smallrye.mutiny.Multi) ArrayList(java.util.ArrayList) Uni(io.smallrye.mutiny.Uni) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) JsonValue(javax.json.JsonValue) BigDecimal(java.math.BigDecimal) Map(java.util.Map) Json(javax.json.Json) MethodInvocation(io.smallrye.graphql.client.impl.typesafe.reflection.MethodInvocation) BigInteger(java.math.BigInteger) HeaderBuilder(io.smallrye.graphql.client.impl.typesafe.HeaderBuilder) URI(java.net.URI) InvalidResponseException(io.smallrye.graphql.client.InvalidResponseException) WebsocketSubprotocol(io.smallrye.graphql.client.websocket.WebsocketSubprotocol) JsonObject(javax.json.JsonObject) BuiltinWebsocketSubprotocolHandlers(io.smallrye.graphql.client.vertx.websocket.BuiltinWebsocketSubprotocolHandlers) FieldInfo(io.smallrye.graphql.client.impl.typesafe.reflection.FieldInfo) Collection(java.util.Collection) ResultBuilder(io.smallrye.graphql.client.impl.typesafe.ResultBuilder) JsonArray(javax.json.JsonArray) WebSocket(io.vertx.core.http.WebSocket) Future(io.vertx.core.Future) ExecutionException(java.util.concurrent.ExecutionException) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) Buffer(io.vertx.core.buffer.Buffer) QueryBuilder(io.smallrye.graphql.client.impl.typesafe.QueryBuilder) TypeInfo(io.smallrye.graphql.client.impl.typesafe.reflection.TypeInfo) JsonObjectBuilder(javax.json.JsonObjectBuilder) HttpClient(io.vertx.core.http.HttpClient) MultiMap(io.vertx.core.MultiMap) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) HeaderBuilder(io.smallrye.graphql.client.impl.typesafe.HeaderBuilder) WebSocketSubprotocolHandler(io.smallrye.graphql.client.vertx.websocket.WebSocketSubprotocolHandler) WebSocket(io.vertx.core.http.WebSocket)

Aggregations

HeaderBuilder (io.smallrye.graphql.client.impl.typesafe.HeaderBuilder)2 MultiMap (io.vertx.core.MultiMap)2 HeadersMultiMap (io.vertx.core.http.impl.headers.HeadersMultiMap)2 InvalidResponseException (io.smallrye.graphql.client.InvalidResponseException)1 QueryBuilder (io.smallrye.graphql.client.impl.typesafe.QueryBuilder)1 ResultBuilder (io.smallrye.graphql.client.impl.typesafe.ResultBuilder)1 FieldInfo (io.smallrye.graphql.client.impl.typesafe.reflection.FieldInfo)1 MethodInvocation (io.smallrye.graphql.client.impl.typesafe.reflection.MethodInvocation)1 TypeInfo (io.smallrye.graphql.client.impl.typesafe.reflection.TypeInfo)1 BuiltinWebsocketSubprotocolHandlers (io.smallrye.graphql.client.vertx.websocket.BuiltinWebsocketSubprotocolHandlers)1 WebSocketSubprotocolHandler (io.smallrye.graphql.client.vertx.websocket.WebSocketSubprotocolHandler)1 WebsocketSubprotocol (io.smallrye.graphql.client.websocket.WebsocketSubprotocol)1 Multi (io.smallrye.mutiny.Multi)1 Uni (io.smallrye.mutiny.Uni)1 Future (io.vertx.core.Future)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpClient (io.vertx.core.http.HttpClient)1 WebSocket (io.vertx.core.http.WebSocket)1 WebsocketVersion (io.vertx.core.http.WebsocketVersion)1 HttpResponse (io.vertx.ext.web.client.HttpResponse)1