use of com.yahoo.elide.graphql.subscriptions.websocket.protocol.MessageType in project elide by yahoo.
the class SubscriptionWebSocketTestClient method onMessage.
@OnMessage
public void onMessage(String text) throws Exception {
JsonNode type = mapper.readTree(text).get("type");
MessageType messageType = MessageType.valueOf(type.textValue().toUpperCase(Locale.ROOT));
switch(messageType) {
case CONNECTION_ACK:
{
Integer id = 1;
for (String query : queries) {
Subscribe subscribe = Subscribe.builder().id(id.toString()).payload(Subscribe.Payload.builder().query(query).build()).build();
session.getBasicRemote().sendText(mapper.writeValueAsString(subscribe));
id++;
}
break;
}
case NEXT:
{
Next next = mapper.readValue(text, Next.class);
results.add(next.getPayload());
expectedNumberOfMessages--;
if (expectedNumberOfMessages <= 0) {
sessionLatch.countDown();
}
break;
}
case PING:
{
expectedNumberOfSubscribes--;
if (expectedNumberOfSubscribes <= 0) {
subscribeLatch.countDown();
}
break;
}
case ERROR:
{
Error error = mapper.readValue(text, Error.class);
log.error("ERROR: {}", error.getPayload());
sessionLatch.countDown();
break;
}
default:
{
break;
}
}
}
use of com.yahoo.elide.graphql.subscriptions.websocket.protocol.MessageType 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);
}
}
Aggregations