/** * Registers the given application to handle messages corresponding to ALL * message types and trigger events. */ public synchronized void registerApplication(AppRoutingData appRouting, ReceivingApplication<? extends Message> application) { if (appRouting == null) { throw new NullPointerException("appRouting must not be null"); } applicationRouter.bindApplication(appRouting, application); }
/** * @see ca.uhn.hl7v2.protocol.ApplicationRouter#enableBinding(ca.uhn.hl7v2.protocol.ApplicationRouter.AppRoutingData) */ public void enableBinding(AppRoutingData theRoutingData) { Binding b = findBinding(theRoutingData); if (b != null) { b.active = true; } }
/** * @see ca.uhn.hl7v2.protocol.ApplicationRouter#hasActiveBinding(ca.uhn.hl7v2.protocol.ApplicationRouter.AppRoutingData) */ public boolean hasActiveBinding(AppRoutingData theRoutingData) { boolean result = false; ReceivingApplication<? extends Message> app = findDestination(null, theRoutingData); if (app != null) { result = true; } return result; }
log.debug("Exception parsing incoming message", e); try { outgoingMessageString = logAndMakeErrorMessage(e, myParser.getCriticalResponseData(incomingMessageString), myParser, myParser.getEncoding(incomingMessageString)); } catch (HL7Exception e2) { log.error("Exception occurred while logging parse failure", e2); ReceivingApplication<Message> app = findApplication(incomingMessageObject); theMetadata.put(RAW_MESSAGE_KEY, incomingMessageString); outgoingMessageCharset = t.get(METADATA_KEY_MESSAGE_CHARSET); } catch (Exception e) { outgoingMessageString = handleProcessMessageException(incomingMessageString, theMetadata, incomingMessageObject, e); } catch (Error e) { log.debug("Caught runtime exception of type {}, going to wrap it as HL7Exception and handle it", e.getClass()); HL7Exception wrapped = new HL7Exception(e); outgoingMessageString = handleProcessMessageException(incomingMessageString, theMetadata, incomingMessageObject, wrapped);
/** * @param theMessage message for which a destination is looked up * @param theRoutingData routing data * @return the application from the binding with a WILDCARD match, if one exists */ private <T extends Message> ReceivingApplication<T> findDestination(T theMessage, AppRoutingData theRoutingData) { ReceivingApplication<? extends Message> result = null; for (int i = 0; i < myBindings.size() && result == null; i++) { Binding binding = myBindings.get(i); if (matches(theRoutingData, binding.routingData) && binding.active) { if (theMessage == null || ((ReceivingApplication<T>)binding.application).canProcess(theMessage)) { result = binding.application; } } } return (ReceivingApplication<T>)result; }
/** * Creates a new instance of Server * * @param parser parser to be used * @param llp LowerLayerProtocol * @param executorService executor used for starting threads */ public HL7Service(Parser parser, LowerLayerProtocol llp, ExecutorService executorService) { super("HL7 Server", executorService); this.connections = new ArrayList<Connection>(); this.listeners = new ArrayList<ConnectionListener>(); this.parser = parser; this.llp = llp; this.applicationRouter = new ApplicationRouterImpl(parser); this.cleaner = new ConnectionCleaner(this); // 960101 assert !this.cleaner.isRunning(); }
/** * Creates an instance that uses the specified <code>Parser</code>. * * @param theContext HAPI context * @param theParser the parser used for converting between Message and * Transportable * @deprecated define parser over context */ public ApplicationRouterImpl(HapiContext theContext, Parser theParser) { init(theParser); myContext = theContext; }
private String handleProcessMessageException(String incomingMessageString, Map<String, Object> theMetadata, Message incomingMessageObject, Exception e) throws HL7Exception { String outgoingMessageString; Segment inHeader = incomingMessageObject != null ? (Segment) incomingMessageObject.get("MSH") : null; outgoingMessageString = logAndMakeErrorMessage(e, inHeader, myParser, myParser.getEncoding(incomingMessageString)); if (outgoingMessageString != null && myExceptionHandler != null) { outgoingMessageString = myExceptionHandler.processException(incomingMessageString, theMetadata, outgoingMessageString, e); } return outgoingMessageString; }
Message out = hl7e.getResponseMessage(); if (out == null) { Message in = getInMessage(inHeader); out = in.generateACK(defaultAcknowledgementMode, hl7e);
log.debug("Exception parsing incoming message", e); try { outgoingMessageString = logAndMakeErrorMessage(e, myParser.getCriticalResponseData(incomingMessageString), myParser, myParser.getEncoding(incomingMessageString)); } catch (HL7Exception e2) { log.error("Exception occurred while logging parse failure", e2); ReceivingApplication<Message> app = findApplication(incomingMessageObject); theMetadata.put(RAW_MESSAGE_KEY, incomingMessageString); outgoingMessageCharset = t.get(METADATA_KEY_MESSAGE_CHARSET); } catch (Exception e) { outgoingMessageString = handleProcessMessageException(incomingMessageString, theMetadata, incomingMessageObject, e); } catch (Error e) { log.debug("Caught runtime exception of type {}, going to wrap it as HL7Exception and handle it", e.getClass()); HL7Exception wrapped = new HL7Exception(e); outgoingMessageString = handleProcessMessageException(incomingMessageString, theMetadata, incomingMessageObject, wrapped);
/** * @param theMessage message for which a destination is looked up * @param theRoutingData routing data * @return the application from the binding with a WILDCARD match, if one exists */ private <T extends Message> ReceivingApplication<T> findDestination(T theMessage, AppRoutingData theRoutingData) { ReceivingApplication<? extends Message> result = null; for (int i = 0; i < myBindings.size() && result == null; i++) { Binding binding = myBindings.get(i); if (matches(theRoutingData, binding.routingData) && binding.active) { if (theMessage == null || ((ReceivingApplication<T>)binding.application).canProcess(theMessage)) { result = binding.application; } } } return (ReceivingApplication<T>)result; }
/** * Creates a new instance of Server * * @param parser parser to be used * @param llp LowerLayerProtocol * @param executorService executor used for starting threads */ public HL7Service(Parser parser, LowerLayerProtocol llp, ExecutorService executorService) { super("HL7 Server", executorService); this.connections = new ArrayList<Connection>(); this.listeners = new ArrayList<ConnectionListener>(); this.parser = parser; this.llp = llp; this.applicationRouter = new ApplicationRouterImpl(parser); this.cleaner = new ConnectionCleaner(this); // 960101 assert !this.cleaner.isRunning(); }
/** * Creates an instance that uses the specified <code>Parser</code>. * * @param theContext HAPI context * @param theParser the parser used for converting between Message and * Transportable * @deprecated define parser over context */ public ApplicationRouterImpl(HapiContext theContext, Parser theParser) { init(theParser); myContext = theContext; }
private String handleProcessMessageException(String incomingMessageString, Map<String, Object> theMetadata, Message incomingMessageObject, Exception e) throws HL7Exception { String outgoingMessageString; Segment inHeader = incomingMessageObject != null ? (Segment) incomingMessageObject.get("MSH") : null; outgoingMessageString = logAndMakeErrorMessage(e, inHeader, myParser, myParser.getEncoding(incomingMessageString)); if (outgoingMessageString != null && myExceptionHandler != null) { outgoingMessageString = myExceptionHandler.processException(incomingMessageString, theMetadata, outgoingMessageString, e); } return outgoingMessageString; }
Message out = hl7e.getResponseMessage(); if (out == null) { Message in = getInMessage(inHeader); out = in.generateACK(defaultAcknowledgementMode, hl7e);
/** * @see ca.uhn.hl7v2.protocol.ApplicationRouter#enableBinding(ca.uhn.hl7v2.protocol.ApplicationRouter.AppRoutingData) */ public void enableBinding(AppRoutingData theRoutingData) { Binding b = findBinding(theRoutingData); if (b != null) { b.active = true; } }
/** * Registers the given application to handle messages corresponding to ALL * message types and trigger events. */ public synchronized void registerApplication(AppRoutingData appRouting, ReceivingApplication<? extends Message> application) { if (appRouting == null) { throw new NullPointerException("appRouting must not be null"); } applicationRouter.bindApplication(appRouting, application); }
/** * @see ca.uhn.hl7v2.protocol.ApplicationRouter#hasActiveBinding(ca.uhn.hl7v2.protocol.ApplicationRouter.AppRoutingData) */ public boolean hasActiveBinding(AppRoutingData theRoutingData) { boolean result = false; ReceivingApplication<? extends Message> app = findDestination(null, theRoutingData); if (app != null) { result = true; } return result; }
/** * @param theMessageData routing data related to a particular message * @param theReferenceData routing data related to a binding, which may include * wildcards * @return true if the message data is consist with the reference data, ie all * values either match or are wildcards in the reference */ public static boolean matches(AppRoutingData theMessageData, AppRoutingData theReferenceData) { boolean result = false; if (matches(theMessageData.getMessageType(), theReferenceData.getMessageType()) && matches(theMessageData.getTriggerEvent(), theReferenceData.getTriggerEvent()) && matches(theMessageData.getProcessingId(), theReferenceData.getProcessingId()) && matches(theMessageData.getVersion(), theReferenceData.getVersion())) { result = true; } return result; }
ApplicationRouter router = new ApplicationRouterImpl();