Search in sources :

Example 6 with JaxbDataFormat

use of org.apache.camel.model.dataformat.JaxbDataFormat in project wildfly-camel by wildfly-extras.

the class JAXBIntegrationTest method testJaxbMarshal.

@Test
public void testJaxbMarshal() throws Exception {
    final JaxbDataFormat format = new JaxbDataFormat();
    format.setContextPath("org.wildfly.camel.test.jaxb.model");
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").marshal(format);
        }
    });
    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/customer.xml")) {
        String expected = XMLUtils.compactXML(input);
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Customer customer = new Customer("John", "Doe");
        String result = producer.requestBody("direct:start", customer, String.class);
        Assert.assertEquals(expected, XMLUtils.compactXML(result));
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) Customer(org.wildfly.camel.test.jaxb.model.Customer) InputStream(java.io.InputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) JaxbDataFormat(org.apache.camel.model.dataformat.JaxbDataFormat) Test(org.junit.Test)

Aggregations

JaxbDataFormat (org.apache.camel.model.dataformat.JaxbDataFormat)6 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 InputStream (java.io.InputStream)2 CamelContext (org.apache.camel.CamelContext)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 Test (org.junit.Test)2 Customer (org.wildfly.camel.test.jaxb.model.Customer)2 SoapJaxbDataFormat (org.apache.camel.model.dataformat.SoapJaxbDataFormat)1