use of com.yahoo.elide.graphql.subscriptions.websocket.protocol.Complete in project elide by yahoo.
the class RequestHandler method safeSendComplete.
protected void safeSendComplete() {
log.debug("Sending Complete");
ObjectMapper mapper = elide.getElideSettings().getMapper().getObjectMapper();
Complete complete = Complete.builder().id(protocolID).build();
try {
sendMessage(mapper.writeValueAsString(complete));
} catch (JsonProcessingException e) {
log.error("UNEXPECTED Json Serialization Error {}", e.getMessage());
safeClose();
}
}
use of com.yahoo.elide.graphql.subscriptions.websocket.protocol.Complete in project elide by yahoo.
the class SessionHandler method handleRequest.
/**
* Handles an incoming graphql-ws protocol message.
* @param message The protocol message.
*/
public void handleRequest(String message) {
log.debug("Received Message: {} {}", wrappedSession.getId(), message);
try {
JsonNode type = mapper.readTree(message).get("type");
if (type == null) {
safeClose(INVALID_MESSAGE);
return;
}
MessageType messageType;
try {
messageType = MessageType.valueOf(type.textValue().toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
safeClose(INVALID_MESSAGE);
return;
}
switch(messageType) {
case PING:
{
handlePing();
return;
}
case PONG:
{
// Ignore
return;
}
case CONNECTION_INIT:
{
handleConnectionInit();
return;
}
case COMPLETE:
{
Complete complete = mapper.readValue(message, Complete.class);
handleComplete(complete);
return;
}
case SUBSCRIBE:
{
Subscribe subscribe = mapper.readValue(message, Subscribe.class);
handleSubscribe(subscribe);
return;
}
default:
{
safeClose(INVALID_MESSAGE);
return;
}
}
} catch (JsonProcessingException e) {
safeClose(INVALID_MESSAGE);
}
}
use of com.yahoo.elide.graphql.subscriptions.websocket.protocol.Complete in project elide by yahoo.
the class SubscriptionWebSocketTest method testSubscribeUnsubscribeSubscribe.
@Test
void testSubscribeUnsubscribeSubscribe() throws IOException {
SubscriptionWebSocket endpoint = SubscriptionWebSocket.builder().executorService(executorService).elide(elide).build();
ConnectionInit init = new ConnectionInit();
endpoint.onOpen(session);
endpoint.onMessage(session, mapper.writeValueAsString(init));
Subscribe subscribe = Subscribe.builder().id("1").payload(Subscribe.Payload.builder().query("subscription {book(topic: ADDED) {id title}}").build()).build();
endpoint.onMessage(session, mapper.writeValueAsString(subscribe));
Complete complete = Complete.builder().id("1").build();
endpoint.onMessage(session, mapper.writeValueAsString(complete));
endpoint.onMessage(session, mapper.writeValueAsString(subscribe));
List<String> expected = List.of("{\"type\":\"connection_ack\"}", "{\"type\":\"complete\",\"id\":\"1\"}", "{\"type\":\"complete\",\"id\":\"1\"}");
ArgumentCaptor<String> message = ArgumentCaptor.forClass(String.class);
verify(remote, times(3)).sendText(message.capture());
assertEquals(expected, message.getAllValues());
}
Aggregations