use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.
the class ExceptionHandlerStreamCacheTest method doTestXmlPayload.
private void doTestXmlPayload(String xml) throws InterruptedException, TransformerException {
successEndpoint.expectedMessageCount(0);
exceptionEndpoint.expectedMessageCount(1);
template.sendBody("direct:start", new StreamSource(new ByteArrayInputStream(xml.getBytes())));
successEndpoint.assertIsSatisfied();
exceptionEndpoint.assertIsSatisfied();
StreamSource body = (StreamSource) exceptionEndpoint.getExchanges().get(0).getIn().getBody();
assertEquals("Ensure message re-readability in the exception handler", xml, new XmlConverter().toString(body, null));
}
use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.
the class CxfMtomProducerPayloadModeTest method testProducer.
@SuppressWarnings("unchecked")
@Test
public void testProducer() throws Exception {
if (MtomTestHelper.isAwtHeadless(logger, null)) {
return;
}
// START SNIPPET: producer
Exchange exchange = context.createProducerTemplate().send("direct:testEndpoint", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
List<Source> elements = new ArrayList<Source>();
elements.add(new DOMSource(StaxUtils.read(new StringReader(MtomTestHelper.REQ_MESSAGE)).getDocumentElement()));
CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), elements, null);
exchange.getIn().setBody(body);
exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));
exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
}
});
// process response
CxfPayload<SoapHeader> out = exchange.getOut().getBody(CxfPayload.class);
Assert.assertEquals(1, out.getBody().size());
Map<String, String> ns = new HashMap<String, String>();
ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
ns.put("xop", MtomTestHelper.XOP_NS);
XPathUtils xu = new XPathUtils(ns);
Element oute = new XmlConverter().toDOMElement(out.getBody().get(0));
Element ele = (Element) xu.getValue("//ns:DetailResponse/ns:photo/xop:Include", oute, XPathConstants.NODE);
// skip "cid:"
String photoId = ele.getAttribute("href").substring(4);
ele = (Element) xu.getValue("//ns:DetailResponse/ns:image/xop:Include", oute, XPathConstants.NODE);
// skip "cid:"
String imageId = ele.getAttribute("href").substring(4);
DataHandler dr = exchange.getOut().getAttachment(decodingReference(photoId));
Assert.assertEquals("application/octet-stream", dr.getContentType());
MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
dr = exchange.getOut().getAttachment(decodingReference(imageId));
Assert.assertEquals("image/jpeg", dr.getContentType());
BufferedImage image = ImageIO.read(dr.getInputStream());
Assert.assertEquals(560, image.getWidth());
Assert.assertEquals(300, image.getHeight());
// END SNIPPET: producer
}
use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.
the class DumpModelAsXmlSplitNestedChoiceEndRouteTest method testDumpModelAsXml.
public void testDumpModelAsXml() throws Exception {
String xml = ModelHelper.dumpModelAsXml(context, context.getRouteDefinition("myRoute"));
assertNotNull(xml);
log.info(xml);
Document doc = new XmlConverter().toDOMDocument(xml);
NodeList nodes = doc.getElementsByTagName("split");
assertEquals(1, nodes.getLength());
Element node = (Element) nodes.item(0);
// there is an empty text document as we pretty print the xml, so need to do 2 x next sibling
Element last = (Element) node.getNextSibling().getNextSibling();
assertEquals("mock:last", last.getAttribute("uri"));
}
use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.
the class CxfPayLoadMessageRouterTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// START SNIPPET: payload
from(routerEndpointURI).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(serviceEndpointURI);
// END SNIPPET: payload
}
};
}
use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.
the class ModelHelper method newXmlConverter.
/**
* Creates a new {@link XmlConverter}
*
* @param context CamelContext if provided
* @return a new XmlConverter instance
*/
private static XmlConverter newXmlConverter(CamelContext context) {
XmlConverter xmlConverter;
if (context != null) {
TypeConverterRegistry registry = context.getTypeConverterRegistry();
xmlConverter = registry.getInjector().newInstance(XmlConverter.class);
} else {
xmlConverter = new XmlConverter();
}
return xmlConverter;
}
Aggregations