package com.codingchili.logging.controller;

import com.codingchili.logging.configuration.LogContext;
import io.vertx.core.json.JsonObject;

import com.codingchili.core.protocol.Request;
import com.codingchili.core.protocol.Serializer;
import com.codingchili.core.protocol.exception.AuthorizationRequiredException;
import com.codingchili.core.security.Token;

import static com.codingchili.common.Strings.*;


/**
 * @author Robin Duda
 *
 * Log handler for messages incoming from clients.
 */
public class ClientLogHandler<T extends LogContext> extends AbstractLogHandler<T> {

    public ClientLogHandler(T context) {
        super(context, NODE_CLIENT_LOGGING);
    }

    @Override
    protected void log(Request request) {
        JsonObject logdata = request.data();

        if (verifyToken(logdata)) {
            logdata.remove(ID_TOKEN);
            logdata.remove(PROTOCOL_ROUTE);
            console.log(logdata);
            store.log(logdata);
        } else {
            request.error(new AuthorizationRequiredException());
        }
    }

    private boolean verifyToken(JsonObject logdata) {
        JsonObject token = (JsonObject) logdata.remove(ID_TOKEN);
        return context.verifyToken(Serializer.unpack(token, Token.class));
    }
}

@@ -1116,54 +1116,31 @@
     
-JsonObject token = (JsonObject) logdata.remove
+if (logdata.containsKey
 (ID_
@@ -1137,34 +1137,40 @@
 insKey(ID_TOKEN)
-;%0A
+) %7B%0A    
         return c
@@ -1210,29 +1210,108 @@
 ack(
-token, Token.class));
+logdata.getJsonObject(ID_TOKEN), Token.class));%0A        %7D else %7B%0A            return false;%0A        %7D
 %0A   

Check if payload contains token before deserializing in ClientLogHandler