diff --git a/commons/ihe/hl7v2/src/test/groovy/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/CustomMessageCopyTest.groovy b/commons/ihe/hl7v2/src/test/groovy/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/CustomMessageCopyTest.groovy index a91222684a..8570d0cada 100644 --- a/commons/ihe/hl7v2/src/test/groovy/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/CustomMessageCopyTest.groovy +++ b/commons/ihe/hl7v2/src/test/groovy/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/CustomMessageCopyTest.groovy @@ -47,16 +47,16 @@ class CustomMessageCopyTest { @Test void testCopyDefaultQBP() throws HL7Exception { - ca.uhn.hl7v2.model.v25.message.QBP_Q21 QBP_Q21_copy = new PipeParser().parse(msg).copy() - assertTrue(QBP_Q21_copy.getQPD() instanceof ca.uhn.hl7v2.model.v25.segment.QPD) + ca.uhn.hl7v2.model.v25.message.QBP_Q21 copy = new PipeParser().parse(msg).copyMessage() + assertTrue(copy.getQPD() instanceof ca.uhn.hl7v2.model.v25.segment.QPD) } @Test void testCopyCustomQBP(){ - QBP_Q21 QBP_Q21_copy = PARSER.parse(msg).copy() - assertTrue(QBP_Q21_copy.getQPD() instanceof QPD) - assertEquals(PARSER, QBP_Q21_copy.getParser()) - assertEquals(PARSER.getFactory(), QBP_Q21_copy.getParser().getFactory()) + QBP_Q21 copy = PARSER.parse(msg).copyMessage() + assertTrue(copy.getQPD() instanceof QPD) + assertEquals(PARSER, copy.getParser()) + assertEquals(PARSER.getFactory(), copy.getParser().getFactory()) } } diff --git a/dependencies/pom.xml b/dependencies/pom.xml index 9ac3e8e8de..a254f785c7 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -13,7 +13,7 @@ 4.4.3 3.19.0 - 4.0.4 + 4.0.5 2.16.1 1.26.1 1.3.200-v20130910-1609 diff --git a/modules/hl7/src/main/groovy/org/openehealth/ipf/modules/hl7/extend/Hl7Dsl2ExtensionModule.groovy b/modules/hl7/src/main/groovy/org/openehealth/ipf/modules/hl7/extend/Hl7Dsl2ExtensionModule.groovy index be44b36fbb..94a421cb0c 100644 --- a/modules/hl7/src/main/groovy/org/openehealth/ipf/modules/hl7/extend/Hl7Dsl2ExtensionModule.groovy +++ b/modules/hl7/src/main/groovy/org/openehealth/ipf/modules/hl7/extend/Hl7Dsl2ExtensionModule.groovy @@ -700,8 +700,8 @@ class Hl7Dsl2ExtensionModule { /** * @DSLDoc http://repo.openehealth.org/confluence/display/ipf2/HL7+DSL */ - static Message copy(Message delegate) { - MessageUtils.copy(delegate) + static Message copyMessage(Message delegate) { + MessageUtils.copyMessage(delegate) } /** diff --git a/modules/hl7/src/main/groovy/org/openehealth/ipf/modules/hl7/message/MessageUtils.groovy b/modules/hl7/src/main/groovy/org/openehealth/ipf/modules/hl7/message/MessageUtils.groovy index 2daee97718..2d824f317f 100644 --- a/modules/hl7/src/main/groovy/org/openehealth/ipf/modules/hl7/message/MessageUtils.groovy +++ b/modules/hl7/src/main/groovy/org/openehealth/ipf/modules/hl7/message/MessageUtils.groovy @@ -211,7 +211,12 @@ class MessageUtils { newInstance(message, message.parser.hapiContext.modelClassFactory) } - static Message copy(Message source) { + /** + * Copies the message by rendering and reparsing it. Consider using {@link AbstractMessage#copy()} for copying using reflection + * @param source message + * @return message copy + */ + static Message copyMessage(Message source) { source.parser.parse(source.encode()) } @@ -225,7 +230,7 @@ class MessageUtils { } private static Group newInstance(Group group) { - group.class.newInstance() + group.class.getConstructor().newInstance() } /** diff --git a/modules/hl7/src/test/groovy/org/openehealth/ipf/modules/hl7/dsl/MessageTest.groovy b/modules/hl7/src/test/groovy/org/openehealth/ipf/modules/hl7/dsl/MessageTest.groovy index d0f659519d..302dd342fa 100644 --- a/modules/hl7/src/test/groovy/org/openehealth/ipf/modules/hl7/dsl/MessageTest.groovy +++ b/modules/hl7/src/test/groovy/org/openehealth/ipf/modules/hl7/dsl/MessageTest.groovy @@ -90,25 +90,25 @@ class MessageTest extends groovy.test.GroovyAssert { void testCopyMessage1() { //def msg1Copy = msg1.empty() //Messages.copyMessage(msg1, msg1Copy) - def msg1Copy = MessageUtils.copy(msg1) + def msg1Copy = MessageUtils.copyMessage(msg1) assert msg1.toString() == msg1Copy.toString() } @Test void testCopyMessage2() { - def msg2Copy = MessageUtils.copy(msg2) + def msg2Copy = MessageUtils.copyMessage(msg2) assert msg2.toString() == msg2Copy.toString() } @Test void testCopyMessageWithNonStandardSegments1() { - def msg3Copy = MessageUtils.copy(msg3) + def msg3Copy = MessageUtils.copyMessage(msg3) assert msg3.toString() == msg3Copy.toString() } @Test void testCopyMessageWithNonStandardSegments2() { - def msg4Copy = MessageUtils.copy(msg4) + def msg4Copy = MessageUtils.copyMessage(msg4) assert msg4.toString() == msg4Copy.toString() } } \ No newline at end of file diff --git a/platform-camel/hl7/src/main/java/org/openehealth/ipf/platform/camel/hl7/CopyMessageExpression.java b/platform-camel/hl7/src/main/java/org/openehealth/ipf/platform/camel/hl7/CopyMessageExpression.java index 9113392c13..768b7adcb1 100644 --- a/platform-camel/hl7/src/main/java/org/openehealth/ipf/platform/camel/hl7/CopyMessageExpression.java +++ b/platform-camel/hl7/src/main/java/org/openehealth/ipf/platform/camel/hl7/CopyMessageExpression.java @@ -33,7 +33,7 @@ public CopyMessageExpression() {} public T evaluate(Exchange exchange, Class type) { try { var msg = HL7v2.bodyMessage(exchange); - var result = MessageUtils.copy(msg); + var result = MessageUtils.copyMessage(msg); return type.cast(result); } catch (HL7Exception e) { throw new HL7v2Exception(e); diff --git a/platform-camel/ihe/hl7v2/src/main/java/org/openehealth/ipf/platform/camel/ihe/hl7v2/intercept/consumer/ConsumerMarshalInterceptor.java b/platform-camel/ihe/hl7v2/src/main/java/org/openehealth/ipf/platform/camel/ihe/hl7v2/intercept/consumer/ConsumerMarshalInterceptor.java index f437296744..e703be7e9c 100644 --- a/platform-camel/ihe/hl7v2/src/main/java/org/openehealth/ipf/platform/camel/ihe/hl7v2/intercept/consumer/ConsumerMarshalInterceptor.java +++ b/platform-camel/ihe/hl7v2/src/main/java/org/openehealth/ipf/platform/camel/ihe/hl7v2/intercept/consumer/ConsumerMarshalInterceptor.java @@ -72,7 +72,7 @@ public void process(Exchange exchange) throws Exception { // Put the original message into the headers. Make a copy if requested try { - inMessage.setHeader(Constants.ORIGINAL_MESSAGE_ADAPTER_HEADER_NAME, copyOriginalMessage ? MessageUtils.copy(originalMessage) : originalMessage); + inMessage.setHeader(Constants.ORIGINAL_MESSAGE_ADAPTER_HEADER_NAME, copyOriginalMessage ? MessageUtils.copyMessage(originalMessage) : originalMessage); } catch (Exception e) { // this exception will occur when the message structure (MSH-9-3) of // the original adapter is wrong or when unknown segments are present diff --git a/platform-camel/ihe/hl7v2ws/src/main/java/org/openehealth/ipf/platform/camel/ihe/hl7v2ws/AbstractHl7v2WebService.java b/platform-camel/ihe/hl7v2ws/src/main/java/org/openehealth/ipf/platform/camel/ihe/hl7v2ws/AbstractHl7v2WebService.java index ac0f79df91..d557d32781 100644 --- a/platform-camel/ihe/hl7v2ws/src/main/java/org/openehealth/ipf/platform/camel/ihe/hl7v2ws/AbstractHl7v2WebService.java +++ b/platform-camel/ihe/hl7v2ws/src/main/java/org/openehealth/ipf/platform/camel/ihe/hl7v2ws/AbstractHl7v2WebService.java @@ -78,7 +78,7 @@ protected String doProcess(String request) { return render(nakFactory.createDefaultNak(e)); } - var originalRequest = MessageUtils.copy(msg); + var originalRequest = MessageUtils.copyMessage(msg); // play the route, handle its outcomes and check response acceptance try {