Class DefaultHapiContext
- All Implemented Interfaces:
HapiContext,Closeable,AutoCloseable
HapiContext.
With this class you can configure HAPI and obtain all major HAPI business
objects that are initialized accordingly. All configuration objects already
have reasonable defaults.
When using Spring Framework for initializing objects, you can use the factory methods like this:
<!-- Define the context -->
<bean id="hapiContext" class="ca.uhn.hl7v2.DefaultHapiContext">
...
</bean>
<!-- Obtain the default PipeParser instance -->
<bean id="pipeParser" factory-bean="hapiContext" factory-method="getPipeParser"/>
...
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultHapiContext(HapiContext context) DefaultHapiContext(ModelClassFactory modelClassFactory) DefaultHapiContext(ParserConfiguration parserConfiguration, ValidationRuleBuilder builder, ModelClassFactory modelClassFactory) DefaultHapiContext(ParserConfiguration parserConfiguration, ValidationContext validationContext, ModelClassFactory modelClassFactory) DefaultHapiContext(ValidationRuleBuilder builder) DefaultHapiContext(ValidationContext validationContext) DefaultHapiContext(ExecutorService executorService) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Returns a ca.uhn.hl7v2.conf.check.Validator instance.<R> Validator<R>Returns the ValidationContext.Construct a new HL7 Client which will connect to an external TCP server for the purpose of sending messages (and receiving responses).Construct a new HL7 two-port client which will connect to an external TCP server for the purpose of sending messages (and receiving responses).newLazyClient(String host, int port, boolean tls) Construct a new HL7 Client which will connect to an external TCP server for the purpose of sending messages (and receiving responses).newLazyClient(String host, int outboundPort, int inboundPort, boolean tls) Construct a new HL7 two-port client which will connect to an external TCP server for the purpose of sending messages (and receiving responses).<T extends Message>
TnewMessage(Class<T> clazz) Creates a new message of the provided message structure class, without further initializing the messagenewMessage(String eventType, String triggerEvent, Version version) Creates a new message of the given event type, trigger and version, and initializes the message headernewServer(int port, boolean tls) Construct a new HL7 Server which will listen for incoming connectionsnewServer(int port, boolean tls, boolean acceptAll) Construct a new HL7 Server which will listen for incoming connections and will pass all messages to the responders, even if the message control id is not known to the servernewServer(int port1, int port2, boolean tls) Construct a new HL7 Server which will listen for a pair of connections (one for incoming messages, one for outgoing)voidsetCodeStoreRegistry(CodeStoreRegistry codeStoreRegistry) voidsetExecutorService(ExecutorService executorService) voidvoidsetModelClassFactory(ModelClassFactory modelClassFactory) voidsetParserConfiguration(ParserConfiguration configuration) voidsetProfileStore(ProfileStore profileStore) voidsetServerConfiguration(ServerConfiguration theServerConfiguration) Sets theServerConfigurationto be used by all HL7 servers obtained from this class.voidsetSocketFactory(SocketFactory socketFactory) voidsetValidationContext(ValidationContext context) voidsetValidationContext(String contextClassName) Sets a defaultValidationContext.<R> voidvoidsetValidationRuleBuilder(ValidationRuleBuilder validationRuleBuilder) Sets a defaultValidationRuleBuilder.voidsetValidationRuleBuilder(String builderClassName) Sets a new instance ofValidationRuleBuilderas default.
-
Constructor Details
-
DefaultHapiContext
public DefaultHapiContext() -
DefaultHapiContext
-
DefaultHapiContext
-
DefaultHapiContext
-
DefaultHapiContext
-
DefaultHapiContext
public DefaultHapiContext(ParserConfiguration parserConfiguration, ValidationContext validationContext, ModelClassFactory modelClassFactory) -
DefaultHapiContext
public DefaultHapiContext(ParserConfiguration parserConfiguration, ValidationRuleBuilder builder, ModelClassFactory modelClassFactory) -
DefaultHapiContext
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getExecutorService
- Specified by:
getExecutorServicein interfaceHapiContext- Returns:
- the
ExecutorServiceto be used by all services that spawn threads
-
setExecutorService
- Specified by:
setExecutorServicein interfaceHapiContext- Parameters:
executorService- theExecutorServiceto be used by all services that spawn threads
-
getConnectionHub
- Specified by:
getConnectionHubin interfaceHapiContext- Returns:
- a new ConnectionHub instance
-
getParserConfiguration
- Specified by:
getParserConfigurationin interfaceHapiContext- Returns:
- the
ParserConfigurationto be used by all parsers obtained from this class.
-
setParserConfiguration
- Specified by:
setParserConfigurationin interfaceHapiContext- Parameters:
configuration-ParserConfigurationto be used by all parsers obtained from this class.
-
getValidationContext
Returns the ValidationContext. If none has been explicitly set,getValidationRuleBuilder()is called in order to to contruct a context. If this is also null, the ca.uhn.hl7v2.validation.context_class system property is evaluated, otherwise it returns the DefaultValidation context.- Specified by:
getValidationContextin interfaceHapiContext- Returns:
- the
ValidationContextto be used by all parsers obtained from this class.
-
setValidationContext
- Specified by:
setValidationContextin interfaceHapiContext- Parameters:
context-ValidationContextto be used by all parsers obtained from this class.
-
setValidationContext
Description copied from interface:HapiContextSets a defaultValidationContext. Note that a defaultValidationRuleBuilderhas precedence of this ValidationContext.- Specified by:
setValidationContextin interfaceHapiContext- Parameters:
contextClassName- class name of theValidationContextto be used by all parsers obtained from this class.
-
getValidationRuleBuilder
- Specified by:
getValidationRuleBuilderin interfaceHapiContext- Returns:
- the
ValidationRuleBuilderto be used by all parsers obtained from this class.
-
setValidationRuleBuilder
Description copied from interface:HapiContextSets a defaultValidationRuleBuilder. Note that thisValidationRuleBuilderhas precedence over a defaultValidationContextset withHapiContext.setValidationContext(ValidationContext)orHapiContext.setValidationContext(String)- Specified by:
setValidationRuleBuilderin interfaceHapiContext- Parameters:
validationRuleBuilder-ValidationRuleBuilderto be used by all parsers obtained from this class.
-
setValidationRuleBuilder
Description copied from interface:HapiContextSets a new instance ofValidationRuleBuilderas default. Note that thisValidationRuleBuilderhas precedence over a defaultValidationContextset withHapiContext.setValidationContext(ValidationContext)orHapiContext.setValidationContext(String)- Specified by:
setValidationRuleBuilderin interfaceHapiContext- Parameters:
builderClassName- class name of theValidationRuleBuilderto be used by all parsers obtained from this class.
-
getModelClassFactory
- Specified by:
getModelClassFactoryin interfaceHapiContext- Returns:
- the
ModelClassFactoryto be used by all parsers obtained from this class.
-
setModelClassFactory
- Specified by:
setModelClassFactoryin interfaceHapiContext- Parameters:
modelClassFactory- theModelClassFactoryto be used by all parsers obtained from this class.
-
getProfileStore
- Specified by:
getProfileStorein interfaceHapiContext- Returns:
- the
ProfileStoreto be used for loading conformance profile files
-
setProfileStore
- Specified by:
setProfileStorein interfaceHapiContext- Parameters:
profileStore- theProfileStoreto be used for loading conformance profile files
-
getCodeStoreRegistry
- Specified by:
getCodeStoreRegistryin interfaceHapiContext- Returns:
- the
CodeStoreRegistryto be used for serving codes for conformance profiles
-
setCodeStoreRegistry
- Specified by:
setCodeStoreRegistryin interfaceHapiContext- Parameters:
codeStoreRegistry- theCodeStoreRegistryto be used for serving codes for conformance profiles
-
getConformanceValidator
Description copied from interface:HapiContextReturns a ca.uhn.hl7v2.conf.check.Validator instance. It is recommended to useHapiContext.getMessageValidator()and configure a Validation rule that checks a message against a conformance profile- Specified by:
getConformanceValidatorin interfaceHapiContext- Returns:
- a ca.uhn.hl7v2.conf.check.Validator instance initialized as set with
HapiContext.setCodeStoreRegistry(CodeStoreRegistry)
-
getPipeParser
- Specified by:
getPipeParserin interfaceHapiContext- Returns:
- a new PipeParser instance initialized as set with
HapiContext.setModelClassFactory(ModelClassFactory),HapiContext.setValidationContext(String)andHapiContext.setParserConfiguration(ParserConfiguration).
-
getXMLParser
- Specified by:
getXMLParserin interfaceHapiContext- Returns:
- a new XMLParser instance initialized as set with
HapiContext.setModelClassFactory(ModelClassFactory),HapiContext.setValidationContext(String)andHapiContext.setParserConfiguration(ParserConfiguration).
-
getGenericParser
- Specified by:
getGenericParserin interfaceHapiContext- Returns:
- a new GenericParser instance initialized as set with
HapiContext.setModelClassFactory(ModelClassFactory),HapiContext.setValidationContext(String)andHapiContext.setParserConfiguration(ParserConfiguration).
-
getMessageValidator
- Specified by:
getMessageValidatorin interfaceHapiContext- Returns:
- a MessageValidator instance initialized with the
ValidationContextas set usingHapiContext.setValidationContext(ValidationContext). For each validation it will use a new instance ofValidationExceptionHandleras obtained byHapiContext.getValidationExceptionHandlerFactory().
-
getValidationExceptionHandlerFactory
- Specified by:
getValidationExceptionHandlerFactoryin interfaceHapiContext
-
setValidationExceptionHandlerFactory
- Specified by:
setValidationExceptionHandlerFactoryin interfaceHapiContext- Parameters:
factory- aValidationExceptionHandlerFactorythat is used to create aValidationExceptionHandlerduring message validation.
-
getLowerLayerProtocol
- Specified by:
getLowerLayerProtocolin interfaceHapiContext- Returns:
- the
LowerLayerProtocolinstance used by all HL7 MLLP operations
-
setLowerLayerProtocol
- Specified by:
setLowerLayerProtocolin interfaceHapiContext- Parameters:
llp- theLowerLayerProtocolinstance used by all HL7 MLLP operations
-
getSocketFactory
- Specified by:
getSocketFactoryin interfaceHapiContext- Returns:
- the
SocketFactoryinstance used by HL7 networking operations
-
setSocketFactory
- Specified by:
setSocketFactoryin interfaceHapiContext- Parameters:
socketFactory- theSocketFactoryinstance used by HL7 networking operations
-
newServer
Description copied from interface:HapiContextConstruct a new HL7 Server which will listen for incoming connections- Specified by:
newServerin interfaceHapiContext- Parameters:
port- The port on which to listen for new connectionstls- Whether or not to use SSL/TLS- Returns:
- HL7 service running on the configured port using the default parser and executor
service instances provided by this interface. Note that the returned service will not
be started, and must manually be started using
Service.start()orService.startAndWait() - See Also:
-
- here for an example of how to use this method
HapiContext.setSocketFactory(SocketFactory)
-
newServer
Description copied from interface:HapiContextConstruct a new HL7 Server which will listen for incoming connections and will pass all messages to the responders, even if the message control id is not known to the server- Specified by:
newServerin interfaceHapiContext- Parameters:
port- The port on which to listen for new connectionstls- Whether or not to use SSL/TLSacceptAll- Whether or not to accept all messages- Returns:
- HL7 service running on the configured port using the default parser and executor
service instances provided by this interface. Note that the returned service will not
be started, and must manually be started using
Service.start()orService.startAndWait() - See Also:
-
newServer
Description copied from interface:HapiContextConstruct a new HL7 Server which will listen for a pair of connections (one for incoming messages, one for outgoing)- Specified by:
newServerin interfaceHapiContext- Parameters:
port1- The port on which to listen for connections for inbound messagesport2- The port on which to listen for connections for outgoing messagestls- Whether or not to use SSL/TLS- Returns:
- HL7 service running on the configured ports using the default parser and executor
service instances provided by this interface. Note that the returned service will not
be started, and must manually be started using
Service.start()orService.startAndWait() - See Also:
-
- here for an example of how to use this method
HapiContext.setSocketFactory(SocketFactory)
-
newClient
Description copied from interface:HapiContextConstruct a new HL7 Client which will connect to an external TCP server for the purpose of sending messages (and receiving responses). Unless otherwise stated, the connection is established by the time this method returns, or an exception should be thrown if the connection can not be established. If a connection to this server already exists, it is reused.Note that connections are pooled by the HapiContext by default. If multiple concurrent connections to the same server are required, the easiest way to accomplish this is currently to create multiple HapiContext instances.
- Specified by:
newClientin interfaceHapiContext- Parameters:
host- The host IP/hostname to connect toport- The port to connect totls- Whether or not to use SSL/TLS- Returns:
- Returns a connection which can be used to transmit messages. Note that this method will attempt to connect to the specified address, and will throw an exception if it fails to connect.
- Throws:
HL7Exception- If the connection can not be initialized for any reason- See Also:
-
- here for an example of how to use this method
-
newClient
public Connection newClient(String host, int outboundPort, int inboundPort, boolean tls) throws HL7Exception Description copied from interface:HapiContextConstruct a new HL7 two-port client which will connect to an external TCP server for the purpose of sending messages (and receiving responses). Unless otherwise stated, the connection is established by the time this method returns, or an exception should be thrown if the connection can not be established. If a connection to this server already exists, it is reused.Note that connections are pooled by the HapiContext by default. If multiple concurrent connections to the same server are required, the easiest way to accomplish this is currently to create multiple HapiContext instances.
- Specified by:
newClientin interfaceHapiContext- Parameters:
host- The host IP/hostname to connect tooutboundPort- The port to connect to for outgoing messagesinboundPort- The port to connect to for inbound (response) messagestls- Whether or not to use SSL/TLS- Returns:
- Returns a connection which can be used to transmit messages. Note that this method will attempt to connect to the specified address, and will throw an exception if it fails to connect.
- Throws:
HL7Exception- If the connection can not be initialized for any reason
-
newLazyClient
Description copied from interface:HapiContextConstruct a new HL7 Client which will connect to an external TCP server for the purpose of sending messages (and receiving responses). The connection should be established by the time the first message is sent.Note that connections are pooled by the HapiContext by default. If multiple concurrent connections to the same server are required, the easiest way to accomplish this is currently to create multiple HapiContext instances.
- Specified by:
newLazyClientin interfaceHapiContext- Parameters:
host- The host IP/hostname to connect toport- The port to connect totls- Whether or not to use SSL/TLS- Returns:
- Returns a connection which can be used to transmit messages.
- Throws:
HL7Exception- If the connection can not be initialized for any reason- See Also:
-
- here for an example of how to use this method
-
newLazyClient
public Connection newLazyClient(String host, int outboundPort, int inboundPort, boolean tls) throws HL7Exception Description copied from interface:HapiContextConstruct a new HL7 two-port client which will connect to an external TCP server for the purpose of sending messages (and receiving responses). The connection should be established by the time the first message is sent.Note that connections are pooled by the HapiContext by default. If multiple concurrent connections to the same server are required, the easiest way to accomplish this is currently to create multiple HapiContext instances.
- Specified by:
newLazyClientin interfaceHapiContext- Parameters:
host- The host IP/hostname to connect tooutboundPort- The port to connect to for outgoing messagesinboundPort- The port to connect to for inbound (response) messagestls- Whether or not to use SSL/TLS- Returns:
- Returns a connection which can be used to transmit messages.
- Throws:
HL7Exception- If the connection can not be initialized for any reason
-
getServerConfiguration
- Specified by:
getServerConfigurationin interfaceHapiContext- Returns:
- the
ServerConfigurationto be used by all HL7 servers obtained from this class. - See Also:
-
setServerConfiguration
Description copied from interface:HapiContextSets theServerConfigurationto be used by all HL7 servers obtained from this class.- Specified by:
setServerConfigurationin interfaceHapiContext- See Also:
-
newMessage
public Message newMessage(String eventType, String triggerEvent, Version version) throws HL7Exception Description copied from interface:HapiContextCreates a new message of the given event type, trigger and version, and initializes the message header- Specified by:
newMessagein interfaceHapiContext- Parameters:
eventType- event type, e.g. ADTtriggerEvent- trigger event, e.g. A01version- HL7v2 version- Returns:
- Message object of the type determined by the underlying model class factory
- Throws:
HL7Exception- if no message object could be created
-
newMessage
Description copied from interface:HapiContextCreates a new message of the provided message structure class, without further initializing the message- Specified by:
newMessagein interfaceHapiContext- Type Parameters:
T- message structure class type- Parameters:
clazz- message structure class- Returns:
- the created message instance
- Throws:
HL7Exception
-