use of ca.uhn.hl7v2.HapiContext in project camel by apache.
the class HL7DataFormat method unmarshal.
public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
byte[] body = ExchangeHelper.convertToMandatoryType(exchange, byte[].class, inputStream);
String charsetName = HL7Charset.getCharsetName(body, guessCharsetName(body, exchange));
String bodyAsString = new String(body, charsetName);
Message message = HL7Converter.parse(bodyAsString, parser);
// add MSH fields as message out headers
Terser terser = new Terser(message);
for (Map.Entry<String, String> entry : HEADER_MAP.entrySet()) {
exchange.getOut().setHeader(entry.getKey(), terser.get(entry.getValue()));
}
exchange.getOut().setHeader(HL7_CONTEXT, hapiContext);
exchange.getOut().setHeader(Exchange.CHARSET_NAME, charsetName);
return message;
}
use of ca.uhn.hl7v2.HapiContext in project camel by apache.
the class HL7XmlDataFormatTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
HapiContext hapiContext = new DefaultHapiContext();
hapiContext.setValidationContext(new NoValidation());
Parser p = new GenericParser(hapiContext);
hl7 = new HL7DataFormat();
hl7.setParser(p);
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:unmarshalOk").unmarshal().hl7(false).to("mock:unmarshal");
from("direct:unmarshalOkXml").unmarshal(hl7).to("mock:unmarshal");
}
};
}
use of ca.uhn.hl7v2.HapiContext in project wildfly-camel by wildfly-extras.
the class HL7IntegrationTest method testMarshalUnmarshal.
@Test
@SuppressWarnings("resource")
public void testMarshalUnmarshal() throws Exception {
final String msg = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4\r";
final HL7DataFormat format = new HL7DataFormat();
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal(format).unmarshal(format).to("mock:result");
}
});
camelctx.start();
try {
HapiContext context = new DefaultHapiContext();
Parser p = context.getGenericParser();
Message hapimsg = p.parse(msg);
ProducerTemplate producer = camelctx.createProducerTemplate();
Message result = (Message) producer.requestBody("direct:start", hapimsg);
Assert.assertEquals(hapimsg.toString(), result.toString());
} finally {
camelctx.stop();
}
}
Aggregations