Interceptor in external jar/library?

32 views
Skip to first unread message

John McBride

unread,
Mar 28, 2026, 1:59:23 PM (2 days ago) Mar 28
to hapi...@googlegroups.com
Hello, is there a way to write an interceptor in an external package and reference/register it into the hapi server without having to download the source and add it to the source code??

Thank you

James Agnew

unread,
Mar 28, 2026, 2:01:46 PM (2 days ago) Mar 28
to John McBride, hapi...@googlegroups.com
Hi John,

Yup, this is the expected way of adding an interceptor.

How you do it really depends on what you're building (jpa, plain server project, client library project) and how you're packaging it, etc. But in general the idea is to include your own code on your deployment classpath, and to register it with the interceptor service.

Cheers,
James

On Sat, Mar 28, 2026 at 1:59 PM John McBride <jo...@johnmcbride.me> wrote:
Hello, is there a way to write an interceptor in an external package and reference/register it into the hapi server without having to download the source and add it to the source code??

Thank you

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/hapi-fhir/CAEo%2BRT7YhHpC-ov9jh9hO5Cwf54mSvSM6RiBvfnks%2Bk%3Dn2%3DdbA%40mail.gmail.com.

John McBride

unread,
Mar 29, 2026, 11:46:35 AM (yesterday) Mar 29
to HAPI FHIR
Is there an example somewhere of what package (maven,etc) to include in the external library and what the deplytment classpath could/should be set to?

James Agnew

unread,
Mar 29, 2026, 12:58:14 PM (yesterday) Mar 29
to John McBride, HAPI FHIR
I'm not sure I'm following your question. The right model for including an interceptor depends on what you are doing exactly, so it might be helpful if you described what you are building, how you are building/compiling/packaging it and what's not working.

Cheers,
James

David Edelstein

unread,
8:50 AM (14 hours ago) 8:50 AM
to HAPI FHIR
I think I get your question - you want to have a customization.jar file that you want to drop into the existing jpa-server without touching that jpa code.  

Create a class tagged with @Configuration.  In this class, use a method with @PostConstruct to register your interceptor with the restfulServer.  
restfulServer is @Autowired.  and your custom interceptor should also be @Autowired.  but setting the ```registerInterceptor``` doesn't happen automatically (we have seen the same thing).  See source code below. 
Then start it all up and see if you can get your interceptor to fire.  



@Configuration
public class CustomOperationConfig {

  @Autowired
  private RestfulServer restfulServer;

  @Autowired
  private 
 MyInterceptor myInterceptor;

  @PostConstruct
  public void registerProviders() {
    restfulServer.registerInterceptor(myInterceptor);

  }

}

John McBride

unread,
11:04 AM (12 hours ago) 11:04 AM
to HAPI FHIR
Hi David/James,

I have successfully registered a custom interceptor via a .class I drop into a mapped volume directory (docker) and setting the props in the application yaml file ( custom-bean-packages, custom-interceptor-classes). My real question here is, I would like to package up my files into a jar file and use that (as I have some additional libraries I need to provide in the jar file) but I'm confused how to reference the jar file in the application.yaml file.

Hope this makes sense

John

David Edelstein

unread,
12:24 PM (11 hours ago) 12:24 PM
to John McBride, HAPI FHIR
jar goes into /app/extra-classes and you set the custom-bean-packages like you mentioned - this should load the configuration.  Then make sure the postconstruct sets up everything.

You received this message because you are subscribed to a topic in the Google Groups "HAPI FHIR" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hapi-fhir/4J3Rcy7Hr7I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/hapi-fhir/a19efb54-3830-4f3a-a68d-8a7df298523en%40googlegroups.com.

John McBride

unread,
1:58 PM (9 hours ago) 1:58 PM
to HAPI FHIR
yeah, I figured it out, had a naming issue. Next question is 1. Is there a way to append to the classpath (using hapi in a docker container) to look for external libraries? I can use a custom class loaded to lad them but I'd not have to do that

Vishwasrao Salunkhe

unread,
3:13 PM (8 hours ago) 3:13 PM
to John McBride, HAPI FHIR
Hi John,

I am not sure if this will help, but this GitHub repo provides a sample custom operation on top of HAPI FHIR and demonstrates how to load it as a custom interceptor and provider classes.

You can find the configuration for the application.yaml here

Additionally, here is the docker-compose to load hapi-extra classes.

Best regards,

Vishwas


Reply all
Reply to author
Forward
0 new messages