Add support for websocket subscriptions
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package ca.uhn.fhir.jpa.starter;
|
||||
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
public class ApplicationContext extends AnnotationConfigWebApplicationContext {
|
||||
|
||||
public ApplicationContext() {
|
||||
FhirVersionEnum fhirVersion = HapiProperties.getFhirVersion();
|
||||
if (fhirVersion == FhirVersionEnum.DSTU2) {
|
||||
register(FhirServerConfigDstu2.class, FhirServerConfigCommon.class);
|
||||
} else if (fhirVersion == FhirVersionEnum.DSTU3) {
|
||||
register(FhirServerConfigDstu3.class, FhirServerConfigCommon.class);
|
||||
} else if (fhirVersion == FhirVersionEnum.R4) {
|
||||
register(FhirServerConfigR4.class, FhirServerConfigCommon.class);
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
if (HapiProperties.getSubscriptionWebsocketEnabled()) {
|
||||
register(ca.uhn.fhir.jpa.config.WebsocketDispatcherConfig.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -53,18 +53,21 @@ public class FhirServerConfigCommon {
|
||||
retVal.setFetchSizeDefaultMaximum(maxFetchSize);
|
||||
ourLog.info("Server configured to have a maximum fetch size of " + (maxFetchSize == Integer.MAX_VALUE? "'unlimited'": maxFetchSize));
|
||||
|
||||
// You can enable these if you want to support Subscriptions from your server
|
||||
// Subscriptions are enabled by channel type
|
||||
if (HapiProperties.getSubscriptionRestHookEnabled()) {
|
||||
ourLog.info("Enabling REST-hook subscriptions");
|
||||
retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.RESTHOOK);
|
||||
}
|
||||
|
||||
if (HapiProperties.getSubscriptionEmailEnabled()) {
|
||||
ourLog.info("Enabling email subscriptions");
|
||||
retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.EMAIL);
|
||||
}
|
||||
if (HapiProperties.getSubscriptionWebsocketEnabled()) {
|
||||
ourLog.info("Enabling websocket subscriptions");
|
||||
retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.WEBSOCKET);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -18,6 +18,7 @@ public class FhirServerConfigR4 extends BaseJavaConfigR4 {
|
||||
@Autowired
|
||||
private DataSource myDataSource;
|
||||
|
||||
|
||||
/**
|
||||
* We override the paging provider definition so that we can customize
|
||||
* the default/max page sizes for search results. You can set these however
|
||||
|
||||
@@ -38,6 +38,7 @@ public class HapiProperties {
|
||||
static final String SERVER_NAME = "server.name";
|
||||
static final String SUBSCRIPTION_EMAIL_ENABLED = "subscription.email.enabled";
|
||||
static final String SUBSCRIPTION_RESTHOOK_ENABLED = "subscription.resthook.enabled";
|
||||
static final String SUBSCRIPTION_WEBSOCKET_ENABLED = "subscription.websocket.enabled";
|
||||
static final String TEST_PORT = "test.port";
|
||||
|
||||
private static Properties properties;
|
||||
@@ -234,11 +235,11 @@ public class HapiProperties {
|
||||
}
|
||||
|
||||
public static Boolean getAllowMultipleDelete() {
|
||||
return HapiProperties.getBooleanProperty(ALLOW_MULTIPLE_DELETE, true);
|
||||
return HapiProperties.getBooleanProperty(ALLOW_MULTIPLE_DELETE, false);
|
||||
}
|
||||
|
||||
public static Boolean getAllowExternalReferences() {
|
||||
return HapiProperties.getBooleanProperty(ALLOW_EXTERNAL_REFERENCES, true);
|
||||
return HapiProperties.getBooleanProperty(ALLOW_EXTERNAL_REFERENCES, false);
|
||||
}
|
||||
|
||||
public static Boolean getExpungeEnabled() {
|
||||
@@ -266,10 +267,14 @@ public class HapiProperties {
|
||||
}
|
||||
|
||||
public static Boolean getSubscriptionEmailEnabled() {
|
||||
return HapiProperties.getBooleanProperty(SUBSCRIPTION_EMAIL_ENABLED, true);
|
||||
return HapiProperties.getBooleanProperty(SUBSCRIPTION_EMAIL_ENABLED, false);
|
||||
}
|
||||
|
||||
public static Boolean getSubscriptionRestHookEnabled() {
|
||||
return HapiProperties.getBooleanProperty(SUBSCRIPTION_RESTHOOK_ENABLED, true);
|
||||
return HapiProperties.getBooleanProperty(SUBSCRIPTION_RESTHOOK_ENABLED, false);
|
||||
}
|
||||
|
||||
public static Boolean getSubscriptionWebsocketEnabled() {
|
||||
return HapiProperties.getBooleanProperty(SUBSCRIPTION_WEBSOCKET_ENABLED, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
|
||||
import ca.uhn.fhir.jpa.model.interceptor.api.IInterceptorRegistry;
|
||||
import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2;
|
||||
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
|
||||
import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider;
|
||||
@@ -14,6 +15,8 @@ import ca.uhn.fhir.jpa.provider.r4.JpaConformanceProviderR4;
|
||||
import ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4;
|
||||
import ca.uhn.fhir.jpa.provider.r4.TerminologyUploaderProviderR4;
|
||||
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
||||
import ca.uhn.fhir.jpa.subscription.SubscriptionActivatingInterceptor;
|
||||
import ca.uhn.fhir.jpa.subscription.SubscriptionMatcherInterceptor;
|
||||
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
|
||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||
import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
|
||||
@@ -22,7 +25,7 @@ import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
|
||||
import org.hl7.fhir.dstu3.model.Bundle;
|
||||
import org.hl7.fhir.dstu3.model.Meta;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.util.List;
|
||||
@@ -30,12 +33,6 @@ import java.util.List;
|
||||
public class JpaRestfulServer extends RestfulServer {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private AnnotationConfigApplicationContext appCtx;
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
appCtx.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@@ -46,27 +43,25 @@ public class JpaRestfulServer extends RestfulServer {
|
||||
* Create a FhirContext object that uses the version of FHIR
|
||||
* specified in the properties file.
|
||||
*/
|
||||
FhirVersionEnum fhirVersion = HapiProperties.getFhirVersion();
|
||||
appCtx = new AnnotationConfigApplicationContext();
|
||||
ApplicationContext appCtx = (ApplicationContext) getServletContext().getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
|
||||
|
||||
// if (HapiProperties.getSubscriptionWebsocketEnabled()) {
|
||||
// appCtx.register(WebsocketDispatcherConfig.class);
|
||||
// }
|
||||
|
||||
/*
|
||||
* ResourceProviders are fetched from the Spring context
|
||||
*/
|
||||
FhirVersionEnum fhirVersion = HapiProperties.getFhirVersion();
|
||||
List<IResourceProvider> resourceProviders;
|
||||
Object systemProvider;
|
||||
if (fhirVersion == FhirVersionEnum.DSTU2) {
|
||||
appCtx.register(FhirServerConfigDstu2.class, FhirServerConfigCommon.class);
|
||||
appCtx.refresh();
|
||||
resourceProviders = appCtx.getBean("myResourceProvidersDstu2", List.class);
|
||||
systemProvider = appCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class);
|
||||
} else if (fhirVersion == FhirVersionEnum.DSTU3) {
|
||||
appCtx.register(FhirServerConfigDstu3.class, FhirServerConfigCommon.class);
|
||||
appCtx.refresh();
|
||||
resourceProviders = appCtx.getBean("myResourceProvidersDstu3", List.class);
|
||||
systemProvider = appCtx.getBean("mySystemProviderDstu3", JpaSystemProviderDstu3.class);
|
||||
} else if (fhirVersion == FhirVersionEnum.R4) {
|
||||
appCtx.register(FhirServerConfigR4.class, FhirServerConfigCommon.class);
|
||||
appCtx.refresh();
|
||||
resourceProviders = appCtx.getBean("myResourceProvidersR4", List.class);
|
||||
systemProvider = appCtx.getBean("mySystemProviderR4", JpaSystemProviderR4.class);
|
||||
} else {
|
||||
@@ -174,6 +169,23 @@ public class JpaRestfulServer extends RestfulServer {
|
||||
SubscriptionTriggeringProvider retriggeringProvider = appCtx.getBean(SubscriptionTriggeringProvider.class);
|
||||
registerProvider(retriggeringProvider);
|
||||
}
|
||||
|
||||
// If subscriptions are enabled, we want to register the interceptor that
|
||||
// will activate them and match results against them
|
||||
if (HapiProperties.getSubscriptionWebsocketEnabled() ||
|
||||
HapiProperties.getSubscriptionEmailEnabled() ||
|
||||
HapiProperties.getSubscriptionRestHookEnabled()) {
|
||||
IInterceptorRegistry interceptorRegistry = appCtx.getBean(IInterceptorRegistry.class);
|
||||
|
||||
SubscriptionActivatingInterceptor subscriptionActivatingInterceptor = appCtx.getBean(SubscriptionActivatingInterceptor.class);
|
||||
interceptorRegistry.registerInterceptor(subscriptionActivatingInterceptor);
|
||||
|
||||
SubscriptionMatcherInterceptor subscriptionMatcherInterceptor = appCtx.getBean(SubscriptionMatcherInterceptor.class);
|
||||
subscriptionMatcherInterceptor.start();
|
||||
interceptorRegistry.registerInterceptor(subscriptionMatcherInterceptor);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,3 +61,6 @@ subscription.resthook.enabled=true
|
||||
|
||||
# Enable Email Subscription Channel
|
||||
subscription.email.enabled=false
|
||||
|
||||
# Enable Websocket Subscription Channel
|
||||
subscription.websocket.enabled=false
|
||||
|
||||
@@ -5,23 +5,20 @@
|
||||
metadata-complete="false"
|
||||
version="3.1">
|
||||
|
||||
<!--
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
<context-param>
|
||||
<param-name>contextClass</param-name>
|
||||
<param-value>
|
||||
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
|
||||
ca.uhn.fhir.jpa.starter.ApplicationContext
|
||||
</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>
|
||||
ca.uhn.fhir.jpa.starter.FhirServerConfig
|
||||
</param-value>
|
||||
</context-param>
|
||||
-->
|
||||
|
||||
<!-- Servlets -->
|
||||
<servlet>
|
||||
@@ -33,7 +30,9 @@
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>ca.uhn.fhir.jpa.starter.FhirTesterConfig</param-value>
|
||||
<param-value>
|
||||
ca.uhn.fhir.jpa.starter.FhirTesterConfig,
|
||||
</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
Reference in New Issue
Block a user