简体   繁体   English

向 Mirth 中的新目的地发送消息

[英]Send message to the new destination in Mirth

I am working on a Mirth channel where I am trying to validate an XML using the XSD file.我在 Mirth 频道上工作,我正在尝试使用 XSD 文件验证 XML。 In order to perform that I wrote the below JavaScript which was serving my purpose.为了实现这一点,我编写了下面的 JavaScript 来满足我的目的。 I am using JAXP API library to perform this action.我正在使用 JAXP API 库来执行此操作。

My next step is: Any validation error should route to the Destination 1. Whereas, valid message should go to the Destination 2.我的下一步是:任何验证错误都应路由到目标 1。而有效消息应路由到目标 2。

I would really appreciate if someone can guide me how to tweak this Javascript or write a filter logic to perform this action.如果有人可以指导我如何调整此 Javascript 或编写过滤器逻辑来执行此操作,我将不胜感激。

Thanks in advance !!!提前致谢!!!

var schemaFile = new Packages.java.io.File("C:\\hl7v3\\Test.xsd");
var schemaFactory = Packages.javax.xml.validation.SchemaFactory.newIns tance("http://www.w3.org/2001/XMLSchema");
var schema = schemaFactory.newSchema(schemaFile);
var reader = new Packages.java.io.StringReader(connectorMessage.get RawData());


var xmlFile = new Packages.javax.xml.transform.stream.StreamSource(r eader);

var validator = schema.newValidator();

try {
// validates the message
validator.validate(xmlFile);
// valid message
logger.info('valid');
} catch (err) {
// invalid message
logger.error('An Error Occurred:'+err.toString());
return false;
}

For above validation example we can use Mirth destinationSet filtering function as below,对于上面的验证示例,我们可以使用 Mirth destinationSet 过滤功能,如下所示,

we should have two destination connectors, one for valid messages transmission and other for error-ed messages我们应该有两个目标连接器,一个用于有效消息传输,另一个用于错误消息

try {
// validates the message
validator.validate(xmlFile);
// valid message
logger.info('valid');
destinationSet.removeAllExcept(<sucess-destination-id>);
} catch (err) {
// invalid message
logger.error('An Error Occurred:'+err.toString());
destinationSet.removeAllExcept(<error-destination-id>);
return false;
}

//Replace destination ID based on your destination IDs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM