Logger rawInbound = LoggerFactory.getLogger("ca.uhn.hl7v2.raw.inbound");
log.debug("Responder got message: {}", incomingMessageString);
rawInbound.debug(incomingMessageString);
Message incomingMessageObject = null;
String outgoingMessageString = null;
try {
incomingMessageObject = parser.parse(incomingMessageString);
} catch (HL7Exception e) {
// TODO this may also throw an Exception, which hides the
// previous one.
outgoingMessageString = logAndMakeErrorMessage(e,
parser.getCriticalResponseData(incomingMessageString),
parser, parser.getEncoding(incomingMessageString));
for (Object app : apps) {
if (app instanceof ApplicationExceptionHandler) {
ApplicationExceptionHandler aeh = (ApplicationExceptionHandler) app;
outgoingMessageString = aeh.processException(
incomingMessageString, outgoingMessageString, e);
}
}
}
if (outgoingMessageString == null) {
try {
// optionally check integrity of parse
try {
if (checkWriter != null)
checkParse(incomingMessageString,
incomingMessageObject, parser);
} catch (IOException e) {
log.error("Unable to write parse check results to file", e);
}
// message validation (in terms of optionality, cardinality)
// would go here ***
Application app = findApplication(incomingMessageObject);
Message response = app.processMessage(incomingMessageObject);
if (response == null) {
throw new HL7Exception("Application of type " + app.getClass().getName() + " failed to return a response message from 'processMessage'");
}