diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java index 6a5a10dc7bd..c5eb62b95ec 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java @@ -10,8 +10,6 @@ import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.server.SimpleBundleProvider; import ca.uhn.fhir.util.UrlUtil; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.hl7.fhir.dstu3.model.BodySite; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Coding; @@ -38,12 +36,9 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.MessageHeaders; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -115,17 +110,6 @@ public class InMemorySubscriptionMatcherR3Test extends BaseSubscriptionDstu3Test assertNotMatched(pr, "ProcedureRequest?subject=Patient/123"); } - @Test - public void testSerializationOfMessageHeaders() throws JsonProcessingException { - Map headers = new HashMap<>(); - headers.put("zoop", "zoop"); - MessageHeaders mh = new MessageHeaders(headers); - - ObjectMapper mapper = new ObjectMapper(); - //Test that serialization of MessageHeaders works. - mapper.writeValueAsString(mh); - } - @Test public void testResourceById() { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java index 0edf77cf96f..ae9cb3ced38 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java @@ -25,15 +25,17 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Set; public abstract class BaseJsonMessage implements Message, IModelJson { private static final long serialVersionUID = 1L; @JsonProperty("headers") - private MessageHeaders myHeaders; + private HapiMessageHeaders myHeaders; private String RETRY_COUNT_HEADER = "retryCount"; private String FIRST_FAILURE_HEADER = "firstFailure"; @@ -46,20 +48,98 @@ public abstract class BaseJsonMessage implements Message, IModelJson { super(); setDefaultRetryHeaders(); } + public static class HapiMessageHeaders implements Map{ + + private final Map headers; + + public HapiMessageHeaders(Map theHeaders) { + headers = theHeaders; + } + + public HapiMessageHeaders() { + headers = new HashMap<>(); + } + + + @Override + public int size() { + return this.headers.size(); + } + + @Override + public boolean isEmpty() { + return this.headers.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return this.headers.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return this.headers.containsValue(value); + } + + @Override + public Object get(Object key) { + return this.headers.get(key); + } + + @Override + public Object put(String key, Object value) { + return this.headers.put(key, value); + } + + @Override + public Object remove(Object key) { + return this.headers.remove(key); + } + + @Override + public void putAll(Map m) { + this.headers.putAll(m); + } + + @Override + public void clear() { + this.headers.clear(); + } + + @Override + public Set keySet() { + return this.headers.keySet(); + } + + @Override + public Collection values() { + return this.headers.values(); + } + + @Override + public Set> entrySet() { + return this.headers.entrySet(); + } + } protected void setDefaultRetryHeaders() { Map headers = new HashMap<>(); headers.put(RETRY_COUNT_HEADER, 0); headers.put(FIRST_FAILURE_HEADER, null); headers.put(LAST_FAILURE_HEADER, null); - MessageHeaders messageHeaders = new MessageHeaders(headers); + HapiMessageHeaders messageHeaders = new HapiMessageHeaders(headers); setHeaders(messageHeaders); } @Override public MessageHeaders getHeaders() { + return new MessageHeaders(myHeaders); + } + + public HapiMessageHeaders getHapiHeaders() { return myHeaders; } + public final Integer getRetryCount() { //TODO GGG this is not NPE-safe return (Integer)this.getHeaders().get(RETRY_COUNT_HEADER); @@ -77,7 +157,7 @@ public abstract class BaseJsonMessage implements Message, IModelJson { } - public void setHeaders(MessageHeaders theHeaders) { + public void setHeaders(HapiMessageHeaders theHeaders) { myHeaders = theHeaders; } } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java index df43b0f9970..2cdf57b1b6a 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java @@ -23,7 +23,6 @@ package ca.uhn.fhir.rest.server.messaging.json; import ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.springframework.messaging.MessageHeaders; public class BaseResourceModifiedJsonMessage extends BaseJsonMessage { @@ -46,7 +45,7 @@ public class BaseResourceModifiedJsonMessage extends BaseJsonMessage { + @Override + public MessageHeaders deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { + JsonNode node = p.getCodec().readTree(p); + return null; + } + + @Override + public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException { + return super.deserializeWithType(p, ctxt, typeDeserializer); + } +}