From e07e071130f365ebbfc317edb790d68836c475cc Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 21 May 2020 05:47:39 -0400 Subject: [PATCH] Avoid deserialization issues in subscription delivery (#1856) * Avoid deserialization issues in subscription delivery * Add changelog --- "\\" | 6 ++++++ ...-xml-seserialization-issue-for-subs-delivery.yaml | 6 ++++++ .../subscription/model/ResourceDeliveryMessage.java | 12 ++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 "\\" create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1856-avoid-xml-seserialization-issue-for-subs-delivery.yaml diff --git "a/\\" "b/\\" new file mode 100644 index 00000000000..164a87f7a0f --- /dev/null +++ "b/\\" @@ -0,0 +1,6 @@ +--- +type: fix +issue: 1856 +title: The subscription delivery queue in the JPA server was erroniously keeping both a copy of the serialized and the + deserialized payload in memory for each entry in the queue, doubling the memory requirements. This also caused failures + when delivering XML payloads in some configurations. This has been corrected. diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1856-avoid-xml-seserialization-issue-for-subs-delivery.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1856-avoid-xml-seserialization-issue-for-subs-delivery.yaml new file mode 100644 index 00000000000..77964969282 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1856-avoid-xml-seserialization-issue-for-subs-delivery.yaml @@ -0,0 +1,6 @@ +--- +type: fix +issue: 1856 +title: "The subscription delivery queue in the JPA server was erroniously keeping both a copy of the serialized and the + deserialized payload in memory for each entry in the queue, doubling the memory requirements. This also caused failures + when delivering XML payloads in some configurations. This has been corrected." diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryMessage.java index 69b40d7004a..25b467735f6 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryMessage.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryMessage.java @@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.subscription.model; */ import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.api.EncodingEnum; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; @@ -62,7 +63,8 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes public IBaseResource getPayload(FhirContext theCtx) { IBaseResource retVal = myPayload; if (retVal == null && isNotBlank(myPayloadString)) { - retVal = theCtx.newJsonParser().parseResource(myPayloadString); + IParser parser = EncodingEnum.detectEncoding(myPayloadString).newParser(theCtx); + retVal = parser.parseResource(myPayloadString); myPayload = retVal; } return retVal; @@ -93,7 +95,13 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes } public void setPayload(FhirContext theCtx, IBaseResource thePayload, EncodingEnum theEncoding) { - myPayload = thePayload; + /* + * Note that we populate the raw string but don't keep the parsed resource around when we set this. This + * has two reasons: + * - If we build up a big queue of these on an in-memory queue, we aren't taking up double the memory + * - If use a serializing queue, we aren't behaving differently (and therefore possibly missing things + * in tests) + */ myPayloadString = theEncoding.newParser(theCtx).encodeResourceToString(thePayload); myPayloadId = thePayload.getIdElement().toUnqualified().getValue(); }