Ignore invalid JSON-LD message
If the owner webapp client sends invalid JSON-LD, a message is logged
(little on info, more on debug), but the WS does not break any more
@@ -51,6 +51,7 @@ import won.protocol.message.WonMessageType;
import won.protocol.message.processor.WonMessageProcessor;
import won.protocol.model.NeedState;
import won.protocol.util.AuthenticationThreadLocal;
+import won.protocol.util.LoggingUtils;
import won.protocol.util.WonRdfUtils;
/**
@@ -165,7 +166,10 @@ public class WonWebSocketHandler extends TextWebSocketHandler implements WonMess
if (completePayload.equals(ECHO_STRING)) {
return;
}
- WonMessage wonMessage = WonMessageDecoder.decodeFromJsonLd(completePayload);
+ WonMessage wonMessage = null;
+ URI needUri = null;
+ try {
+ wonMessage = WonMessageDecoder.decodeFromJsonLd(completePayload);
// remember which user or (if not logged in) which needUri the session is bound
// to
User user = getUserForSession(session);
@@ -175,9 +179,17 @@ public class WonWebSocketHandler extends TextWebSocketHandler implements WonMess
}
// anyway, we have to bind the URI to the session, otherwise we can't handle
// incoming server->client messages
- URI needUri = wonMessage.getSenderNeedURI();
+ needUri = wonMessage.getSenderNeedURI();
logger.debug("binding session to need URI {}", needUri);
this.webSocketSessionService.addMapping(needUri, session);
+ } catch (Exception e) {
+ // ignore this message
+ LoggingUtils.logMessageAsInfoAndStacktraceAsDebug(logger, e,
+ "Ignoring WonMessage received via Websocket that caused an Exception");
+ WebSocketMessage<String> wsMsg = new TextMessage(
+ "{'error':'Error processing WonMessage: " + e.getMessage() + "'}");
+ return;
+ }
try {
AuthenticationThreadLocal.setAuthentication((Authentication) session.getPrincipal());
ownerApplicationService.sendWonMessage(wonMessage);
