By default, the HAPI FHIR client uses the Apache HTTP Client (HC) as it's underlying HTTP provider. HC is a very powerful and efficient provider, so it is generally a good choice.

It can be replaced however by providing an alternate implementation of IRestfulClientFactory to the FhirContext.

JAX-RS

If you are using HAPI FHIR's client in an environment where other JAX-RS clients are being used, you may want to use the JAX-RS provider instead of the Apache HC provider.

Using this provider is as simple as creating an instance and providing it to the context:

// Create a client
FhirContext ctx = FhirContext.forDstu2();

// Create an instance of the JAX RS client factory and
// set it on the context
JaxRsRestfulClientFactory clientFactory = new JaxRsRestfulClientFactory(ctx);
ctx.setRestfulClientFactory(clientFactory);

// This client uses JAX-RS!
IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");

Note that this provider is defined in the JAX-RS Server module, so you need to add the following dependency to your project in order for this to work:

<dependency>
	<groupId>ca.uhn.hapi.fhir</groupId>
	<artifactId>hapi-fhir-jaxrsserver-base</artifactId>
	<version>[version]</version>
</dependency>

Back to top

Reflow Maven skin by Andrius Velykis.