-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for binary resource download (fixes #2108)
- Loading branch information
Showing
9 changed files
with
251 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash -e | ||
|
||
sudo apt -y install xq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash -e | ||
|
||
# This script queries the server for a non-existent binary resource | ||
# and verifies that we get the 404 error message. | ||
|
||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" | ||
. "$SCRIPT_DIR/util.sh" | ||
|
||
BASE="http://localhost:8080/fhir" | ||
|
||
RANDOM_ID="$(uuidgen | tr '[:upper:]' '[:lower:]')" | ||
|
||
# Attempt to retrieve the Binary resource by ID | ||
echo "Verifying that the Binary resource with ID '$RANDOM_ID' does not exist." | ||
|
||
# Perform a GET request to retrieve the Binary resource by ID | ||
STATUS_CODE=$(curl -s -H "Accept: application/pdf" -o /dev/null -w '%{response_code}' "$BASE/Binary/$RANDOM_ID") | ||
|
||
# Test that the response code is 404 (Not Found), indicating the resource doesn't exist | ||
test "GET response code for Binary resource" "$STATUS_CODE" "404" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash -e | ||
|
||
# This script creates a binary resource and verifies that its binary content | ||
# can be read (via JSON). | ||
|
||
BASE="http://localhost:8080/fhir" | ||
|
||
# 10 KiB of random data, base64 encoded | ||
DATA="$(openssl rand -base64 10240 | tr -d '\n')" | ||
|
||
binary() { | ||
cat <<END | ||
{ | ||
"resourceType": "Binary", | ||
"contentType": "application/pdf", | ||
"data": "$DATA" | ||
} | ||
END | ||
} | ||
|
||
# Create a Binary resource that contains that data, and get its ID (via JSON) | ||
ID_VIA_JSON=$(curl -s -H 'Content-Type: application/fhir+json' -d "$(binary)" "$BASE/Binary" | jq -r '.id') | ||
|
||
echo "Created Binary resource that contains the Random Data" | ||
echo " - via JSON, with ID: $ID_VIA_JSON" | ||
|
||
|
||
# Retrieve the Binary resource, and Base64 encode it so it can be safely handled by Bash (JSON) | ||
BASE64_ENCODED_BINARY_RESOURCE_VIA_JSON=$(curl -s -H 'Accept: application/pdf' "$BASE/Binary/$ID_VIA_JSON" | base64 | tr -d '\n') | ||
|
||
|
||
echo "Binary data retrieved. Verifying content... (JSON version)" | ||
|
||
if [ "$DATA" = "$BASE64_ENCODED_BINARY_RESOURCE_VIA_JSON" ]; then | ||
echo "✅ Base64 encoding of both the Original Data and the Retrieved Resource Data match (JSON)" | ||
else | ||
echo "🆘 Base64 encoding of both the Original Data and the Retrieved Resource Data are different (JSON)" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash -e | ||
|
||
# This script creates a binary resource and verifies that its binary content | ||
# can be read (via XML). | ||
|
||
BASE="http://localhost:8080/fhir" | ||
|
||
# 10 KiB of random data, base64 encoded | ||
DATA="$(openssl rand -base64 10240 | tr -d '\n')" | ||
|
||
binary() { | ||
cat <<END | ||
<Binary xmlns="http://hl7.org/fhir"> | ||
<contentType value="application/pdf"/> | ||
<data value="$DATA"/> | ||
</Binary> | ||
END | ||
} | ||
|
||
|
||
# Create a Binary resource that contains that data, and get its ID (via XML) | ||
ID_VIA_XML=$(curl -s -H 'Content-Type: application/fhir+xml' -H 'Accept: application/fhir+xml' -d "$(binary)" "$BASE/Binary" | xq -x //id/@value) | ||
|
||
echo "Created Binary resource that contains the Random Data" | ||
echo " - via XML, with ID: $ID_VIA_XML" | ||
|
||
|
||
# Retrieve the Binary resource, and Base64 encode it so it can be safely handled by Bash (via XML) | ||
BASE64_ENCODED_BINARY_RESOURCE_VIA_XML=$(curl -s -H 'Accept: application/pdf' "$BASE/Binary/$ID_VIA_XML" | base64 | tr -d '\n') | ||
|
||
|
||
echo "Binary data retrieved. Verifying content... (XML version)" | ||
|
||
if [ "$DATA" = "$BASE64_ENCODED_BINARY_RESOURCE_VIA_XML" ]; then | ||
echo "✅ Base64 encoding of both the Original Data and the Retrieved Resource Data match (XML)" | ||
else | ||
echo "🆘 Base64 encoding of both the Original Data and the Retrieved Resource Data are different (XML)" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters