Groovy Mapping Post Processors
One of the main goals of the Dynamic Message Mapper is to allow reconfiguration after deployment without rebuilding anything. Although the Java post processor allows you to add functionality after deployment, it requires some building.
As an alternative to providing a className
attribute for your mapping post
processor, you can instead specify the path of a Groovy file containing an
implementation of the MappingPostProcessor
class.
This works the same way as the Java implementation, but it allows you to write code without rebuilding.
This example shows the definition of a Groovy mapping post processor:
postProcessors:
- name: "Dynamic Post Processor"
groovyFile: "DynamicPostProcessor.groovy"
The Groovy file in this example is in the same directory as the mapping configuration.
This example shows configuration of the Groovy mapping post processor:
package com.matrixx.mapping.example
import com.matrixx.datacontainer.DataContainer
import com.matrixx.mapping.MappingContext
import com.matrixx.mapping.postprocess.MappingPostProcessor
class DynamicPostProcessor extends MappingPostProcessor {
@Override
void postProcess(final Object targetMessage, final MappingContext mappingContext)
{
println "I'm in a dynamic Mapping Post Processor!"
final DataContainer message = targetMessage
message.set(message.lookupKey("ExternalServiceType"), 123L)
}
}