use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.
the class GraphQLBrokerMessageHandler method sendErrorMessageToClient.
private void sendErrorMessageToClient(String errorText, GraphQLMessageType type, Message<?> inputMessage) {
Map<String, Object> payload = Collections.singletonMap("errors", Collections.singletonList(errorText));
GraphQLMessage inputOperation = (GraphQLMessage) inputMessage.getPayload();
GraphQLMessage connectionError = new GraphQLMessage(inputOperation.getId(), type, payload);
MessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.getMutableAccessor(inputMessage);
Message<GraphQLMessage> errorMessage = MessageBuilder.createMessage(connectionError, headerAccessor.getMessageHeaders());
getClientOutboundChannel().send(errorMessage);
}
use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.
the class GraphQLBrokerMessageHandler method handleDisconnect.
private void handleDisconnect(String sessionId, Principal user, Message<?> origMessage) {
this.sessions.remove(sessionId);
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
accessor.setSessionId(sessionId);
accessor.setUser(user);
if (origMessage != null) {
accessor.setHeader(SimpMessageHeaderAccessor.DISCONNECT_MESSAGE_HEADER, origMessage);
}
initHeaders(accessor);
GraphQLMessage disconnect = new GraphQLMessage(null, GraphQLMessageType.CONNECTION_ERROR);
Message<GraphQLMessage> message = MessageBuilder.createMessage(disconnect, accessor.getMessageHeaders());
getClientOutboundChannel().send(message);
}
use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.
the class GraphQLBrokerMessageHandler method handleStartSubscription.
@Timed
protected final void handleStartSubscription(Message<GraphQLMessage> message) {
logger.info("handleStartSubscription for message " + message);
MessageHeaders headers = message.getHeaders();
String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
GraphQLMessage operationPayload = message.getPayload();
QueryParameters parameters = null;
try {
parameters = QueryParameters.from(operationPayload.getPayload());
} catch (Exception e) {
sendErrorMessageToClient(e.getMessage(), GraphQLMessageType.ERROR, message);
return;
}
ExecutionResult executionResult = graphQLSubscriptionExecutor.execute(parameters.getQuery(), parameters.getVariables());
if (executionResult.getErrors().isEmpty()) {
if (executionResult.getData() == null) {
sendErrorMessageToClient("Server error!", GraphQLMessageType.ERROR, message);
} else if (executionResult.getData() instanceof Publisher) {
Optional.of(executionResult.<Publisher<ExecutionResult>>getData()).ifPresent(data -> {
MessageChannel outboundChannel = getClientOutboundChannelForSession(sessionId);
GraphQLBrokerChannelSubscriber subscriber = new GraphQLBrokerChannelSubscriber(message, operationPayload.getId(), outboundChannel, bufferTimeSpanMs, bufferCount);
graphQLsubscriptionRegistry.subscribe(sessionId, operationPayload.getId(), subscriber, () -> {
data.subscribe(subscriber);
});
});
} else {
handleQueryOrMutation(operationPayload.getId(), executionResult, message);
}
} else {
Map<String, Object> payload = Collections.singletonMap("errors", executionResult.getErrors());
GraphQLMessage startSubscriptionMessage = message.getPayload();
GraphQLMessage startSubscriptionErrors = new GraphQLMessage(startSubscriptionMessage.getId(), GraphQLMessageType.ERROR, payload);
Message<GraphQLMessage> errorMessage = MessageBuilder.createMessage(startSubscriptionErrors, headers);
getClientOutboundChannel().send(errorMessage);
}
}
use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.
the class GraphQLBrokerSubProtocolHandlerTest method testHandleProtocolErrorMessageToClient.
@Test
public void testHandleProtocolErrorMessageToClient() throws IOException {
// given
WebSocketSession session = spy(mockWebSocketSession("sess1"));
doThrow(RuntimeException.class).when(session).sendMessage(any(TextMessage.class));
Message<GraphQLMessage> message = connectionAckMessage("operationId", session);
// when
testSubject.handleMessageToClient(session, message);
// then
verify(session).close(eq(CloseStatus.PROTOCOL_ERROR));
}
use of org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage in project activiti-cloud by Activiti.
the class GraphQLBrokerSubProtocolHandlerTest method connectionAckMessage.
private Message<GraphQLMessage> connectionAckMessage(String operationId, WebSocketSession session) {
SimpMessageHeaderAccessor headerAccessor = simpHeaderAccessor(session);
GraphQLMessage payload = new GraphQLMessage(operationId, GraphQLMessageType.CONNECTION_ACK);
return MessageBuilder.createMessage(payload, headerAccessor.getMessageHeaders());
}
Aggregations