How to access the full server-log of on each request: Tired of HTTP 400 Bad Request with GET, PUT, DELETE via HAPI-Client

I have used the HAPI-FHIR Generic Client to automate FHIR Patient CRUD operations on via the instance.

Refer to the PR → FM2-460: Create a real integration test for the Patient domain by jnsereko · Pull Request #402 · openmrs/openmrs-module-fhir2 · GitHub

When I point to the OpenMRS dev3 instance ie SERVER_BASE = "" with the Community Outreach location like PATIENT_LOCATION_UUID = "1ce1b7d4-c865-4178-82b0-5932e51503d6",

Only the @BeforeClass -> shouldCreatePatient() runs successfully. The patient is created, and the rest return a small portion of the error which is less informative of the fault and hence not-helping.

Caused by: HTTP 400 Bad Request
        at org.openmrs.module.fhir.patient.PatientDomainTest.lambda$shouldThrow404WithNonExistingPatient$0(
        at org.openmrs.module.fhir.patient.PatientDomainTest.shouldThrow404WithNonExistingPatient(

[ERROR] org.openmrs.module.fhir.patient.PatientDomainTest.shouldGetPatientDomainByUUID  Time elapsed: 1.133 s  <<< ERROR! HTTP 400 Bad Request
        at org.openmrs.module.fhir.patient.PatientDomainTest.shouldGetPatientDomainByUUID(

[ERROR] org.openmrs.module.fhir.patient.PatientDomainTest.updatePatientByUUID  Time elapsed: 1.135 s  <<< ERROR! HTTP 400 Bad Request
        at org.openmrs.module.fhir.patient.PatientDomainTest.updatePatientByUUID(

[ERROR] org.openmrs.module.fhir.patient.PatientDomainTest  Time elapsed: 2.199 s  <<< ERROR! HTTP 400 Bad Request
        at org.openmrs.module.fhir.patient.PatientDomainTest.shouldDeletePatientByUUID(

However, when I run this locally using the SDK watching the latest changes of openmrs-module-fhir2 with SERVER_BASE = "http://localhost:8090/openmrs/ws/fhir2/R4" and Isolation Ward location as PATIENT_LOCATION_UUID = "2131aff8-2e2a-480a-b7ab-4ac53250262b". It works pretty fine.

Screenshot 2022-05-19 at 21 13 24


cc @ibacher @mozzy @dkayiwa @mseaton @mogoodrich @kdaud @sharif

Are your changes publicly available for anyone to locally reproduce the problem?

1 Like

@dkayiwa the above is the PR i created

there might be need to also change the identifier because "1000H0E" might have been assigned already when the tests executed via github-actions

so you might also need to alter PATIENT_IDENTIFIER_ID = "1000H45" generated with

POST /openmrs/ws/rest/v1/idgen/identifiersource/8549f706-7e85-4c1d-9424-217d50a2988b/identifier HTTP/1.1
Content-Type: application/json
Authorization: Basic YWRtaW46QWRtaW4xMjM=
Cache-Control: no-cache
Postman-Token: bbfeb383-f3d2-5fb4-628d-4ac9e05ebcc4

	"comment": "created for the new FHIR patient Rest-API test"

thank you @dkayiwa for the response

If you catch the exception, you should be able to get a somewhat more informative message via the OperationOutcome. However: an HTTP 400 response indicates that the client sent a request that the server does not understand.

At a quick thought: at the start of each method, you call authenticate(). Your authenticate() method then registers an interceptor that adds a basic auth header. Because nothing is done to clear those, it seems like you are probably sending a request that looks something like this:

Authorization: Basic 1234
Authorization: Basic 1234
Authorization: Basic 1234

Because there are a few different layers in line when talking to dev3 (roughly two nginx servers) its likely that one of them is rejecting the request. Can you please refactor things so that authenticate() is only called once? (You can just make it a @BeforeClass method, since that’s when everything is being setup).


Thank you @ibacher This was really hard for me to hunt down.