public void start(Future<Void> startFuture) { logger.info("[PacketDividerController-start()] START! > " + this.name); EventBus eb = vertx.eventBus(); PacketAnalyzer pa = new PacketAnalyzer(); eb.consumer( "PD_Trap" + remoteAddr, message -> { JsonObject jo = (JsonObject) message.body(); String recvMsg = jo.getString("recvPacket"); logger.debug(name_log + "PD_Trap, RECV[" + recvMsg.length() + "]> \n" + recvMsg); JsonObject paJo = new JsonObject(); paJo = pa.reqAnalyzePacket(recvMsg); logger.debug("paJo.size(): " + paJo.size()); // RESPONSE, to Target if (!paJo.isEmpty()) { logger.debug("nextCmd: " + paJo.getString("nextCmd")); String sendPacket = paJo.getString("sendPacket"); logger.debug("[sendData()] sendPacket: " + sendPacket); logger.debug(name_log + "PD_Trap, SEND> " + sendPacket); eb.send(remoteAddr + "Trap_ACK", sendPacket); } else { logger.debug(name_log + "PD_Trap, SEND> " + "NACK"); String sendPacket = "NACK"; eb.send(remoteAddr + "Trap_NACK", sendPacket); } }); }
private ExecutionResult<MessageResponse> validateAndInitialize() { if (message == null || !(message.body() instanceof JsonObject)) { LOGGER.error("Invalid message received, either null or body of message is not JsonObject "); return new ExecutionResult<>( MessageResponseFactory.createInvalidRequestResponse(), ExecutionResult.ExecutionStatus.FAILED); } userId = ((JsonObject) message.body()).getString(MessageConstants.MSG_USER_ID); if (!validateUser(userId)) { LOGGER.error("Invalid user id passed. Not authorized."); return new ExecutionResult<>( MessageResponseFactory.createForbiddenResponse(), ExecutionResult.ExecutionStatus.FAILED); } prefs = ((JsonObject) message.body()).getJsonObject(MessageConstants.MSG_KEY_PREFS); request = ((JsonObject) message.body()).getJsonObject(MessageConstants.MSG_HTTP_BODY); if (prefs == null || prefs.isEmpty()) { LOGGER.error("Invalid preferences obtained, probably not authorized properly"); return new ExecutionResult<>( MessageResponseFactory.createForbiddenResponse(), ExecutionResult.ExecutionStatus.FAILED); } if (request == null) { LOGGER.error("Invalid JSON payload on Message Bus"); return new ExecutionResult<>( MessageResponseFactory.createInvalidRequestResponse(), ExecutionResult.ExecutionStatus.FAILED); } // All is well, continue processing return new ExecutionResult<>(null, ExecutionResult.ExecutionStatus.CONTINUE_PROCESSING); }