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");
}
};
}
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
}
};
}
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);
}
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);
}
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());
}
}
}
Aggregations