From b71924ecaefd1f6011595e40670ad08e10558ea1 Mon Sep 17 00:00:00 2001 From: lathouwerssam Date: Thu, 22 Feb 2024 15:24:47 +0100 Subject: [PATCH 1/2] Check whether knowledge interaction id is unknown (i.e. null) in processPost/processAsk --- .../impl/InteractionProcessorImpl.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/InteractionProcessorImpl.java b/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/InteractionProcessorImpl.java index 61859e79..95ad817f 100644 --- a/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/InteractionProcessorImpl.java +++ b/smart-connector/src/main/java/eu/knowledge/engine/smartconnector/impl/InteractionProcessorImpl.java @@ -30,7 +30,6 @@ import org.apache.jena.vocabulary.RDF; import org.slf4j.Logger; -import eu.knowledge.engine.reasoner.BaseRule; import eu.knowledge.engine.reasoner.Rule; import eu.knowledge.engine.smartconnector.api.AnswerExchangeInfo; import eu.knowledge.engine.smartconnector.api.AnswerKnowledgeInteraction; @@ -203,6 +202,16 @@ public CompletableFuture processAskFromMessageRouter(AskMessage a KnowledgeInteractionInfo knowledgeInteractionById = this.myKnowledgeBaseStore .getKnowledgeInteractionById(answerKnowledgeInteractionId); + if (knowledgeInteractionById == null) { + AnswerMessage m = new AnswerMessage(anAskMsg.getToKnowledgeBase(), anAskMsg.getToKnowledgeInteraction(), + anAskMsg.getFromKnowledgeBase(), anAskMsg.getFromKnowledgeInteraction(), anAskMsg.getMessageId(), + "Received AskMessage wth unknown ToKnowledgeInteractionId"); + LOG.debug("Received AskMessage with unknown ToKnowledgeInteractionId: "+anAskMsg.getToKnowledgeInteraction().toString()); + CompletableFuture f = new CompletableFuture<>(); + f.complete(m); + return f; + } + AnswerKnowledgeInteraction answerKnowledgeInteraction; answerKnowledgeInteraction = (AnswerKnowledgeInteraction) knowledgeInteractionById.getKnowledgeInteraction(); @@ -305,6 +314,17 @@ public CompletableFuture processPostFromMessageRouter(PostMessage URI reactKnowledgeInteractionId = aPostMsg.getToKnowledgeInteraction(); KnowledgeInteractionInfo knowledgeInteractionById = this.myKnowledgeBaseStore .getKnowledgeInteractionById(reactKnowledgeInteractionId); + + if (knowledgeInteractionById == null) { + ReactMessage m = new ReactMessage(aPostMsg.getToKnowledgeBase(), aPostMsg.getToKnowledgeInteraction(), + aPostMsg.getFromKnowledgeBase(), aPostMsg.getFromKnowledgeInteraction(), aPostMsg.getMessageId(), + "Received PostMessage with unknown ToKnowledgeInteractionId"); + LOG.debug("Received PostMessage with unknown ToKnowledgeInteractionId: "+aPostMsg.getToKnowledgeInteraction().toString()); + CompletableFuture f = new CompletableFuture<>(); + f.complete(m); + return f; + } + ReactKnowledgeInteraction reactKnowledgeInteraction; reactKnowledgeInteraction = (ReactKnowledgeInteraction) knowledgeInteractionById.getKnowledgeInteraction(); From 070f6e78468ea9e47bf98629e6d4b24ae22de19f Mon Sep 17 00:00:00 2001 From: Barry Nouwt Date: Tue, 20 Feb 2024 14:30:26 +0100 Subject: [PATCH 2/2] Possibly fix the build bug. --- .../test/java/eu/knowledge/engine/rest/RestServerHelper.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/smart-connector-rest-dist/src/test/java/eu/knowledge/engine/rest/RestServerHelper.java b/smart-connector-rest-dist/src/test/java/eu/knowledge/engine/rest/RestServerHelper.java index e3bf04e6..06f3f2b6 100644 --- a/smart-connector-rest-dist/src/test/java/eu/knowledge/engine/rest/RestServerHelper.java +++ b/smart-connector-rest-dist/src/test/java/eu/knowledge/engine/rest/RestServerHelper.java @@ -36,6 +36,11 @@ public void run() { public void cleanUp() { thread.interrupt(); + try { + thread.join(); + } catch (InterruptedException e) { + LOG.info("Failed to join thread."); + } } private static boolean portAvailable(int port) {