ack.getMSH().getFieldSeparator().setValue(HL7Constants.HL7_FIELD_SEPARATOR);
ack.getMSH().getEncodingCharacters().setValue(HL7Constants.HL7_ENCODING_CHARS);
ack.getMSA().getAcknowledgmentCode().setValue(HL7Constants.HL7_ACK_CODE_AR);
ack.getERR().getErrorCodeAndLocation(0).getCodeIdentifyingError().getIdentifier()
.setValue("Backend service reject the value");
String msg = new PipeParser().encode(ack);
if (log.isDebugEnabled()) {
log.debug("Generate HL7 error : " + ack);
}
outputStream.write(msg.getBytes());
outputStream.flush();
outputStream.close();
msgCtx.setProperty(Constants.Configuration.CONTENT_TYPE,HL7Constants.HL7_CONTENT_TYPE);
} catch (DataTypeException e) {
handleException("Error on creating HL7 Error segment", e);
} catch (HL7Exception e) {
handleException("Error on creating HL7 Error segment", e);
} catch (IOException e) {
handleException("Error on writing HL7 Error to output stream", e);
}
} else {
try {
String xmlFormat = omElement.toString();
Message message = new DefaultXMLParser().parse(xmlFormat);
String msg = new PipeParser().encode(message);
if (log.isDebugEnabled()) {
log.debug("Message inside the formatter : " + message);
}
outputStream.write(msg.getBytes());
outputStream.flush();