Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the timeout of a HAPI FHIR IGenericClient

I'm trying to run a fhir search using the following code;

FhirContext ctx = FhirContext.forDstu2();
ctx.getRestfulClientFactory().setConnectTimeout(2000000);
IGenericClient client = ctx.newRestfulGenericClient("http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2");

Bundle results = client.search().forResource(Basic.class).returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class).execute();

However when it runs, it always throws the exception 'FhirClientConnectionException' which is caused by the exception 'SocketTimeoutException'. Am I to assume that this is the server timing out, and not my local connection, since I set my local to 2000000?

How do I go about fixing thing? I'm using HAPI in it's out of the box config, and it times out searching through a relatively small amount of resources within about 10-15 seconds.

like image 474
Andy Avatar asked Jan 11 '17 15:01

Andy


1 Answers

Try setSocketTimeout() instead.

Like this:

FhirContext ctx = FhirContext.forDstu2();
ctx.getRestfulClientFactory().setSocketTimeout(200 * 1000);
IGenericClient client = ctx.newRestfulGenericClient("http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2");

Bundle results = client.search().forResource(Basic.class).returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class).execute();

v3 example:

serverBase =  "http://hapi.fhir.org/baseDstu3";
ctx = FhirContext.forDstu3();
ctx.getRestfulClientFactory().setSocketTimeout(200 * 1000);

// Create the client
client = ctx.newRestfulGenericClient(serverBase);

I found the answer reading source code here: https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java#L1710

like image 73
Micah Stubbs Avatar answered Oct 05 '22 13:10

Micah Stubbs