hapi-fhir-jpaserver-starter icon indicating copy to clipboard operation
hapi-fhir-jpaserver-starter copied to clipboard

Harmonize use of InterceptorService

Open jkiddo opened this issue 1 year ago • 7 comments

Currently different two InterceptorService instances are used simultaneously - one from JpaConfig and one from RestfulServer. This might cause confusion and does not seems necessary.

jkiddo avatar Mar 21 '24 18:03 jkiddo

Please have a look at CompositeInterceptorBroadcaster to have a look at how pointcut invocations are spread across multiple interceptor services. Yes, there are intentionally 2 in HAPI-FHIR, because we occasionally have a FHIR Endpoint with no persistence layer, and occasionally have a persistence layer with no FHIR Endpoint. The two layers have separate pointcuts, and the compositeinterceptorbroadcaster is what allows you to span the chasm and invoke pointcuts on the other layer if needed.

Edit: Actually, I don't think you should merge this. If you did this, HAPI-FHIR will double-invoke a single interceptor due to its use of the CompositeInterceptorBroadcaster., which will cause problems if the interceptor is not idempotent (most are not).

tadgh avatar Mar 21 '24 20:03 tadgh

Thx for the clarifying response. Wouldn't a check on instance equality on broadcasters on e.g. https://github.com/hapifhir/hapi-fhir/blob/4a726dd2d1d015ad03340d9c726a31c2b0ee831b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/util/CompositeInterceptorBroadcaster.java#L83 fix that so it isn't invoked twice?

jkiddo avatar Mar 22 '24 07:03 jkiddo

( including AopUtils.isAopProxy ) that is or something like that ...

jkiddo avatar Mar 22 '24 08:03 jkiddo

I get the design with the flexibility that sometimes it is used as a facade and sometime its more mainly a storage setup - but in the pure starter setup, wouldn't the above suggestion fix that and also make it more simple in total? With the current setup you need to be extra cautious about where you register interceptors.

jkiddo avatar Mar 22 '24 12:03 jkiddo

I'm not fully understanding the problem. The current examples and automated options for registering interceptors in the JPA Starter all register by calling the RestfulServer.registerInterceptor(..). Are there cases where that doesn't work?

XcrigX avatar Mar 22 '24 14:03 XcrigX

@XcrigX try change https://github.com/hapifhir/hapi-fhir-jpaserver-starter/blob/624a269994933cc51a7b269f33e9f2006c7954a7/src/test/java/some/custom/pkg1/CustomInterceptorPojo.java#L14 to @Hook(Pointcut.STORAGE_PRESTORAGE_RESOURCE_CREATED) and you'll see the difference

jkiddo avatar Mar 22 '24 16:03 jkiddo

I got it wrong. It works just as @tadgh described it, though the double invocation could be solved if instance equality is checked.

jkiddo avatar Mar 22 '24 16:03 jkiddo