Question

Mirth is receiving java object from ActiveMQ JMS Topic.I have set source connector inbound data type to Delimited Text in Mirth Channel and Connector Type is JMS Reader. Now in preprocessor phase i want to marshal this java object into XML.I have put logger like this

logger.info("incoming data "+message);

And it is printing OrderDetails@240aaf81

Now i am calling custom java class for marshaling java object into XML.But this incoming message is converted to String by Mirth.Code in preprocessor script looks like this :

// Modify the message variable below to pre process data
logger.info("incoming data "+message);
var object = new Packages.coms.controller.JAXBMarshalling();
object.marshallJavaObjectToXml(message);
return message;

While passing incoming message to method it is showing error that method does not exist because method expects custom java object as method parameter,but it going as String. Method looks like this:

public  void marshallJavaObjectToXml(OrderDetails orderDetails) {
        JAXBContext jaxbContext;
        try {
            File file = new File(
                    "C:\\Program Files (x86)\\Mirth Connect\\conf\\xml\\xmlrepresentation.xml");
            jaxbContext = JAXBContext.newInstance(OrderDetails.class);
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
            // output pretty printed
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            jaxbMarshaller.marshal(orderDetails, file);
            jaxbMarshaller.marshal(orderDetails, System.out);
        } catch (JAXBException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Class which object is passed looks like this:

 @XmlRootElement
    public class OrderDetails implements Serializable{

        private static final long serialVersionUID = -4617153110762983450L;
        private Long mrn;
        private Long orderNo;
        private Long patientId;
        private Long orderId;**strong text**
        private Long encounterId;
    }

I have created jar file with these two classes and put in custom-lib folder of Mirth.How can i get the actual java object in preprocessor script of Mirth? I am using Mirth version 2.2.1.5861

Was it helpful?

Solution

Such result can be achieved using the Attachment script on the Summary tab. There you deal with a message in its raw format. You can extract your object there and store it to the Global Channel Map which also allows passing objects, contrary to other two maps. The Preprocessor script handles the raw message as well. The difference between these two is that message is not stored in the database when it hits the Attachment handler, but it's stored after.

As a further reading I would recommend the "Unofficial Mirth Connect Developer's Guide". (Disclaimer: I'm the author of this book.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top