Search in sources :

Example 1 with SoapJaxbDataFormat

use of org.apache.camel.dataformat.soap.SoapJaxbDataFormat in project camel by apache.

the class SoapJaxbDataFormatAutoConfiguration method configureSoapJaxbDataFormatFactory.

@Bean(name = "soapjaxb-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(SoapJaxbDataFormat.class)
public DataFormatFactory configureSoapJaxbDataFormatFactory(final CamelContext camelContext, final SoapJaxbDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            SoapJaxbDataFormat dataformat = new SoapJaxbDataFormat();
            if (CamelContextAware.class.isAssignableFrom(SoapJaxbDataFormat.class)) {
                CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
                if (contextAware != null) {
                    contextAware.setCamelContext(camelContext);
                }
            }
            try {
                Map<String, Object> parameters = new HashMap<>();
                IntrospectionSupport.getProperties(configuration, parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            return dataformat;
        }
    };
}
Also used : DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) SoapJaxbDataFormat(org.apache.camel.dataformat.soap.SoapJaxbDataFormat) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with SoapJaxbDataFormat

use of org.apache.camel.dataformat.soap.SoapJaxbDataFormat in project camel by apache.

the class Soap12MarshalTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            SoapJaxbDataFormat df = createDataFormat();
            //
            from("direct:start").marshal(//
            df).to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) SoapJaxbDataFormat(org.apache.camel.dataformat.soap.SoapJaxbDataFormat)

Example 3 with SoapJaxbDataFormat

use of org.apache.camel.dataformat.soap.SoapJaxbDataFormat in project wildfly-camel by wildfly-extras.

the class SOAPIntegrationTest method testSoapUnmarshal.

@Test
public void testSoapUnmarshal() throws Exception {
    final SoapJaxbDataFormat format = new SoapJaxbDataFormat();
    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").unmarshal(format);
        }
    });
    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/envelope.xml")) {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Element response = producer.requestBody("direct:start", input, Element.class);
        Assert.assertEquals("Customer", response.getLocalName());
    } 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) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) SoapJaxbDataFormat(org.apache.camel.dataformat.soap.SoapJaxbDataFormat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 4 with SoapJaxbDataFormat

use of org.apache.camel.dataformat.soap.SoapJaxbDataFormat in project wildfly-camel by wildfly-extras.

the class SOAPIntegrationTest method testSoapV1_2Marshal.

@Test
public void testSoapV1_2Marshal() throws Exception {
    final SoapJaxbDataFormat format = new SoapJaxbDataFormat();
    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("/envelope-1.2-marshal.xml")) {
        String expected = camelctx.getTypeConverter().mandatoryConvertTo(String.class, input);
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Customer customer = new Customer("John", "Doe");
        String customerXML = producer.requestBody("direct:start", customer, String.class);
        Assert.assertEquals(expected, XMLUtils.compactXML(customerXML));
    } 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) SoapJaxbDataFormat(org.apache.camel.dataformat.soap.SoapJaxbDataFormat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 5 with SoapJaxbDataFormat

use of org.apache.camel.dataformat.soap.SoapJaxbDataFormat in project wildfly-camel by wildfly-extras.

the class SOAPIntegrationTest method testSoapV1_2Unmarshal.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").unmarshal(format);
        }
    });
    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/envelope-1.2-unmarshal.xml")) {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Element response = producer.requestBody("direct:start", input, Element.class);
        Assert.assertEquals("Customer", response.getLocalName());
    } 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) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) SoapJaxbDataFormat(org.apache.camel.dataformat.soap.SoapJaxbDataFormat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

SoapJaxbDataFormat (org.apache.camel.dataformat.soap.SoapJaxbDataFormat)8 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 InputStream (java.io.InputStream)5 CamelContext (org.apache.camel.CamelContext)5 ProducerTemplate (org.apache.camel.ProducerTemplate)5 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)5 Test (org.junit.Test)5 Element (org.w3c.dom.Element)2 Customer (org.wildfly.camel.test.jaxb.model.Customer)2 GetCustomersByName (com.example.customerservice.GetCustomersByName)1 HashMap (java.util.HashMap)1 CamelContextAware (org.apache.camel.CamelContextAware)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 ElementNameStrategy (org.apache.camel.dataformat.soap.name.ElementNameStrategy)1 ServiceInterfaceStrategy (org.apache.camel.dataformat.soap.name.ServiceInterfaceStrategy)1 TypeNameStrategy (org.apache.camel.dataformat.soap.name.TypeNameStrategy)1 DataFormatFactory (org.apache.camel.spi.DataFormatFactory)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1