diff --git a/Dockerfile b/Dockerfile index 89ada58..263fe9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,4 +46,4 @@ WORKDIR /app COPY --chown=nonroot:nonroot --from=build-distroless /app /app COPY --chown=nonroot:nonroot --from=build-hapi /tmp/hapi-fhir-jpaserver-starter/opentelemetry-javaagent.jar /app -CMD ["/app/main.war"] +ENTRYPOINT ["java", "--class-path", "/app/main.war", "-Dloader.path=main.war!/WEB-INF/classes/,main.war!/WEB-INF/,/app/extra-classes", "org.springframework.boot.loader.PropertiesLauncher", "app/main.war"] diff --git a/README.md b/README.md index 9da490b..dbb5740 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ services: depends_on: - db + db: image: postgres restart: always @@ -105,6 +106,87 @@ spring: hibernate.search.enabled: false ``` +### Example running custom interceptor using docker-compose + +This example is an extension of the above one, now adding a custom interceptor. + +```yaml +version: '3.7' + +services: + fhir: + container_name: fhir + image: "hapiproject/hapi:latest" + ports: + - "8080:8080" + configs: + - source: hapi + target: /app/config/application.yaml + - source: hapi-extra-classes + target: /app/extra-classes + depends_on: + - db + + db: + image: postgres + restart: always + environment: + POSTGRES_PASSWORD: admin + POSTGRES_USER: admin + POSTGRES_DB: hapi + volumes: + - ./hapi.postgress.data:/var/lib/postgresql/data + +configs: + hapi: + file: ./hapi.application.yaml + hapi-extra-classes: + file: ./hapi-extra-classes +``` + +Provide the following content in ``./hapi.aplication.yaml``: + +```yaml +spring: + datasource: + url: 'jdbc:postgresql://db:5432/hapi' + username: admin + password: admin + driverClassName: org.postgresql.Driver + jpa: + properties: + hibernate.dialect: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect + hibernate.search.enabled: false +hapi: + fhir: + custom-bean-packages: the.package.containing.your.interceptor + custom-interceptor-classes: the.package.containing.your.interceptor.YourInterceptor +``` + +The basic interceptor structure would be like this: + +```java +package the.package.containing.your.interceptor; + +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.springframework.stereotype.Component; + +import ca.uhn.fhir.interceptor.api.Hook; +import ca.uhn.fhir.interceptor.api.Interceptor; +import ca.uhn.fhir.interceptor.api.Pointcut; + +@Component +@Interceptor +public class YourInterceptor +{ + @Hook(Pointcut.STORAGE_PRECOMMIT_RESOURCE_CREATED) + public void resourceCreated(IBaseResource newResource) + { + System.out.println("YourInterceptor.resourceCreated"); + } +} +``` + ## Running locally The easiest way to run this server entirely depends on your environment requirements. At least, the following 4 ways are supported: