From ed4f69ef207122d9d7178b76d75a37b05e92324f Mon Sep 17 00:00:00 2001 From: moshonk Date: Thu, 25 Jun 2020 00:23:32 +0300 Subject: [PATCH 1/9] Fixed issue of notifications not being sent to Lab --- pom.xml | 2 +- .../java/org/openhim/mediator/dsub/DsubActor.java | 2 +- .../mediator/dsub/service/DsubServiceImpl.java | 2 ++ .../subscription/SoapSubscriptionNotifier.java | 15 +++++++++------ .../mediator/messages/ITI53NotifyMessage.java | 7 ++----- .../ProvideAndRegisterOrchestrationActor.java | 2 +- .../mediator/orchestration/RepositoryActor.java | 2 ++ 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index e75196a..0c1c0e2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.openhim mediator-xds -1.0.3 +1.0.4-SNAPSHOT UTF-8 diff --git a/src/main/java/org/openhim/mediator/dsub/DsubActor.java b/src/main/java/org/openhim/mediator/dsub/DsubActor.java index 95b0d77..6d73783 100644 --- a/src/main/java/org/openhim/mediator/dsub/DsubActor.java +++ b/src/main/java/org/openhim/mediator/dsub/DsubActor.java @@ -65,7 +65,7 @@ public DsubActor(MediatorConfig config) { PullPointFactory pullPointFactory = new PullPointFactory(mongoDb); SubscriptionRepository subRepo = new MongoSubscriptionRepository(mongoDb, log); - SubscriptionNotifier subNotifier = new SoapSubscriptionNotifier(config); + SubscriptionNotifier subNotifier = new SoapSubscriptionNotifier(config, log); dsubService = new DsubServiceImpl(pullPointFactory, subRepo, subNotifier, log); diff --git a/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java b/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java index dc510ce..68290d4 100644 --- a/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java +++ b/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java @@ -49,7 +49,9 @@ public void notifyNewDocument(String docId, String facilityId) { List subscriptions = subscriptionRepository .findActiveSubscriptions(facilityId); + log.info("Active subscriptions: {}", subscriptions.size()); for (Subscription sub : subscriptions) { + log.info("URL: {}", sub.getUrl()); subscriptionNotifier.notifySubscription(sub, docId); } } diff --git a/src/main/java/org/openhim/mediator/dsub/subscription/SoapSubscriptionNotifier.java b/src/main/java/org/openhim/mediator/dsub/subscription/SoapSubscriptionNotifier.java index 685ec53..3c44e59 100644 --- a/src/main/java/org/openhim/mediator/dsub/subscription/SoapSubscriptionNotifier.java +++ b/src/main/java/org/openhim/mediator/dsub/subscription/SoapSubscriptionNotifier.java @@ -5,6 +5,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import akka.event.LoggingAdapter; + import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; @@ -17,10 +19,11 @@ public class SoapSubscriptionNotifier implements SubscriptionNotifier { private MediatorConfig config; - private static final Logger LOGGER = LoggerFactory.getLogger(SoapSubscriptionNotifier.class); + private final LoggingAdapter logA; - public SoapSubscriptionNotifier(MediatorConfig config) { + public SoapSubscriptionNotifier(MediatorConfig config, LoggingAdapter logA) { this.config = config; + this.logA = logA; } @Override @@ -36,7 +39,7 @@ public void notifySubscription(Subscription subscription, String documentId) { private void sendMessage(String url, byte[] body) { HttpURLConnection con = null; try { - + logA.info("Connecting to: {}", url); URL myurl = new URL(url); con = (HttpURLConnection) myurl.openConnection(); @@ -50,7 +53,7 @@ private void sendMessage(String url, byte[] body) { } StringBuilder content; - + try (BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream()))) { @@ -63,9 +66,9 @@ private void sendMessage(String url, byte[] body) { } } - System.out.println(content.toString()); + logA.info(content.toString()); } catch (IOException exception) { - LOGGER.error(exception.getMessage()); + logA.error(exception, exception.getMessage()); } finally { con.disconnect(); } diff --git a/src/main/java/org/openhim/mediator/messages/ITI53NotifyMessage.java b/src/main/java/org/openhim/mediator/messages/ITI53NotifyMessage.java index 85da262..6299df9 100644 --- a/src/main/java/org/openhim/mediator/messages/ITI53NotifyMessage.java +++ b/src/main/java/org/openhim/mediator/messages/ITI53NotifyMessage.java @@ -11,9 +11,6 @@ public class ITI53NotifyMessage { private String documentId; private static final String TEMPLATE = - "------OPENHIM\n" + - "Content-Type: application/xop+xml; charset=utf-8; type=\"application/soap+xml\"\n" + - "\n" + "" + "" + "" + "" + - "" + - "------OPENHIM--"; + ""; public ITI53NotifyMessage(String recipientServerAddress, String brokerServerAddress, String documentId) { this.messageId = UUID.randomUUID().toString(); diff --git a/src/main/java/org/openhim/mediator/orchestration/ProvideAndRegisterOrchestrationActor.java b/src/main/java/org/openhim/mediator/orchestration/ProvideAndRegisterOrchestrationActor.java index 9129291..717c850 100644 --- a/src/main/java/org/openhim/mediator/orchestration/ProvideAndRegisterOrchestrationActor.java +++ b/src/main/java/org/openhim/mediator/orchestration/ProvideAndRegisterOrchestrationActor.java @@ -56,7 +56,7 @@ */ public class ProvideAndRegisterOrchestrationActor extends UntypedActor { - private static final String LAB_ORDER_FORMAT_CODE = "HL7/Lab 2.5"; + private static final String LAB_ORDER_FORMAT_CODE = "CDAR2/IHE 1.0"; LoggingAdapter log = Logging.getLogger(getContext().system(), this); private abstract class IdentifierMapping { diff --git a/src/main/java/org/openhim/mediator/orchestration/RepositoryActor.java b/src/main/java/org/openhim/mediator/orchestration/RepositoryActor.java index ac2760b..f1573f0 100644 --- a/src/main/java/org/openhim/mediator/orchestration/RepositoryActor.java +++ b/src/main/java/org/openhim/mediator/orchestration/RepositoryActor.java @@ -256,6 +256,7 @@ private void forwardRequestToRepository() { private void finalizeResponse(MediatorHTTPResponse response) { if (StringUtil.isNotBlank(labOrderDocumentId)) { + log.info("Notifying DBUS {}", labOrderDocumentId); NotifyNewDocument msg = new NotifyNewDocument(labOrderDocumentId); dsubActor.tell(msg, getSelf()); } @@ -273,6 +274,7 @@ public void onReceive(Object msg) throws Exception { } else if (msg instanceof OrchestrateProvideAndRegisterRequestResponse) { processProvideAndRegisterResponse((OrchestrateProvideAndRegisterRequestResponse) msg); } else if (msg instanceof MediatorHTTPResponse) { + log.info("Finalizing response"); finalizeResponse((MediatorHTTPResponse) msg); } else { unhandled(msg); From 10ecdb0945be7cfa0b81e20b21b4e703a8336c3c Mon Sep 17 00:00:00 2001 From: moshonk Date: Thu, 25 Jun 2020 23:03:36 +0300 Subject: [PATCH 2/9] Reverted the changes to the Lab order format --- .../orchestration/ProvideAndRegisterOrchestrationActor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/openhim/mediator/orchestration/ProvideAndRegisterOrchestrationActor.java b/src/main/java/org/openhim/mediator/orchestration/ProvideAndRegisterOrchestrationActor.java index 717c850..9129291 100644 --- a/src/main/java/org/openhim/mediator/orchestration/ProvideAndRegisterOrchestrationActor.java +++ b/src/main/java/org/openhim/mediator/orchestration/ProvideAndRegisterOrchestrationActor.java @@ -56,7 +56,7 @@ */ public class ProvideAndRegisterOrchestrationActor extends UntypedActor { - private static final String LAB_ORDER_FORMAT_CODE = "CDAR2/IHE 1.0"; + private static final String LAB_ORDER_FORMAT_CODE = "HL7/Lab 2.5"; LoggingAdapter log = Logging.getLogger(getContext().system(), this); private abstract class IdentifierMapping { From d556d7cf58531521bc02fd06cb62683d07fcdd2e Mon Sep 17 00:00:00 2001 From: moshonk Date: Thu, 25 Jun 2020 23:38:51 +0300 Subject: [PATCH 3/9] Auto update version number in mediator registration info to module version --- pom.xml | 10 ++++++++++ .../mediator-registration-info.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) rename src/main/{resources => resources-filtered}/mediator-registration-info.json (96%) diff --git a/pom.xml b/pom.xml index 0c1c0e2..595101e 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,16 @@ + + + src/main/resources-filtered + true + + + src/main/resources + false + + diff --git a/src/main/resources/mediator-registration-info.json b/src/main/resources-filtered/mediator-registration-info.json similarity index 96% rename from src/main/resources/mediator-registration-info.json rename to src/main/resources-filtered/mediator-registration-info.json index 4003eff..fca5ede 100644 --- a/src/main/resources/mediator-registration-info.json +++ b/src/main/resources-filtered/mediator-registration-info.json @@ -1,6 +1,6 @@ { "urn": "urn:mediator:xds", - "version": "1.0.2-SNAPSHOT", + "version": "${version}", "name": "OpenHIE XDS.b Mediator", "description": "An XDS.b mediator for OpenHIE integration", "endpoints": [ From 612e9381e9053b7f02c667916598d13b4c8c6944 Mon Sep 17 00:00:00 2001 From: moshonk Date: Wed, 2 Sep 2020 01:15:51 +0300 Subject: [PATCH 4/9] Added check for invalid URLs before registering a subscription --- .../org/openhim/mediator/dsub/DsubActor.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openhim/mediator/dsub/DsubActor.java b/src/main/java/org/openhim/mediator/dsub/DsubActor.java index 6d73783..a79f41b 100644 --- a/src/main/java/org/openhim/mediator/dsub/DsubActor.java +++ b/src/main/java/org/openhim/mediator/dsub/DsubActor.java @@ -39,6 +39,8 @@ import javax.xml.ws.wsaddressing.W3CEndpointReference; import java.io.IOException; import java.lang.reflect.Field; +import java.net.URL; +import java.net.URI; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -149,7 +151,11 @@ private void handleSubscriptionMessage(Subscribe subscribeRequest) { } } } - dsubService.createSubscription(uri, null, terminationDate); + if (parseUrl(uri) != null) { + dsubService.createSubscription(uri, null, terminationDate); + } else { + log.error("Subscription not registered. Invalid url: " + uri); + } } private Object parseMessage(MediatorHTTPRequest request) { @@ -172,4 +178,15 @@ private T getProperty(Object object, String name) { throw new RuntimeException("Unable to read field: " + name, e); } } + + private URL parseUrl(String url) { + try { + URI uri = new URL(url).toURI(); + return uri.toURL(); + } + catch (Exception e) { + return null; + } + } + } } From 7d37581fbae9aa041d9abb29c7e7201dc48284f9 Mon Sep 17 00:00:00 2001 From: moshonk Date: Wed, 2 Sep 2020 01:41:14 +0300 Subject: [PATCH 5/9] bug fix: removed extra brace --- .../org/openhim/mediator/dsub/DsubActor.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/openhim/mediator/dsub/DsubActor.java b/src/main/java/org/openhim/mediator/dsub/DsubActor.java index a79f41b..6def2c2 100644 --- a/src/main/java/org/openhim/mediator/dsub/DsubActor.java +++ b/src/main/java/org/openhim/mediator/dsub/DsubActor.java @@ -180,13 +180,12 @@ private T getProperty(Object object, String name) { } private URL parseUrl(String url) { - try { - URI uri = new URL(url).toURI(); - return uri.toURL(); - } - catch (Exception e) { - return null; - } - } - } -} + try { + URI uri = new URL(url).toURI(); + return uri.toURL(); + } + catch (Exception e) { + return null; + } + } +} \ No newline at end of file From 576b646bb90fcc4cb0b9a2f50dd025627d4aa4c8 Mon Sep 17 00:00:00 2001 From: moshonk Date: Wed, 2 Sep 2020 02:00:47 +0300 Subject: [PATCH 6/9] Check for existing subscription Added check for an existing subsription during registration to prevent duplicates --- .../mediator/dsub/service/DsubService.java | 2 ++ .../dsub/service/DsubServiceImpl.java | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openhim/mediator/dsub/service/DsubService.java b/src/main/java/org/openhim/mediator/dsub/service/DsubService.java index 4e2c288..c148410 100644 --- a/src/main/java/org/openhim/mediator/dsub/service/DsubService.java +++ b/src/main/java/org/openhim/mediator/dsub/service/DsubService.java @@ -14,4 +14,6 @@ public interface DsubService { void newDocumentForPullPoint(String docId, String facilityId); List getDocumentsForPullPoint(String facilityId); + + Boolean subscriptionExists(String url, String facility) } diff --git a/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java b/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java index 68290d4..6438e81 100644 --- a/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java +++ b/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java @@ -35,7 +35,11 @@ public void createSubscription(String url, String facilityQuery, Date terminateA Subscription subscription = new Subscription(url, terminateAt, facilityQuery); - subscriptionRepository.saveSubscription(subscription); + if (subscriptionExists(url, facilityQuery) == false) { + subscriptionRepository.saveSubscription(subscription); + } else { + log.error("unable to create subscription. Another one already exists for: " + url); + } } @Override @@ -67,4 +71,22 @@ public List getDocumentsForPullPoint(String locationId) { PullPoint pullPoint = pullPointFactory.get(locationId); return pullPoint.getDocumentIds(); } + + @Override + public Boolean subscriptionExists(String url, String facility) { + Boolean subcriptionFound = false; + List subscriptions = subscriptionRepository + .findActiveSubscriptions(facility); + + log.info("Active subscriptions: {}", subscriptions.size()); + for (Subscription sub : subscriptions) { + log.info("URL: {}", sub.getUrl()); + if (url.equals(sub.getUrl())) { + subcriptionFound = true; + break; + } + } + + return subcriptionFound; + } } From 5b3d87a8c248cf9e6b6c85c713c0f6597ad5f55e Mon Sep 17 00:00:00 2001 From: moshonk Date: Wed, 2 Sep 2020 02:10:05 +0300 Subject: [PATCH 7/9] Bug fix: missing semi-colon --- .../java/org/openhim/mediator/dsub/service/DsubService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/openhim/mediator/dsub/service/DsubService.java b/src/main/java/org/openhim/mediator/dsub/service/DsubService.java index c148410..930f6b6 100644 --- a/src/main/java/org/openhim/mediator/dsub/service/DsubService.java +++ b/src/main/java/org/openhim/mediator/dsub/service/DsubService.java @@ -15,5 +15,5 @@ public interface DsubService { List getDocumentsForPullPoint(String facilityId); - Boolean subscriptionExists(String url, String facility) + Boolean subscriptionExists(String url, String facility); } From 6025cca92a919ec3ef47b47a260129cdbb71f0bb Mon Sep 17 00:00:00 2001 From: moshonk Date: Wed, 2 Sep 2020 02:42:15 +0300 Subject: [PATCH 8/9] Catch subscriptions processing error Catch error that prevents processing of subsequent subscriptions when one of them fails --- .../org/openhim/mediator/dsub/service/DsubServiceImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java b/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java index 6438e81..b13b7c2 100644 --- a/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java +++ b/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java @@ -56,7 +56,12 @@ public void notifyNewDocument(String docId, String facilityId) { log.info("Active subscriptions: {}", subscriptions.size()); for (Subscription sub : subscriptions) { log.info("URL: {}", sub.getUrl()); - subscriptionNotifier.notifySubscription(sub, docId); + + try { + subscriptionNotifier.notifySubscription(sub, docId); + } catch (Exception ex) { + log.error("Error occured while sending subscription. Unable to notify subscriber: " + uri); + } } } From b632477c1816d52212e597ca44d103df877f340f Mon Sep 17 00:00:00 2001 From: moshonk Date: Wed, 2 Sep 2020 02:51:47 +0300 Subject: [PATCH 9/9] bug fix logging mesage --- .../java/org/openhim/mediator/dsub/service/DsubServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java b/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java index b13b7c2..7ef2352 100644 --- a/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java +++ b/src/main/java/org/openhim/mediator/dsub/service/DsubServiceImpl.java @@ -60,7 +60,7 @@ public void notifyNewDocument(String docId, String facilityId) { try { subscriptionNotifier.notifySubscription(sub, docId); } catch (Exception ex) { - log.error("Error occured while sending subscription. Unable to notify subscriber: " + uri); + log.error("Error occured while sending notification. Unable to notify subscriber: " + sub.getUrl()); } } }