Package org.apache.camel.component.hl7
Class HL7DataFormat
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.component.hl7.HL7DataFormat
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.DataFormat,org.apache.camel.spi.DataFormatName,org.apache.camel.StatefulService,org.apache.camel.SuspendableService
@Dataformat("hl7")
public class HL7DataFormat
extends org.apache.camel.support.service.ServiceSupport
implements org.apache.camel.spi.DataFormat, org.apache.camel.spi.DataFormatName
HL7 DataFormat (supports v2.x of the HL7 protocol).
This data format supports two operations:
- marshal = from Message to String (can be used when returning as response using the HL7 MLLP codec)
- unmarshal = from String to Message (can be used when receiving streamed data from the HL7 MLLP codec). This operation will also enrich the message by adding the MSH fields (MSH-3 to MSH-12) as headers on the message.
- CamelHL7SendingApplication = MSH-3
- CamelHL7SendingFacility = MSH-4
- CamelHL7ReceivingApplication = MSH-5
- CamelHL7ReceivingFacility = MSH-6
- CamelHL7Timestamp = MSH-7
- CamelHL7Security = MSH-8
- CamelHL7MessageType = MSH-9-1
- CamelHL7TriggerEvent = MSH-9-2
- CamelHL7MessageControl = MSH-10
- CamelHL7ProcessingId = MSH-11
- CamelHL7VersionId = MSH-12
- CamelHL7Charset = MSH-18
- See Also:
-
Field Summary
Fields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoStart()protected voiddoStop()ca.uhn.hl7v2.HapiContextca.uhn.hl7v2.parser.Parserprotected StringguessCharsetName(byte[] b, org.apache.camel.Exchange exchange) In HL7 the charset of the message can be set in MSH-18, but you need to decode the input stream in order to be able to read MSH-18.booleanvoidmarshal(org.apache.camel.Exchange exchange, Object body, OutputStream outputStream) voidsetHapiContext(ca.uhn.hl7v2.HapiContext context) voidsetParser(ca.uhn.hl7v2.parser.Parser parser) voidsetValidate(boolean validate) unmarshal(org.apache.camel.Exchange exchange, InputStream inputStream) Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getInternalLock, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.camel.spi.DataFormat
unmarshalMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Constructor Details
-
HL7DataFormat
public HL7DataFormat()
-
-
Method Details
-
getDataFormatName
- Specified by:
getDataFormatNamein interfaceorg.apache.camel.spi.DataFormatName
-
marshal
public void marshal(org.apache.camel.Exchange exchange, Object body, OutputStream outputStream) throws Exception - Specified by:
marshalin interfaceorg.apache.camel.spi.DataFormat- Throws:
Exception
-
unmarshal
public Object unmarshal(org.apache.camel.Exchange exchange, InputStream inputStream) throws Exception - Specified by:
unmarshalin interfaceorg.apache.camel.spi.DataFormat- Throws:
Exception
-
isValidate
public boolean isValidate() -
setValidate
public void setValidate(boolean validate) -
getHapiContext
public ca.uhn.hl7v2.HapiContext getHapiContext() -
setHapiContext
public void setHapiContext(ca.uhn.hl7v2.HapiContext context) -
getParser
public ca.uhn.hl7v2.parser.Parser getParser() -
setParser
public void setParser(ca.uhn.hl7v2.parser.Parser parser) -
doStart
- Overrides:
doStartin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doStop
- Overrides:
doStopin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
guessCharsetName
In HL7 the charset of the message can be set in MSH-18, but you need to decode the input stream in order to be able to read MSH-18. This works well for differentiating e.g. between ASCII, UTF-8 and ISI-8859 charsets, but not for multi-byte charsets like UTF-16, Big5 etc. This method is called to "guess" the initial encoding, and subclasses can overwrite it using 3rd party libraries like ICU4J that provide a CharsetDetector. The implementation in this class just assumes the charset defined in the exchange property or header by callingExchangeHelper.getCharsetName(Exchange).- Parameters:
b- byte arrayexchange- the exchange- Returns:
- charset name
-