Search in sources :

Example 31 with GraphQLMessage

use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.

the class GraphQLBrokerMessageHandlerTest method startMessage.

private Message<GraphQLMessage> startMessage(String operationId, String sessionId) {
    SimpMessageHeaderAccessor headerAccessor = simpHeaderAccessor(mockWebSocketSession(sessionId));
    Map<String, Object> json = new HashMap<>();
    json.put("query", "{}");
    json.put("variables", "{}");
    GraphQLMessage payload = new GraphQLMessage(operationId, GraphQLMessageType.START, json);
    return MessageBuilder.createMessage(payload, headerAccessor.getMessageHeaders());
}
Also used : HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor)

Example 32 with GraphQLMessage

use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.

the class GraphQLBrokerMessageHandlerTest method testHandleConnectionTerminateMessageCancelsSubscriber.

@Test
public void testHandleConnectionTerminateMessageCancelsSubscriber() {
    // given
    WebSocketSession session = mockWebSocketSession("sessionId");
    Message<GraphQLMessage> message = createDisconnectMessage(session);
    GraphQLBrokerChannelSubscriber subscriber = mock(GraphQLBrokerChannelSubscriber.class);
    GraphQLBrokerSubscriptionRegistry registry = messageHandler.getGraphQLsubscriptionRegistry();
    registry.subscribe("sessionId", "subscriptionId", subscriber);
    // when
    this.messageHandler.handleMessage(message);
    // then
    verify(subscriber).cancel();
}
Also used : GraphQLBrokerChannelSubscriber(org.activiti.cloud.services.notifications.graphql.ws.transport.GraphQLBrokerChannelSubscriber) GraphQLBrokerSubscriptionRegistry(org.activiti.cloud.services.notifications.graphql.ws.transport.GraphQLBrokerSubscriptionRegistry) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) WebSocketSession(org.springframework.web.socket.WebSocketSession) StandardWebSocketSession(org.springframework.web.socket.adapter.standard.StandardWebSocketSession) Test(org.junit.jupiter.api.Test)

Example 33 with GraphQLMessage

use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.

the class GraphQLBrokerChannelSubscriber method onComplete.

@Override
public void onComplete() {
    log.info("Subscription complete: {}", subscriptionRef.get());
    cancel();
    GraphQLMessage operationMessage = new GraphQLMessage(operationMessageId, GraphQLMessageType.COMPLETE);
    Message<?> responseMessage = MessageBuilder.createMessage(operationMessage, getMessageHeaders());
    outboundChannel.send(responseMessage);
}
Also used : GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage)

Example 34 with GraphQLMessage

use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.

the class GraphQLBrokerMessageHandler method handleStopSubscription.

@Timed
protected final void handleStopSubscription(Message<GraphQLMessage> message) {
    logger.info("handleStopSubscription for message " + message);
    MessageHeaders headers = message.getHeaders();
    String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
    GraphQLMessage operationPayload = message.getPayload();
    graphQLsubscriptionRegistry.unsubscribe(sessionId, operationPayload.getId(), (subscriber) -> {
        subscriber.onComplete();
    });
}
Also used : MessageHeaders(org.springframework.messaging.MessageHeaders) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Timed(com.codahale.metrics.annotation.Timed)

Example 35 with GraphQLMessage

use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.

the class GraphQLBrokerMessageHandler method handleConnectionInitMessage.

@Timed
protected final void handleConnectionInitMessage(Message<GraphQLMessage> message) {
    GraphQLMessage operationPayload = message.getPayload();
    GraphQLMessage connection_ack = new GraphQLMessage(operationPayload.getId(), GraphQLMessageType.CONNECTION_ACK);
    MessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.getMutableAccessor(message);
    Message<?> responseMessage = MessageBuilder.createMessage(connection_ack, headerAccessor.getMessageHeaders());
    getClientOutboundChannel().send(responseMessage);
}
Also used : SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

GraphQLMessage (org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage)35 Test (org.junit.jupiter.api.Test)14 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 WebsocketSender (reactor.netty.http.client.HttpClient.WebsocketSender)6 Date (java.util.Date)5 TextMessage (org.springframework.web.socket.TextMessage)5 ExecutionResult (graphql.ExecutionResult)4 Principal (java.security.Principal)4 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)4 WebSocketSession (org.springframework.web.socket.WebSocketSession)4 Timed (com.codahale.metrics.annotation.Timed)3 HashMap (java.util.HashMap)3 GraphQLMessageType (org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessageType)3 Message (org.springframework.messaging.Message)3 MessageHeaders (org.springframework.messaging.MessageHeaders)3 SimpMessageType (org.springframework.messaging.simp.SimpMessageType)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2