use of org.w3c.dom.Document in project camel by apache.
the class RawMessageWSDLGetOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
Document doc = (Document) message.get(RawMessageWSDLGetInterceptor.DOCUMENT_HOLDER);
if (doc == null) {
return;
}
message.remove(RawMessageWSDLGetInterceptor.DOCUMENT_HOLDER);
OutputStream out = message.getContent(OutputStream.class);
String enc = null;
try {
enc = doc.getXmlEncoding();
} catch (Exception ex) {
//ignore - not dom level 3
}
if (enc == null) {
enc = "utf-8";
}
XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out, enc);
try {
StaxUtils.writeNode(doc, writer, true);
writer.flush();
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
use of org.w3c.dom.Document in project camel by apache.
the class CxfJavaOnlyCamelContextAwareTest method testCxfEndpointHasCamelContext.
@Test
public void testCxfEndpointHasCamelContext() 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);
log.info("Endpoints: {}", context.getEndpoints());
Object output = template.requestBody("personService", 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"));
assertTrue(context.getEndpoint("personService") instanceof CamelContextAware);
assertNotNull("CamelContext should be set on CxfEndpoint", context.getEndpoint("personService").getCamelContext());
}
use of org.w3c.dom.Document in project camel by apache.
the class ConverterTest method testFallbackConverter.
@Test
public void testFallbackConverter() throws Exception {
CamelContext context = new DefaultCamelContext();
Exchange exchange = new DefaultExchange(context);
MessageContentsList list = new MessageContentsList();
NodeListWrapper nl = new NodeListWrapper(new ArrayList<Element>());
list.add(nl);
exchange.getIn().setBody(list);
Node node = exchange.getIn().getBody(Node.class);
assertNull(node);
File file = new File("src/test/resources/org/apache/camel/component/cxf/converter/test.xml");
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(file);
document.getDocumentElement().normalize();
List<Element> elements = new ArrayList<Element>();
elements.add(document.getDocumentElement());
nl = new NodeListWrapper(elements);
list.clear();
list.add(nl);
exchange.getIn().setBody(list);
node = exchange.getIn().getBody(Node.class);
assertNotNull(node);
}
use of org.w3c.dom.Document in project camel by apache.
the class DefaultCxfBindingTest method testPayloadBodyNamespace.
@Test
public void testPayloadBodyNamespace() throws Exception {
MessageImpl message = new MessageImpl();
Map<String, String> nsMap = new HashMap<String, String>();
Document document = getDocument(SOAP_MESSAGE_1);
message.setContent(Node.class, document);
DefaultCxfBinding.getPayloadBodyElements(message, nsMap);
assertEquals(2, nsMap.size());
assertEquals("http://www.mycompany.com/test/", nsMap.get("xmlns"));
Element element = document.createElement("tag");
DefaultCxfBinding.addNamespace(element, nsMap);
assertEquals("http://www.mycompany.com/test/", element.getAttribute("xmlns"));
assertEquals("http://www.mycompany.com/test/1/", element.getAttribute("xmlns:ns1"));
}
use of org.w3c.dom.Document in project camel by apache.
the class DefaultCxfBindingTest method getDocument.
private Document getDocument(String soapMessage) throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(IOConverter.toInputStream(soapMessage, null));
document.getDocumentElement().normalize();
return document;
}
Aggregations