diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/3482-unsupported-channel-type-bad-error-messag.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/3482-unsupported-channel-type-bad-error-messag.yaml new file mode 100644 index 00000000000..4336c1b5f1e --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/3482-unsupported-channel-type-bad-error-messag.yaml @@ -0,0 +1,4 @@ +type: fix +issue: 3482 +jira: SMILE-5076 +title: "Previously, persistence modules were attempting to activate subscriptions that used channel types they did not support. This has been changed, and those subscriptions will not be activated if the given channel type is not supported" diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java index 0507d1a5993..0db6757cfce 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java @@ -32,6 +32,7 @@ import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.SubscriptionUtil; +import org.hl7.fhir.dstu2.model.Subscription; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -144,4 +145,9 @@ public class SubscriptionActivatingSubscriber extends BaseSubscriberForSubscript } } + public boolean isChannelTypeSupported(IBaseResource theSubscription) { + Subscription.SubscriptionChannelType channelType = mySubscriptionCanonicalizer.getChannelType(theSubscription).toCanonical(); + return myDaoConfig.getSupportedSubscriptionTypes().contains(channelType); + } + } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/registry/SubscriptionLoader.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/registry/SubscriptionLoader.java index 35e06522741..6f5b179e859 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/registry/SubscriptionLoader.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/registry/SubscriptionLoader.java @@ -228,14 +228,24 @@ public class SubscriptionLoader implements IResourceChangeListener { * @return true if activated */ private boolean activateSubscriptionIfRequested(IBaseResource theSubscription) { + boolean successfullyActivated = false; + if (SubscriptionConstants.REQUESTED_STATUS.equals(mySubscriptionCanonicalizer.getSubscriptionStatus(theSubscription))) { - // internally, subscriptions that cannot activate will be set to error - if (mySubscriptionActivatingInterceptor.activateSubscriptionIfRequired(theSubscription)) { - return true; + if (mySubscriptionActivatingInterceptor.isChannelTypeSupported(theSubscription)) { + // internally, subscriptions that cannot activate will be set to error + if (mySubscriptionActivatingInterceptor.activateSubscriptionIfRequired(theSubscription)) { + successfullyActivated = true; + } else { + logSubscriptionNotActivatedPlusErrorIfPossible(theSubscription); + } + } else { + ourLog.debug("Could not activate subscription {} because channel type {} is not supported.", + theSubscription.getIdElement(), + mySubscriptionCanonicalizer.getChannelType(theSubscription)); } - logSubscriptionNotActivatedPlusErrorIfPossible(theSubscription); } - return false; + + return successfullyActivated; } /** diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/registry/SubscriptionLoaderTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/registry/SubscriptionLoaderTest.java index 1a720a867b1..b0fe98e11f3 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/registry/SubscriptionLoaderTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/registry/SubscriptionLoaderTest.java @@ -134,6 +134,9 @@ public class SubscriptionLoaderTest { when(mySubscriptionActivatingInterceptor.activateSubscriptionIfRequired(any(IBaseResource.class))) .thenReturn(false); + when(mySubscriptionActivatingInterceptor.isChannelTypeSupported(any(IBaseResource.class))) + .thenReturn(true); + when(mySubscriptionCanonicalizer.getSubscriptionStatus(any())).thenReturn(SubscriptionConstants.REQUESTED_STATUS); // test