rbeckman-nextgen / test-mc6

0 stars 0 forks source link

Message Browser xml/json prettyprint throws exception when erroneously parsing message #3746

Open rbeckman-nextgen opened 4 years ago

rbeckman-nextgen commented 4 years ago

The message browser currently just checks for the first character to know whether messages can be pretty printed or not.

isXml = trimmedMessage.length() > 0 && trimmedMessage.charAt(0) == '<';

A message's first character can be '<' but also not be xml which leads to the client throwing a bunch of exception. An example of this is the response from sending to gmail's smtp server: <538656531.1.1455322472671.JavaMail.eduardoarmendariz@EduardoIMac.hq.mirthcorp.com>

I am not sure if we should add a better check for isXml or whether we should be catching this exception.

Imported Issue. Original Details: Jira Issue Key: MIRTH-3888 Reporter: eduardoa Created: 2016-02-12T16:34:46.000-0800

rbeckman-nextgen commented 4 years ago

Exception example

ERROR 2016-02-12 16:15:21,915 [pool-4-thread-3] com.mirth.connect.util.MirthXmlUtil: Error pretty printing xml. javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: The markup in the document preceding the root element must be well-formed. at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:755) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:357) at com.mirth.connect.util.MirthXmlUtil.prettyPrint(MirthXmlUtil.java:103) at com.mirth.connect.client.ui.browsers.message.MessageBrowser$10.doInBackground(MessageBrowser.java:1006) at com.mirth.connect.client.ui.browsers.message.MessageBrowser$10.doInBackground(MessageBrowser.java:999) at javax.swing.SwingWorker$1.call(SwingWorker.java:295) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at javax.swing.SwingWorker.run(SwingWorker.java:334) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: The markup in the document preceding the root element must be well-formed. at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(TransformerImpl.java:584) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:745) ... 12 more Caused by: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: The markup in the document preceding the root element must be well-formed. at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:427) at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:215) at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(TransformerImpl.java:562) ... 13 more

Imported Comment. Original Details: Author: eduardoa Created: 2016-02-12T16:35:35.000-0800

rbeckman-nextgen commented 4 years ago

Exception example for JSON (Test Channel = Sending HL7 to Mirth Result using MR Sender) `ERROR 2016-03-25 09:14:21,200 [pool-5-thread-5] com.mirth.connect.util.MirthJsonUtil: Error pretty printing json. com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'ORIGINAL': was expecting ('true', 'false' or 'null') at [Source: [ORIGINAL] MSH](^~&||LAB1||SITE1|200812091126|SECURITY|ADT^A01^ADT_A01|MSG00001|P|2.5| EVN|A01|200812091126|| PID|1||1002||JOHN^DOE^^||19850705|M||2106-7|1200 N ELM STREET^^NEWPORT BEACH^CA^92660-1020^US^H|OC|(949) 555-1234|(949) 555-5678||S|| NK1|1|JANET^DOE^M|SIS^SISTER||||N^NEXT-OF-KIN PV1|1|I|2000^2012^01||||001122^ZOIDBERG^JOHN^|||SUR||||1|A0||||12345

[CONTENT) MSH|^~&||LAB1||SITE1|200812091126|SECURITY|ADT^A01^ADT_A01|MSG00001|P|2.5| EVN|A01|200812091126|| PID|1||1002||JOHN^DOE^^||19850705|M||2106-7|1200 N ELM STREET^^NEWPORT BEACH^CA^92660-1020^US^H|OC|(949) 555-1234|(949) 555-5678||S|| NK1|1|JANET^DOE^M|SIS^SISTER||||N^NEXT-OF-KIN PV1|1|I|2000^2012^01||||001122^ZOIDBERG^JOHN^|||SUR||||1|A0||||12345 ; line: 1, column: 10] at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1487) at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:518) at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2299) at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1458) at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:683) at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeArray(JsonNodeDeserializer.java:261) at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:64) at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:14) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3562) at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2136) at com.mirth.connect.util.MirthJsonUtil.prettyPrint(MirthJsonUtil.java:32) at com.mirth.connect.client.ui.browsers.message.MessageBrowser$10.doInBackground(MessageBrowser.java:1008) at com.mirth.connect.client.ui.browsers.message.MessageBrowser$10.doInBackground(MessageBrowser.java:998) at javax.swing.SwingWorker$1.call(SwingWorker.java:295) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at javax.swing.SwingWorker.run(SwingWorker.java:334) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)`

Imported Comment. Original Details: Author: minht Created: 2016-03-25T09:22:13.000-0700

rbeckman-nextgen commented 4 years ago

The json check is also only checking the first character.

MessageBrowser 981 isJson = trimmedMessage.length() > 0 && (trimmedMessage.charAt(0) == '{' || trimmedMessage.charAt(0) == '[');

Imported Comment. Original Details: Author: eduardoa Created: 2016-03-25T09:25:15.000-0700