org.apache.camel.dataformat.soap.SoapJaxbDataFormat Java Examples

The following examples show how to use org.apache.camel.dataformat.soap.SoapJaxbDataFormat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SoapRoutes.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public void configure() {
    final String soapPackage = GetCustomersByName.class.getPackage().getName();
    SoapJaxbDataFormat soap = new SoapJaxbDataFormat(soapPackage, new TypeNameStrategy());

    from("direct:marshal")
            .marshal(soap);

    from("direct:unmarshal")
            .unmarshal(soap);

    from("direct:marshal-soap12")
            .marshal().soapjaxb12(soapPackage);

    from("direct:unmarshal-soap12")
            .unmarshal().soapjaxb12(soapPackage);
}
 
Example #2
Source File: SOAPIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSoapMarshal() 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.xml")) {
        String expected = XMLUtils.compactXML(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.close();
    }
}
 
Example #3
Source File: SOAPIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@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.close();
    }
}
 
Example #4
Source File: SOAPIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@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.close();
    }
}
 
Example #5
Source File: SOAPIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@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.close();
    }
}
 
Example #6
Source File: SOAPServiceInterfaceStrategyIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testSOAPServiceInterfaceStrategyMarshal() throws Exception {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(CustomerService.class, true);
    final SoapJaxbDataFormat format = new SoapJaxbDataFormat("org.wildfly.camel.test.common.types", strategy);

    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.xml")) {
        Customer customer = new Customer();
        customer.setFirstName("Kermit");
        customer.setLastName("The Frog");

        ProducerTemplate template = camelctx.createProducerTemplate();
        String result = template.requestBody("direct:start", customer, String.class);
        Assert.assertEquals(XMLUtils.compactXML(input), XMLUtils.compactXML(result));
    } finally {
        camelctx.close();
    }
}
 
Example #7
Source File: SoapJaxbDataFormatAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean(name = "soapjaxb-dataformat-factory")
@ConditionalOnMissingBean(SoapJaxbDataFormat.class)
public DataFormatFactory configureSoapJaxbDataFormatFactory()
        throws Exception {
    return new DataFormatFactory() {
        @Override
        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);
                CamelPropertiesHelper.setCamelProperties(camelContext,
                        dataformat, parameters, false);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            if (ObjectHelper.isNotEmpty(customizers)) {
                for (DataFormatCustomizer<SoapJaxbDataFormat> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId)
                            ? HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.soapjaxb.customizer",
                                    ((HasId) customizer).getId())
                            : HierarchicalPropertiesEvaluator.evaluate(
                                    applicationContext.getEnvironment(),
                                    "camel.dataformat.customizer",
                                    "camel.dataformat.soapjaxb.customizer");
                    if (useCustomizer) {
                        LOGGER.debug(
                                "Configure dataformat {}, with customizer {}",
                                dataformat, customizer);
                        customizer.customize(dataformat);
                    }
                }
            }
            return dataformat;
        }
    };
}