Search code examples
dstu2-fhirhl7-fhirhapi-fhir

Iterating over a paged fhir response


I've ran a query on a hapi fhir database which has returned a paged result back to me. I'm using hapi base in java to actually do the search, as per the documentation here: http://hapifhir.io/doc_rest_client.html

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

        for (Entry entry: bundle.getEntry())
            System.out.println(entry.getFullUrl());

        if (bundle.getLink(Bundle.LINK_NEXT) != null)
            bundle = client.loadPage().next(bundle).execute();
        else
            bundle = null;
    }
    while (bundle != null);

The code runs as far as getting the first bundle, and prints out the urls as expected, however when it tries to execute the next bundle, I get a ConnectionException 'Connection refused: connect'.

The server still appears to be responsive however as I can rerun my program and have the exact same result returned.

Any idea why the connection would be being refused? I get a similar issue when I try to run it manually from postman.


Solution

  • Just in case anyone stumbles across this. I had some sort of redirection going on (setup by another member of my team). Essentially my base url was localhost:8080, but the next address was returning as localhost:1080 (which I don't entirely understand why).

    He changed a config in the server to make it not redirect.