Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request body empty when use Content-Type x-application/hl7-v2+er7 #2626

Open
andreas-hempel opened this issue Nov 13, 2024 · 2 comments
Open

Comments

@andreas-hempel
Copy link

Hello KarateDSL team,

I am using KarateDSL to check if an HL7 message processing is executed correctly and the data is rendered correctly via a second FHIR endpoint (REST based). When sending the message, the content-type x-application/hl7-v2+er7 must be used (see https://hapifhir.github.io/hapi-hl7v2/hapi-hl7overhttp/specification.html#a2.4_Content_Type_and_Character_Set)

If I set the content type to x-application/hl7-v2+er7; charset=utf-8 for a POST request, the request body is empty. In the appendix you will find an example project to simulate the behavior.

missing-body.zip

In the example there are two scenarios, one with content-type x-application/hl7-v2+er7; charset=utf-8 and one with content-type application/plain; charset=utf-8. The request body is in both scenrios the same.

* url 'https://httpbin.org'
* def message = "MSH|^~\&|ADT1|GOOD HEALTH HOSPITAL|GHH LAB, INC.|GOOD HEALTH HOSPITAL|198808181126|SECURITY|ADT^A01^ADT_A01|MSG00001|P|2.8||"

Given path 'post'
And header Content-Type = 'x-application/hl7-v2+er7; charset=utf-8'
And request message
When method post
Then status 200

log entry with missing body (Content-Type: x-application/hl7-v2+er7; charset=utf-8)

15:24:25.410 [pool-2-thread-1] DEBUG com.intuit.karate - request:
1 > POST https://httpbin.org/post
1 > Content-Type: x-application/hl7-v2+er7; charset=utf-8
1 > Content-Length: 123
1 > Host: httpbin.org
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.8.1)
1 > Accept-Encoding: gzip,deflate

log entry with body (Content-Type: text/plain; charset=utf-8)

15:24:25.410 [pool-2-thread-2] DEBUG com.intuit.karate - request:
1 > POST https://httpbin.org/post
1 > Content-Type: text/plain; charset=utf-8
1 > Content-Length: 123
1 > Host: httpbin.org
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.8.1)
1 > Accept-Encoding: gzip,deflate
MSH|^~&|ADT1|GOOD HEALTH HOSPITAL|GHH LAB, INC.|GOOD HEALTH HOSPITAL|198808181126|SECURITY|ADT^A01^ADT_A01|MSG00001|P|2.8||

I've tested everything in a new minimal maven karate template as explained in https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue, and you can replicate everything in the code in the attached .zip using the command: mvn clean test

Many thanks and best regards,
Andreas

@ptrthomas
Copy link
Member

ptrthomas commented Nov 14, 2024

@andreas-hempel appreciate the details and the info to replicate. actually, when logging the request, karate does not attempt to log the body if it is some "unknown" type, and the reason for this is to avoid logging binary content. so that explains that part

so look at the response from httpbin.org you will see that the request string was indeed sent and received successfully on the server:

image

we could probably introduce a new configuration setting to over-ride the request (or response) body logging suppression, so I can leave this issue open for now.

just one tip - in case you have weird content that confuses the JSON parser or spans multiple lines, you can consider using text. it won't solve your original problem, but may be useful:

    * text body =
    """
    MSH|^~\&|ADT1|GOOD HEALTH HOSPITAL|GHH LAB, INC.|GOOD HEALTH HOSPITAL|198808181126|SECURITY|ADT^A01^ADT_A01|MSG00001|P|2.8||
    """
    * url 'https://httpbin.org/post'
    * header Content-Type = 'x-application/hl7-v2+er7'
    * request body
    * method post

can you confirm that the HTTP call works fine at least from the server pov ? if your intent is to have the body show up in the HTML report somehow, you could always do * print body

@andreas-hempel
Copy link
Author

@ptrthomas thank you very much for the quick feedback. I have now been able to verify on the server that the request body was transmitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants