use of org.w3c.dom.Document in project camel by apache.
the class ManagedCamelContext method dumpRestsAsXml.
@Override
public String dumpRestsAsXml(boolean resolvePlaceholders) throws Exception {
List<RestDefinition> rests = context.getRestDefinitions();
if (rests.isEmpty()) {
return null;
}
// use a routes definition to dump the rests
RestsDefinition def = new RestsDefinition();
def.setRests(rests);
String xml = ModelHelper.dumpModelAsXml(context, def);
// if resolving placeholders we parse the xml, and resolve the property placeholders during parsing
if (resolvePlaceholders) {
final AtomicBoolean changed = new AtomicBoolean();
InputStream is = new ByteArrayInputStream(xml.getBytes());
Document dom = XmlLineNumberParser.parseXml(is, new XmlLineNumberParser.XmlTextTransformer() {
@Override
public String transform(String text) {
try {
String after = getContext().resolvePropertyPlaceholders(text);
if (!changed.get()) {
changed.set(!text.equals(after));
}
return after;
} catch (Exception e) {
// ignore
return text;
}
}
});
// okay there were some property placeholder replaced so re-create the model
if (changed.get()) {
xml = context.getTypeConverter().mandatoryConvertTo(String.class, dom);
RestsDefinition copy = ModelHelper.createModelFromXml(context, xml, RestsDefinition.class);
xml = ModelHelper.dumpModelAsXml(context, copy);
}
}
return xml;
}
use of org.w3c.dom.Document in project camel by apache.
the class BodyAndHeaderConvertTest method testConversionOfBody.
public void testConversionOfBody() throws Exception {
Document document = exchange.getIn().getBody(Document.class);
assertNotNull(document);
Element element = document.getDocumentElement();
assertEquals("Root element name", "hello", element.getLocalName());
}
use of org.w3c.dom.Document in project camel by apache.
the class BeanProxyTest method testBeanProxyDocumentReturnDocument.
public void testBeanProxyDocumentReturnDocument() throws Exception {
// START SNIPPET: e3
Endpoint endpoint = context.getEndpoint("direct:start");
OrderService service = ProxyHelper.createProxy(endpoint, OrderService.class);
Document doc = context.getTypeConverter().convertTo(Document.class, "<order type=\"book\">Camel in action</order>");
Document reply = service.submitOrderDocumentReturnDocument(doc);
assertNotNull(reply);
String s = context.getTypeConverter().convertTo(String.class, reply);
assertEquals("<order id=\"123\">OK</order>", s);
// END SNIPPET: e3
}
use of org.w3c.dom.Document in project camel by apache.
the class BeanProxyTest method testBeanProxyStringReturnDocument.
public void testBeanProxyStringReturnDocument() throws Exception {
Endpoint endpoint = context.getEndpoint("direct:start");
OrderService service = ProxyHelper.createProxy(endpoint, OrderService.class);
Document reply = service.submitOrderStringReturnDocument("<order type=\"book\">Camel in action</order>");
assertNotNull(reply);
String s = context.getTypeConverter().convertTo(String.class, reply);
assertEquals("<order id=\"123\">OK</order>", s);
}
use of org.w3c.dom.Document in project camel by apache.
the class BeanProxyTest method testBeanProxyDocumentReturnString.
public void testBeanProxyDocumentReturnString() throws Exception {
Endpoint endpoint = context.getEndpoint("direct:start");
OrderService service = ProxyHelper.createProxy(endpoint, OrderService.class);
Document doc = context.getTypeConverter().convertTo(Document.class, "<order type=\"book\">Camel in action</order>");
String reply = service.submitOrderDocumentReturnString(doc);
assertEquals("<order id=\"123\">OK</order>", reply);
}
Aggregations