use of org.w3c.dom.Document in project camel by apache.
the class CxfJavaOnlyPayloadModeTest method testCxfJavaOnly.
@Test
public void testCxfJavaOnly() throws Exception {
String s = "<GetPerson xmlns=\"http://camel.apache.org/wsdl-first/types\"><personId>123</personId></GetPerson>";
Document xml = context.getTypeConverter().convertTo(Document.class, s);
Object output = template.requestBody(url, xml);
assertNotNull(output);
// using CxfPayload in payload mode
CxfPayload<?> payload = (CxfPayload<?>) output;
// convert the payload body to string
String reply = context.getTypeConverter().convertTo(String.class, payload.getBody().get(0));
assertNotNull(reply);
assertTrue(reply.contains("<personId>123</personId"));
assertTrue(reply.contains("<ssn>456</ssn"));
assertTrue(reply.contains("<name>Donald Duck</name"));
}
use of org.w3c.dom.Document in project camel by apache.
the class XPathTransformTest method testXPathTransform.
public void testXPathTransform() throws Exception {
Document doc = context.getTypeConverter().convertTo(Document.class, "<root><firstname>Apache</firstname><lastname>Camel</lastname></root>");
NodeList list = XPathBuilder.xpath("/root/firstname", NodeList.class).evaluate(context, doc, NodeList.class);
assertNotNull(list);
list.item(0).setTextContent("Servicemix");
String out = context.getTypeConverter().convertTo(String.class, doc);
assertEquals("<root><firstname>Servicemix</firstname><lastname>Camel</lastname></root>", out);
}
use of org.w3c.dom.Document in project camel by apache.
the class XPathTransformTest method testXPathNamespaceLoggingEnabledJavaDSL.
public void testXPathNamespaceLoggingEnabledJavaDSL() throws Exception {
Logger l = createNiceMock(Logger.class);
expect(l.isInfoEnabled()).andReturn(true).anyTimes();
l.info(contains("Namespaces discovered in message"), anyObject(Object.class));
expectLastCall().times(1);
replay(l);
String body = "<aRoot xmlns:nsa=\"http://namespacec.net\"><nsa:a xmlns:nsa=\"http://namespacea.net\">Hello|there|Camel</nsa:a>" + "<nsb:a xmlns:nsb=\"http://namespaceb.net\">Hello|there|Camel</nsb:a><nsb:a xmlns:nsb=\"http://namespaceb.net\">Hello|there|Camel</nsb:a>" + "<a xmlns=\"http://defaultNamespace.net\">Hello|there|Camel</a><a>Hello|there|Camel</a></aRoot>";
Document doc = context.getTypeConverter().convertTo(Document.class, body);
Field logField = XPathBuilder.class.getDeclaredField("LOG");
logField.setAccessible(true);
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(logField, logField.getModifiers() & ~Modifier.FINAL);
logField.set(null, l);
NodeList list = XPathBuilder.xpath("//*", NodeList.class).logNamespaces().evaluate(context, doc, NodeList.class);
assertNotNull(list);
verify(l);
}
use of org.w3c.dom.Document in project camel by apache.
the class XPathTest method testXPathNodeListSimpleTestText.
public void testXPathNodeListSimpleTestText() throws Exception {
String xml = "<foo><person>Claus</person></foo>";
Document doc = context.getTypeConverter().convertTo(Document.class, xml);
Object result = xpath("/foo/person/text()").nodeSetResult().evaluate(createExchange(doc));
assertNotNull(result);
String s = context.getTypeConverter().convertTo(String.class, result);
assertEquals("Claus", s);
}
use of org.w3c.dom.Document in project camel by apache.
the class XPathTest method testXPathNodeListTest.
public void testXPathNodeListTest() throws Exception {
String xml = "<foo><person id=\"1\">Claus<country>SE</country></person>" + "<person id=\"2\">Jonathan<country>CA</country></person></foo>";
Document doc = context.getTypeConverter().convertTo(Document.class, xml);
Object result = xpath("/foo/person").nodeSetResult().evaluate(createExchange(doc));
assertNotNull(result);
String s = context.getTypeConverter().convertTo(String.class, result);
assertEquals(ObjectHelper.between(xml, "<foo>", "</foo>"), s);
}
Aggregations