Interceptors add headers - HAPI as a Gateway/Proxy

430 views
Skip to first unread message

kevin.m...@xml-solutions.com

unread,
Nov 3, 2017, 12:08:15 PM11/3/17
to HAPI FHIR
Hi,

Have been looking at writing an interceptor to add:

X-Forwarded-For  (which contains the originating Ip address)

and

X-Request-ID (to have a message Id to be used for subsequent calls to actual FHIR Server)


but not seen a way to add in the two headers. 

Is it possible 

Many thanks 
Kev

James Agnew

unread,
Nov 3, 2017, 5:35:54 PM11/3/17
to Kevin Mayfield, HAPI FHIR
Hi Kevin,

Can you elaborate a bit on the setup you're envisioning? I.e. is HAPI a client, or a server, or both in this case?

If you just want to add those two headers to a client request, you could do this by creating a custom client interceptor similar to this one: https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/interceptor/BearerTokenAuthInterceptor.java

But maybe I'm misunderstanding the use case..

Cheers,
James

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/e9c4ae40-4a08-4bdd-b92b-728ef3783397%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin Mayfield

unread,
Nov 3, 2017, 5:47:57 PM11/3/17
to James Agnew, Kevin Mayfield, HAPI FHIR
It’s a restful server acting as a gateway/proxy, using apache camel to call another hapi server.

We can add a correlation Identifier in camel but want to add it to the gateway so the logging interceptor also uses same identifier.

Sent from my iPhone

James Agnew

unread,
Nov 3, 2017, 5:51:27 PM11/3/17
to Kevin Mayfield, Kevin Mayfield, HAPI FHIR
Is the problem then that you receive these IDs in the RestfulServer, but you then want to capture them and forward them on via the HAPI Client?

If the issue you have is just wanting to capture those two header values, you are allowed to add a parameter of type HttpServletRequest to any RestfulServer resource provider method. You could just add that, and grab the header values directly from it.

Cheers,
James

On Fri, Nov 3, 2017 at 5:47 PM, Kevin Mayfield <kevin.m...@airelogic.com> wrote:
It’s a restful server acting as a gateway/proxy, using apache camel to call another hapi server.

We can add a correlation Identifier in camel but want to add it to the gateway so the logging interceptor also uses same identifier.

Sent from my iPhone

On 3 Nov 2017, at 21:35, James Agnew <james...@gmail.com> wrote:

Hi Kevin,

Can you elaborate a bit on the setup you're envisioning? I.e. is HAPI a client, or a server, or both in this case?

If you just want to add those two headers to a client request, you could do this by creating a custom client interceptor similar to this one: https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/interceptor/BearerTokenAuthInterceptor.java

But maybe I'm misunderstanding the use case..

Cheers,
James

Kevin Mayfield

unread,
Nov 3, 2017, 6:14:16 PM11/3/17
to James Agnew, Kevin Mayfield, HAPI FHIR
I think we would need to generate the identifiers before it’s passed to the providers, so the logging interceptor can also record them.

Also I think we may want to add request-modified header as per 



Sent from my iPhone

James Agnew

unread,
Nov 3, 2017, 7:40:11 PM11/3/17
to Kevin Mayfield, Kevin Mayfield, HAPI FHIR
I have to be honest, I'm not understanding at all what you're trying to do.....

Maybe a diagram would make it more clear?

Cheers,
James

kevin.m...@xml-solutions.com

unread,
Nov 4, 2017, 4:57:52 AM11/4/17
to HAPI FHIR


The two http components ('Gateway' left hand side) are HAPI RestFul servers (running in a docker container - not hapi overlay's as shown in the diagram), as is the FHIR 'application' server. All are logging to ELK stack. Design is scalable so we could have multiple FHIR gateway and application servers.

So when a call comes in, it will be processed by the gateway and then sent to the application server. The reasons for the gateway:
- reduced capability statement (the server supports more than the gateway)
- support multiple security standards (server supports just one)

All components create log entries (in ELK) and so we get multiple log entries for every call coming in. So to assist with fault finding (and audit) we're planning to use a correlation identifier across the micro-services. We would introduce this correlationId in the the gateway, earlier in the stack the better [If we do this in apache camel (which is in the gateway), we don't cover all incoming calls such as when the default exception handler has rejected the call]. 
  
 
Kev

James Agnew

unread,
Nov 4, 2017, 6:53:28 AM11/4/17
to Kevin Mayfield, HAPI FHIR
Oh, that part makes sense... And where do the headers come in?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.

Kevin Mayfield

unread,
Nov 4, 2017, 8:05:54 AM11/4/17
to James Agnew, Kevin Mayfield, HAPI FHIR

I think we need to explore a little more and document. Seems to be a non functional requirement in intranet and extranet use cases.

We can mock using camel for now and look at moving into hapi later.

Is their any specific instructions on making changes to hapi code, we found a spelling mistake in capability statement we’d like to fix.

Kev


Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages