Search in sources :

Example 16 with XmlConverter

use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.

the class CxfPayLoadMessageXmlBindingRouterTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            from("cxf:bean:routerEndpoint?dataFormat=PAYLOAD").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    CxfPayload<?> payload = exchange.getIn().getBody(CxfPayload.class);
                    List<Source> elements = payload.getBodySources();
                    assertNotNull("We should get the elements here", elements);
                    assertEquals("Get the wrong elements size", elements.size(), 1);
                    Element el = new XmlConverter().toDOMElement(elements.get(0));
                    assertEquals("Get the wrong namespace URI", el.getNamespaceURI(), "http://cxf.component.camel.apache.org/");
                }
            }).to("cxf:bean:serviceEndpoint?dataFormat=PAYLOAD");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Element(org.w3c.dom.Element) Source(javax.xml.transform.Source) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 17 with XmlConverter

use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.

the class CxfPayLoadSoapHeaderTest method createRouteBuilder.

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

        public void configure() {
            // START SNIPPET: payload
            from(getRouterEndpointURI()).process(new Processor() {

                @SuppressWarnings("unchecked")
                public void process(Exchange exchange) throws Exception {
                    CxfPayload<SoapHeader> payload = exchange.getIn().getBody(CxfPayload.class);
                    List<Source> elements = payload.getBodySources();
                    assertNotNull("We should get the elements here", elements);
                    assertEquals("Get the wrong elements size", 1, elements.size());
                    Element el = new XmlConverter().toDOMElement(elements.get(0));
                    elements.set(0, new DOMSource(el));
                    assertEquals("Get the wrong namespace URI", "http://camel.apache.org/pizza/types", el.getNamespaceURI());
                    List<SoapHeader> headers = payload.getHeaders();
                    assertNotNull("We should get the headers here", headers);
                    assertEquals("Get the wrong headers size", headers.size(), 1);
                    assertEquals("Get the wrong namespace URI", ((Element) (headers.get(0).getObject())).getNamespaceURI(), "http://camel.apache.org/pizza/types");
                    // alternatively you can also get the SOAP header via the camel header:
                    headers = exchange.getIn().getHeader(Header.HEADER_LIST, List.class);
                    assertNotNull("We should get the headers here", headers);
                    assertEquals("Get the wrong headers size", headers.size(), 1);
                    assertEquals("Get the wrong namespace URI", ((Element) (headers.get(0).getObject())).getNamespaceURI(), "http://camel.apache.org/pizza/types");
                }
            }).to(getServiceEndpointURI());
        // END SNIPPET: payload
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) DOMSource(javax.xml.transform.dom.DOMSource) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Element(org.w3c.dom.Element) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) List(java.util.List) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 18 with XmlConverter

use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.

the class CachedCxfPayloadTest method doTest.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void doTest(Object source, String payload) throws IOException {
    CxfPayload<?> originalPayload = context.getTypeConverter().convertTo(CxfPayload.class, source);
    CachedCxfPayload<?> cache = new CachedCxfPayload(originalPayload, exchange, new XmlConverter());
    assertTrue(cache.inMemory());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    cache.writeTo(bos);
    String s = context.getTypeConverter().convertTo(String.class, bos);
    assertEquals(payload, s);
    cache.reset();
    CachedCxfPayload clone = (CachedCxfPayload) cache.copy(exchange);
    bos = new ByteArrayOutputStream();
    clone.writeTo(bos);
    s = context.getTypeConverter().convertTo(String.class, bos);
    assertEquals(payload, s);
    cache.reset();
    clone.reset();
    s = context.getTypeConverter().convertTo(String.class, cache);
    assertEquals(payload, s);
    s = context.getTypeConverter().convertTo(String.class, clone);
    assertEquals(payload, s);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 19 with XmlConverter

use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.

the class SpringWebserviceComponent method addXmlConverterToConfiguration.

private void addXmlConverterToConfiguration(Map<String, Object> parameters, SpringWebserviceConfiguration configuration) {
    XmlConverter xmlConverter = new XmlConverter();
    TransformerFactory transformerFactory = resolveAndRemoveReferenceParameter(parameters, "transformerFactory", TransformerFactory.class, null);
    if (transformerFactory != null) {
        xmlConverter.setTransformerFactory(transformerFactory);
    }
    configuration.setXmlConverter(xmlConverter);
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 20 with XmlConverter

use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.

the class SpringWebserviceConsumer method invoke.

/**
     * Invoked by Spring-WS when a {@link WebServiceMessage} is received
     */
public void invoke(MessageContext messageContext) throws Exception {
    Exchange exchange = getEndpoint().createExchange(ExchangePattern.InOptionalOut);
    populateExchangeFromMessageContext(messageContext, exchange);
    // populate camel exchange with breadcrumb from transport header        
    populateExchangeWithBreadcrumbFromMessageContext(messageContext, exchange);
    // start message processing
    getProcessor().process(exchange);
    if (exchange.getException() != null) {
        throw exchange.getException();
    } else if (exchange.getPattern().isOutCapable()) {
        Message responseMessage = exchange.hasOut() ? exchange.getOut(Message.class) : exchange.getIn(Message.class);
        if (responseMessage != null) {
            Source responseBody = responseMessage.getBody(Source.class);
            WebServiceMessage response = messageContext.getResponse();
            configuration.getMessageFilter().filterConsumer(exchange, response);
            XmlConverter xmlConverter = configuration.getXmlConverter();
            xmlConverter.toResult(responseBody, response.getPayloadResult());
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) WebServiceMessage(org.springframework.ws.WebServiceMessage) SoapMessage(org.springframework.ws.soap.SoapMessage) Message(org.apache.camel.Message) MimeMessage(org.springframework.ws.mime.MimeMessage) WebServiceMessage(org.springframework.ws.WebServiceMessage) SOAPMessage(javax.xml.soap.SOAPMessage) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) Source(javax.xml.transform.Source) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Aggregations

XmlConverter (org.apache.camel.converter.jaxp.XmlConverter)29 Element (org.w3c.dom.Element)14 Exchange (org.apache.camel.Exchange)10 Document (org.w3c.dom.Document)10 Source (javax.xml.transform.Source)9 Processor (org.apache.camel.Processor)7 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 NodeList (org.w3c.dom.NodeList)4 StringReader (java.io.StringReader)3 List (java.util.List)3 TransformerException (javax.xml.transform.TransformerException)3 DOMSource (javax.xml.transform.dom.DOMSource)3 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 JAXBContext (javax.xml.bind.JAXBContext)2