private boolean addTargets(CamelContext camelContext) throws CamelException { for (String routeId : routeIds) { try { Mina2Consumer consumer = (Mina2Consumer) camelContext.getRoute(routeId).getConsumer(); Hl7v2Interceptor interceptor = (Hl7v2Interceptor) consumer.getProcessor(); while (!(interceptor instanceof ConsumerStringProcessingInterceptor)) { interceptor = (Hl7v2Interceptor) interceptor.getWrappedProcessor(); } LOG.debug("Adding MLLP transaction route {} to dispatcher", routeId); map.put(routeId, (Hl7v2Interceptor) interceptor.getWrappedProcessor()); } catch (NullPointerException e) { throw new CamelException( "Route with ID='" + routeId + "' not found or is not an IPF MLLP route", e); } catch (ClassCastException e) { throw new CamelException("Route with ID='" + routeId + "' is not an IPF MLLP route", e); } } return !map.isEmpty(); }
@Override public void process(Exchange exchange) throws Exception { // determine attributes of the message String message = exchange.getIn().getBody(String.class); String[] fields = PreParser.getFields(message, "MSH-9-1", "MSH-9-2", "MSH-9-3", "MSH-12"); String messageType = fields[0]; String triggerEvent = fields[1]; String messageStructure = fields[2]; String version = fields[3]; // check who can accept the message boolean found = false; for (String routeId : routeIds) { Hl7v2Interceptor interceptor = map.get(routeId); Hl7v2TransactionConfiguration config = interceptor.getConfigurationHolder().getHl7v2TransactionConfiguration(); try { config.checkMessageAcceptance(messageType, triggerEvent, messageStructure, version, true); LOG.debug( "Dispatch message with MSH-9-1='{}', MSH-9-2='{}', MSH-9-3='{}', MSH-12='{}' to route '{}'", messageType, triggerEvent, messageStructure, version, routeId); found = true; interceptor.process(exchange); break; } catch (Hl7v2AcceptanceException e) { // no problem } } if (!found) { LOG.debug( "Nobody can process message with MSH-9-1='{}', MSH-9-2='{}', MSH-9-3='{}', MSH-12='{}'", messageType, triggerEvent, messageStructure, version); HL7Exception exception = new HL7Exception( "Unsupported message type and/or version", ErrorCode.APPLICATION_INTERNAL_ERROR); resultMessage(exchange).setBody(getNakFactory().createDefaultNak(exception).encode()); } }