@Bean @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(SoapJaxbDataFormat.class) public SoapJaxbDataFormat configureSoapJaxbDataFormat( CamelContext camelContext, SoapJaxbDataFormatConfiguration configuration) throws Exception { SoapJaxbDataFormat dataformat = new SoapJaxbDataFormat(); if (dataformat instanceof CamelContextAware) { ((CamelContextAware) dataformat).setCamelContext(camelContext); } Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration, parameters, null, false); IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters); return dataformat; }
@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.stop(); } }
@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(); } }
@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(); } }
@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(); } }
/** * Create data format by using the constructor */ protected SoapJaxbDataFormat createDataFormat() { String jaxbPackage = GetCustomersByName.class.getPackage().getName(); ElementNameStrategy elStrat = new TypeNameStrategy(); SoapJaxbDataFormat answer = new SoapJaxbDataFormat(jaxbPackage, elStrat); answer.setVersion("1.2"); return answer; }
@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"); } }; }
@Bean(name = "rivtaObservationsDataFormat") public SoapJaxbDataFormat soapJaxbDataFormat() { return new SoapJaxbDataFormat("se.riv.clinicalprocess.healthcond.basic.getobservationsresponder.v1", new ServiceInterfaceStrategy( se.riv.clinicalprocess.healthcond.basic.getobservations.v1.rivtabp21.GetObservationsResponderInterface.class, false)); }
@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.stop(); } }