@Override
    public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
        Message message = ExchangeHelper.convertToMandatoryType(exchange, Message.class, body);
        String charsetName = HL7Charset.getCharsetName(message, exchange);
        String encoded = parser.encode(message);
        outputStream.write(encoded.getBytes(charsetName));
    }
@Test
    public void testMarshal() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:marshal");
        mock.expectedMessageCount(1);
        mock.message(0).body().isInstanceOf(InputStream.class);
        mock.message(0).body(String.class).contains("MSA|AA|123");
        mock.message(0).body(String.class).contains("QRD|20080805120000");

        Message message = createHL7AsMessage();
        template.sendBody("direct:marshal", message);

        MockEndpoint.assertIsSatisfied(context);
    }