Documenting this issue reported by Nicholas Lefebvre
----
I have found a problem with the Responder.java class of Hapi-Base since release 1.1, in the "ca.uhn.hl7v2.app" package. One Hl7Exeption is not handle. To correct this, I suggest this improvement (in bold) in the Responder.java file :
protected String processMessage(String incomingMessageString) throws HL7Exception {
HapiLog rawOutbound = HapiLogFactory.getHapiLog("ca.uhn.hl7v2.raw.outbound");
HapiLog rawInbound = HapiLogFactory.getHapiLog("ca.uhn.hl7v2.raw.inbound");
log.info( "Responder got message: " + incomingMessageString );
rawInbound.info(incomingMessageString);
Message incomingMessageObject = null;
String outgoingMessageString = null;
try {
incomingMessageObject = parser.parse(incomingMessageString);
}
catch (HL7Exception e) {
try {
outgoingMessageString = logAndMakeErrorMessage(e, parser.getCriticalResponseData(incomingMessageString), parser, parser.getEncoding(incomingMessageString));
} catch (HL7Exception e2) {
outgoingMessageString = null;
}
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);
//Here we explicitly use the same encoding as that of the inbound message - this is important with GenericParser, which might use a different encoding by default
outgoingMessageString = parser.encode(response, parser.getEncoding(incomingMessageString));
}
catch (Exception e) {
outgoingMessageString = logAndMakeErrorMessage(e, (Segment) incomingMessageObject.get("MSH"), parser, parser.getEncoding(incomingMessageString));
}
}
log.info( "Responder sending message: " + outgoingMessageString );
rawOutbound.info(outgoingMessageString);
return outgoingMessageString;
}
I tested this modification and it is solving that problem.
I hope you can take it into account before your next release of Hapi.
I worked about this bug with one of my colleague, Gabriel Landais.
Thanks a lot in advance,
Fix checked in.
Not that it was applied to ApplicationRouterImpl, as the functionality above was migrated there in the current release.