use of com.google.api.services.healthcare.v1.model.Message in project camel by apache.
the class HL7MLLPEncoder method encode.
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
if (message == null) {
throw new IllegalArgumentException("Message to be encoded is null");
} else if (message instanceof Exception) {
// we cannot handle exceptions
throw (Exception) message;
}
byte[] body;
if (message instanceof Message) {
body = ((Message) message).encode().getBytes(config.getCharset());
} else if (message instanceof String) {
body = ((String) message).getBytes(config.getCharset());
} else if (message instanceof byte[]) {
body = (byte[]) message;
} else {
throw new IllegalArgumentException("The message to encode is not a supported type: " + message.getClass().getCanonicalName());
}
// put the data into the byte buffer
IoBuffer buf = IoBuffer.allocate(body.length + 3).setAutoExpand(true);
buf.put((byte) config.getStartByte());
buf.put(body);
buf.put((byte) config.getEndByte1());
buf.put((byte) config.getEndByte2());
// flip the buffer so we can use it to write to the out stream
buf.flip();
LOG.debug("Encoded HL7 from {} to byte stream", message.getClass().getCanonicalName());
out.write(buf);
}
use of com.google.api.services.healthcare.v1.model.Message in project camel by apache.
the class HL7ValidateTest method testMarshalWithoutValidation.
@Test
public void testMarshalWithoutValidation() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:end");
mock.expectedMessageCount(1);
Message message = createADT01Message();
template.sendBody("direct:start2", message);
assertMockEndpointsSatisfied();
}
use of com.google.api.services.healthcare.v1.model.Message in project camel by apache.
the class HL7ValidateTest method testMarshalWithValidation.
@Test
public void testMarshalWithValidation() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:end");
mock.expectedMessageCount(0);
Message message = createADT01Message();
try {
template.sendBody("direct:start1", message);
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(HL7Exception.class, e.getCause());
assertIsInstanceOf(ValidationException.class, e.getCause().getCause());
System.out.println(e.getCause().getCause().getMessage());
assertTrue("Should be a validation error message", e.getCause().getCause().getMessage().startsWith("Validation failed:"));
}
assertMockEndpointsSatisfied();
}
use of com.google.api.services.healthcare.v1.model.Message in project camel by apache.
the class MessageValidatorTest method testDynamicCustomValidationContext.
@Test
public void testDynamicCustomValidationContext() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:test3");
mock.expectedMessageCount(1);
Message msg = createADT01Message();
template.sendBodyAndHeader("direct:test3", msg, "validator", defaultValidationContext);
assertMockEndpointsSatisfied();
}
use of com.google.api.services.healthcare.v1.model.Message in project camel by apache.
the class MessageValidatorTest method testCustomValidationContext.
@Test(expected = CamelExecutionException.class)
public void testCustomValidationContext() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:test2");
mock.expectedMessageCount(0);
Message msg = createADT01Message();
template.sendBody("direct:test2", msg);
assertMockEndpointsSatisfied();
}
Aggregations