Skip to content

Commit

Permalink
APID-206: put From, FaultTo and ReplyTo addresses inside child nodes.…
Browse files Browse the repository at this point in the history
… Move declaration of wsa namespace to root of document (#44)
  • Loading branch information
worthydolt authored Jun 30, 2021
1 parent 69b5098 commit f1dc4ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class OutboundService @Inject()(outboundConnector: OutboundConnector,
}

private def addHeaders(message: MessageRequest, operation: Operation, envelope: SOAPEnvelope): Unit = {
val wsaNs: OMNamespace = getOMFactory.createOMNamespace(WSA_NAMESPACE, "wsa")
val wsaNs: OMNamespace = envelope.declareNamespace(WSA_NAMESPACE, "wsa")
addSoapAction(operation, wsaNs, envelope)
addMessageHeader(message, operation, envelope)
addOptionalAddressingHeaders(message, wsaNs, envelope)
Expand Down Expand Up @@ -175,10 +175,10 @@ class OutboundService @Inject()(outboundConnector: OutboundConnector,
}

private def addOptionalAddressingHeaders(message: MessageRequest, wsaNs: OMNamespace, envelope: SOAPEnvelope): Unit = {
message.addressing.from.foreach(addToSoapHeader(_, WSA_FROM, wsaNs, envelope))
message.addressing.from.foreach(addWithAddressElementChildToSoapHeader(_, WSA_FROM, wsaNs, envelope))
addToSoapHeader(message.addressing.to, WSA_TO, wsaNs, envelope)
addToSoapHeader(message.addressing.replyTo, WSA_REPLY_TO, wsaNs, envelope)
message.addressing.faultTo.foreach(addToSoapHeader(_, WSA_FAULT_TO, wsaNs, envelope))
addWithAddressElementChildToSoapHeader(message.addressing.replyTo, WSA_REPLY_TO, wsaNs, envelope)
message.addressing.faultTo.foreach(addWithAddressElementChildToSoapHeader(_, WSA_FAULT_TO, wsaNs, envelope))
addToSoapHeader(message.addressing.messageId, WSA_MESSAGE_ID, wsaNs, envelope)
message.addressing.relatesTo.foreach(addToSoapHeader(_, WSA_RELATES_TO, wsaNs, envelope))
}
Expand All @@ -189,6 +189,14 @@ class OutboundService @Inject()(outboundConnector: OutboundConnector,
envelope.getHeader.addChild(addressingElement)
}

private def addWithAddressElementChildToSoapHeader(property: String, elementName: String, namespace: OMNamespace, envelope: SOAPEnvelope): Unit = {
val addressingElement: OMElement = getOMFactory.createOMElement(elementName, namespace)
val addressingElementInner: OMElement = getOMFactory.createOMElement("Address", namespace)
getOMFactory.createOMText(addressingElementInner, property)
addressingElement.addChild(addressingElementInner)
envelope.getHeader.addChild(addressingElement)
}

private def addBody(message: MessageRequest, operation: Operation, envelope: SOAPEnvelope): Unit = {
val inputMessageName = operation.getInput.getMessage.getParts.asScala.values.head.asInstanceOf[Part].getElementName
val payload = getOMFactory.createOMElement(inputMessageName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,21 @@ class OutboundServiceSpec extends AnyWordSpec with Matchers with GuiceOneAppPerS
val expectedStatus: Int = OK

val allAddressingHeaders =
"""<wsa:From xmlns:wsa="http://www.w3.org/2005/08/addressing">HMRC</wsa:From>
|<wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing">CCN2</wsa:To>
|<wsa:ReplyTo xmlns:wsa="http://www.w3.org/2005/08/addressing">ReplyTo</wsa:ReplyTo>
|<wsa:FaultTo xmlns:wsa="http://www.w3.org/2005/08/addressing">FaultTo</wsa:FaultTo>
|<wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing">123</wsa:MessageID>
|<wsa:RelatesTo xmlns:wsa="http://www.w3.org/2005/08/addressing">RelatesTo</wsa:RelatesTo>""".stripMargin.replaceAll("\n", "")
"""<wsa:From><wsa:Address>HMRC</wsa:Address></wsa:From>
|<wsa:To>CCN2</wsa:To>
|<wsa:ReplyTo><wsa:Address>ReplyTo</wsa:Address></wsa:ReplyTo>
|<wsa:FaultTo><wsa:Address>FaultTo</wsa:Address></wsa:FaultTo>
|<wsa:MessageID>123</wsa:MessageID>
|<wsa:RelatesTo>RelatesTo</wsa:RelatesTo>""".stripMargin.replaceAll("\n", "")

val mandatoryAddressingHeaders =
"""<wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing">CCN2</wsa:To>
|<wsa:ReplyTo xmlns:wsa="http://www.w3.org/2005/08/addressing">ReplyTo</wsa:ReplyTo>
|<wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing">123</wsa:MessageID>""".stripMargin.replaceAll("\n", "")
"""<wsa:To>CCN2</wsa:To>
|<wsa:ReplyTo><wsa:Address>ReplyTo</wsa:Address></wsa:ReplyTo>
|<wsa:MessageID>123</wsa:MessageID>""".stripMargin.replaceAll("\n", "")

def expectedSoapEnvelope(extraHeaders: String = ""): String =
s"""<?xml version='1.0' encoding='utf-8'?>
|<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
|<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing">
|<soapenv:Header>
|<wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">CCN2.Service.Customs.EU.ICS.RiskAnalysisOrchestrationBAS/IE4N03notifyERiskAnalysisHit</wsa:Action>
|<ccnm:MessageHeader xmlns:ccnm="http://ccn2.ec.eu/CCN2.Service.Platform.Common.Schema">
Expand Down Expand Up @@ -291,8 +291,6 @@ class OutboundServiceSpec extends AnyWordSpec with Matchers with GuiceOneAppPerS
when(outboundMessageRepositoryMock.persist(*)).thenReturn(Future(InsertOneResult.acknowledged(BsonNumber(1))))

await(underTest.sendMessage(messageRequestMinimalAddressing))
getXmlDiff(messageCaptor.getValue.toString, expectedSoapEnvelope(mandatoryAddressingHeaders)).build().getDifferences.forEach(d => println(d))

getXmlDiff(messageCaptor.getValue.toString, expectedSoapEnvelope(mandatoryAddressingHeaders)).build().hasDifferences shouldBe false
}

Expand All @@ -304,7 +302,6 @@ class OutboundServiceSpec extends AnyWordSpec with Matchers with GuiceOneAppPerS
when(outboundMessageRepositoryMock.persist(*)).thenReturn(Future(InsertOneResult.acknowledged(BsonNumber(1))))

await(underTest.sendMessage(messageRequestMinimalAddressing))
getXmlDiff(messageCaptor.getValue.toString, expectedSoapEnvelope(mandatoryAddressingHeaders)).build().getDifferences.forEach(d => println(d))

getXmlDiff(messageCaptor.getValue.toString, expectedSoapEnvelope(mandatoryAddressingHeaders)).build().hasDifferences shouldBe false
}
Expand Down

0 comments on commit f1dc4ed

Please sign in to comment.