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

Support using a single FhirContext to talk to multiple servers that might require different proxy configuration

Open MFAshby opened this issue 4 months ago • 0 comments

Describe the issue In order to use an http proxy with HAPI; one has to supply the proxy details to the FhirContext, e.g.

var ctx = FhirContext.forDstu3();
ctx.getRestfulClientFactory().setProxy("myProxyHost", 1234);

Then any clients created from that context will use the same proxy details

var fhirClient = ctx.newRestfulGenericClient("http://myFhirServer:8080/fhir");

This is a problem when I want to communicate with 2 FHIR servers, and only 1 of them is behind a proxy:

var secondFhirClient = ctx.newRestfulGenericClient("http://myOtherFhirServer:8080/fhir");

This fails if http://myOtherFhirServer:8080 is not accessible via the proxy I specified earlier.

The workaround is to use multiple FhirContext objects. This is suboptimal; because a FhirContext is a heavyweight object; ~70MB for a DSTU3 once it's been used for a few FHIR operations including validation.

I'm experiencing a pathological case where I have ~40 FHIR servers to talk to behind different proxies; which means the memory requirement is large even though the majority of the FhirContext data could be shared between the servers.

Environment (please complete the following information):

  • HAPI FHIR Version: 6.4.4
  • OS: [e.g. iOS]: linux
  • Browser [e.g. chrome, safari]: n/a

Additional context n/a

MFAshby avatar Oct 21 '24 15:10 MFAshby