After consuming HL7 v2 files I am trying to marshal them into HAPI HL7 objects. The route sample would be:
from("file:C:\\routes\\in").unmarshal(new HL7DataFormat()).log("Success!");
Unfortunately I get the Exception:
ca.uhn.hl7v2.parser.EncodingNotSupportedException: Determine encoding for message. The following is the first 50 chars of the message for reference, although this may not be where the issue is: MSH|^~\&|...
I found that each message whish is parsed has \u000B symbol in the front, this causes the parser fail to find "MSH" header.
Of cource, I can fix it with simple string operation, like:
from("file:C:\\routes\\in")
.convertBodyTo(String.class)
.transform().simple("${in.body.trim()}")
.unmarshal(new HL7DataFormat())
.log("Success!");
But it seems to me that this is not the best solution. I've found, that if the MLLP protocol is used, the same symbol is in the front of the message, and HL7 codec should handle it. http://camel.apache.org/hl7.html
The question: Is it possible to use something like HL7Codec for File or FTP component to handle conversion to string/parsing?