diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/common/BinaryStorageInterceptorRegistrar.java b/src/main/java/ca/uhn/fhir/jpa/starter/common/BinaryStorageInterceptorRegistrar.java new file mode 100644 index 0000000..79b5134 --- /dev/null +++ b/src/main/java/ca/uhn/fhir/jpa/starter/common/BinaryStorageInterceptorRegistrar.java @@ -0,0 +1,41 @@ +package ca.uhn.fhir.jpa.starter.common; + +import ca.uhn.fhir.IHapiBootOrder; +import ca.uhn.fhir.interceptor.api.IInterceptorService; +import ca.uhn.fhir.jpa.binary.interceptor.BinaryStorageInterceptor; +import ca.uhn.fhir.jpa.starter.AppProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +@Component +public class BinaryStorageInterceptorRegistrar { + private static final Logger ourLog = LoggerFactory.getLogger(BinaryStorageInterceptorRegistrar.class); + + private final IInterceptorService myInterceptorService; + private final BinaryStorageInterceptor myBinaryStorageInterceptor; + private final AppProperties myAppProperties; + + public BinaryStorageInterceptorRegistrar( + IInterceptorService theInterceptorService, + BinaryStorageInterceptor theBinaryStorageInterceptor, + AppProperties theAppProperties) { + myInterceptorService = theInterceptorService; + myBinaryStorageInterceptor = theBinaryStorageInterceptor; + myAppProperties = theAppProperties; + } + + @EventListener(classes = {ContextRefreshedEvent.class}) + @Order(IHapiBootOrder.REGISTER_INTERCEPTORS) + public void register() { + if (!myAppProperties.getBinary_storage_enabled()) { + ourLog.debug("Binary storage disabled; skipping BinaryStorageInterceptor registration"); + return; + } + ourLog.info("Registering BinaryStorageInterceptor with JPA interceptor service"); + myInterceptorService.registerInterceptor(myBinaryStorageInterceptor); + } +} diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.java b/src/main/java/ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.java index 1e3bc6a..86e4793 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/common/StarterJpaConfig.java @@ -15,7 +15,6 @@ import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; import ca.uhn.fhir.jpa.api.config.ThreadPoolFactoryConfig; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao; -import ca.uhn.fhir.jpa.binary.interceptor.BinaryStorageInterceptor; import ca.uhn.fhir.jpa.binary.provider.BinaryAccessProvider; import ca.uhn.fhir.jpa.config.util.HapiEntityManagerFactoryUtil; import ca.uhn.fhir.jpa.config.util.ResourceCountCacheUtil; @@ -323,7 +322,6 @@ public class StarterJpaConfig { Optional corsInterceptor, IInterceptorBroadcaster interceptorBroadcaster, Optional binaryAccessProvider, - BinaryStorageInterceptor binaryStorageInterceptor, IValidatorModule validatorModule, Optional graphQLProvider, BulkDataExportProvider bulkDataExportProvider, @@ -455,7 +453,6 @@ public class StarterJpaConfig { // Binary Storage if (appProperties.getBinary_storage_enabled() && binaryAccessProvider.isPresent()) { fhirServer.registerProvider(binaryAccessProvider.get()); - fhirServer.registerInterceptor(binaryStorageInterceptor); } // Validation