Permalink
Browse files

Refactoring Outboundheader Config to allow delayed property evaluation

  • Loading branch information...
atooni committed Dec 20, 2018
1 parent 6e1f3eb commit 9229e22435ae4e683f6eda01dbb114f4fbcb4293
@@ -29,9 +29,7 @@ trait ContainerIdentifierService {
def resolvePropertyString(value : String) : Try[AnyRef] = resolvePropertyString(value, Map.empty)

def resolvePropertyString(value: String, additionalProps: Map[String, Any]) : Try[AnyRef] = Try {

val r = ContainerPropertyResolver.resolve(this, value, additionalProps)

r
}
}
@@ -205,7 +205,7 @@ object OutboundHeaderConfig {
case None => defaultProvider
}

val bridgeDestination = cfg.getStringOption(bridgeDestinationPath).map(s => JmsDestination.create(idSvc.resolvePropertyString(s).map(_.toString()).get).get)
val bridgeDestination = cfg.getStringOption(bridgeDestinationPath).map(s => idSvc.resolvePropertyString(s).get).map(_.toString())
val moduleLastOnComplete = cfg.getBoolean(moduleLastOnCompletePath, false)
val applicationLogHeader = cfg.getStringListOption(applicationLogHeaderPath).getOrElse(defaultLogHeader)

@@ -233,7 +233,7 @@ object OutboundHeaderConfig {

case class OutboundHeaderConfig(
bridgeProviderConfig : BridgeProviderConfig,
bridgeDestination : Option[JmsDestination],
bridgeDestination : Option[String],
autoComplete : Boolean,
condition : Option[String],
applicationLogHeader : List[String],
@@ -35,25 +35,33 @@ object DispatcherOutbound {
}
}

val resolveDest : DispatcherBuilderSupport => FlowEnvelope => Try[JmsDestination] = { bs => env => Try {
val resolveDest : ContainerIdentifierService => DispatcherBuilderSupport => FlowEnvelope => Try[JmsDestination] = {
idSvc => bs => env => Try {

env.getFromContext[Option[JmsDestination]](bs.bridgeDestinationKey).get match {
env.getFromContext[Option[String]](bs.bridgeDestinationKey).get match {
case None => throw new Exception(s"Failed to resolve context object [${bs.bridgeDestinationKey}]")
case Some(ctxtDest) => ctxtDest match {
case None => JmsDestination.create(JmsFlowSupport.replyToQueueName).get
case Some(d) => d
case Some(d) =>

val name : String = idSvc.resolvePropertyString(
value = d,
additionalProps = env.flowMessage.header.mapValues(_.value)
).map(_.toString()).get

JmsDestination.create(name).get

}
}
}}


private[builder] def outboundRouting(
dispatcherCfg : ResourceTypeRouterConfig,
idSvc : ContainerIdentifierService,
bs : DispatcherBuilderSupport
)(env: FlowEnvelope) : Try[DispatcherTarget] = Try {

val dest = resolveDest(bs)(env).get
val dest : JmsDestination = resolveDest(idSvc)(bs)(env).get

val targetDest : JmsDestination = dest.name match {
case JmsFlowSupport.replyToQueueName =>
@@ -69,9 +77,17 @@ object DispatcherOutbound {
val bridgeProvider : BridgeProviderConfig = dest.name match {
// For the replyto destination we have to respond to the src provider
case JmsFlowSupport.replyToQueueName =>
val v = env.header[String](bs.srcVendorHeader(bs.headerConfig.prefix))
val p = env.header[String](bs.srcProviderHeader(bs.headerConfig.prefix))

val v : Option[String] = env.header[String](bs.srcVendorHeader(bs.headerConfig.prefix)).map{ s =>
idSvc.resolvePropertyString(s).map(_.toString()).get
}

val p : Option[String] = env.header[String](bs.srcProviderHeader(bs.headerConfig.prefix)).map{ s =>
idSvc.resolvePropertyString(s).map(_.toString()).get
}

resolveProvider(dispatcherCfg.providerRegistry,v,p).get

case _ =>
env.getFromContext[BridgeProviderConfig](bs.bridgeProviderKey).get match {
case None => throw new Exception(s"Failed to resolve context object [${bs.bridgeProviderKey}]")
@@ -157,7 +157,7 @@ class DispatcherOutboundSpec extends DispatcherSpecSupport
.withHeader(srcDestHeader(ctxt), JmsDestination.create("Dummy").get.asString).get
.withContextObject(ctxt.bs.bridgeProviderKey, provider)
// This will trigger the replyto routing
.withContextObject(ctxt.bs.bridgeDestinationKey, Some(JmsDestination.create(JmsFlowSupport.replyToQueueName).get))
.withContextObject(ctxt.bs.bridgeDestinationKey, Some(JmsFlowSupport.replyToQueueName))

val routing : DispatcherTarget = DispatcherOutbound.outboundRouting(
dispatcherCfg = ctxt.cfg,
@@ -180,7 +180,7 @@ class DispatcherOutboundSpec extends DispatcherSpecSupport
.withHeader(replyToHeader(ctxt), "response").get
.withHeader(srcDestHeader(ctxt), JmsDestination.create("Dummy").get.asString).get
.withContextObject(ctxt.bs.bridgeProviderKey, provider)
.withContextObject(ctxt.bs.bridgeDestinationKey, Some(JmsDestination.create("centralDest").get))
.withContextObject(ctxt.bs.bridgeDestinationKey, Some("centralDest"))

val routing : DispatcherTarget = DispatcherOutbound.outboundRouting(
dispatcherCfg = ctxt.cfg,
@@ -41,7 +41,7 @@ class ResourceTypeRouterConfigSpec extends DispatcherSpecSupport
out.outboundHeader should have size 1
val ohCfg = out.outboundHeader.head
ohCfg.bridgeProviderConfig.id should be(amqId)
ohCfg.bridgeDestination should be(Some(JmsTopic("SagTest")))
ohCfg.bridgeDestination should be(Some("topic:SagTest"))
}
}
}
@@ -66,7 +66,7 @@ class ResourceTypeRouterConfigSpec extends DispatcherSpecSupport
out.outboundHeader should have size 1
val ohCfg = out.outboundHeader.head
ohCfg.bridgeProviderConfig.id should be(ccQueueId)
ohCfg.bridgeDestination should be(Some(JmsQueue("/Qucc/data/out")))
ohCfg.bridgeDestination should be(Some("queue:/Qucc/data/out"))
}
}
}
@@ -85,7 +85,7 @@ class ResourceTypeRouterConfigSpec extends DispatcherSpecSupport
other.foreach { out =>
val ohCfg = other.head.outboundHeader.head
ohCfg.timeToLive should be (14400000)
ohCfg.bridgeDestination should be (Some(JmsQueue("OtherAppToQueue")))
ohCfg.bridgeDestination should be (Some("OtherAppToQueue"))
ohCfg.applicationLogHeader should have size(2)
ohCfg.applicationLogHeader should contain ("keymetric1")
ohCfg.applicationLogHeader should contain ("keymetric3")

0 comments on commit 9229e22

Please sign in to comment.