2

Hapi xml parser is giving following exception while encoding the HL7 v2.7 message using Hapi Xml Parser.

ca.uhn.hl7v2.HL7Exception: Can't XML-encode a GenericMessage. Message must have a recognized structure.

Below is my code snippet that i am using to encode message

HapiContext context = new DefaultHapiContext(modelClassFactory)
PipeParser pipeParser = context.getPipeParser();
pipeParser.setValidationContext(new NoValidation());                    
pipeParser.getParserConfiguration().setAllowUnknownVersions(true);
Message msg = pipeParser.parse(document);   
Parser xmlParser = context.getXMLParser();      
return xmlParser.encode(msg); 

Any suggestion/solutions?

vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30
umair yasin
  • 159
  • 1
  • 2
  • 16

1 Answers1

0

This exception is thrown if the message you try to encode has no specific type but is a GenericMessage instead. It seems as if HAPI cannot determine the right message type for your document. If you increase the log level of HAPI to DEBUG, it might give you a clue why the PipeParser cannot create an instance of a specific message type.

Tillmann Seidel
  • 1,032
  • 1
  • 12
  • 20