use of javax.xml.transform.dom.DOMSource in project camel by apache.
the class CxfPayloadConverterTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
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 = documentBuilder.parse(file);
document.getDocumentElement().normalize();
List<Source> body = new ArrayList<Source>();
body.add(new DOMSource(document.getDocumentElement()));
List<Source> staxbody = new ArrayList<Source>();
staxbody.add(new StAXSource(StaxUtils.createXMLStreamReader(new FileInputStream(file), "utf-8")));
payload = new CxfPayload<String[]>(new ArrayList<String[]>(), body, null);
emptyPayload = new CxfPayload<String[]>(new ArrayList<String[]>(), new ArrayList<Source>(), null);
staxpayload = new CxfPayload<String[]>(new ArrayList<String[]>(), staxbody, null);
inputStream = new FileInputStream(file);
}
use of javax.xml.transform.dom.DOMSource 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 javax.xml.transform.dom.DOMSource in project camel by apache.
the class CachedCxfPayloadTest method testCachedCxfPayloadDOMSource.
@Test
public void testCachedCxfPayloadDOMSource() throws TypeConversionException, NoTypeConversionAvailableException, IOException {
DOMSource source = context.getTypeConverter().mandatoryConvertTo(DOMSource.class, PAYLOAD);
doTest(source, PAYLOAD);
}
use of javax.xml.transform.dom.DOMSource in project camel by apache.
the class CxfMessageHeadersRelayTest method testInoutHeaderCXFClientNoServiceClassNoRelay.
@Test
public void testInoutHeaderCXFClientNoServiceClassNoRelay() throws Exception {
// TODO: Fix this test later
QName qname = QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SOAPHeaderInfo");
String uri = "cxf:bean:routerNoRelayNoServiceClassEndpoint?headerFilterStrategy=#dropAllMessageHeadersStrategy";
String requestHeader = "<ns2:SOAPHeaderInfo xmlns:ns2=\"http://apache.org/camel/" + "component/cxf/soap/headers\"><originator>CxfSoapHeaderRoutePropagationTest.testInOutHeader Requestor" + "</originator><message>Invoking CxfSoapHeaderRoutePropagationTest.testInOutHeader() Request" + "</message></ns2:SOAPHeaderInfo>";
String requestBody = "<ns2:inoutHeader xmlns:ns2=\"http://apache.org/camel/component/cxf/soap/headers\">" + "<requestType>CXF user</requestType></ns2:inoutHeader>";
List<Source> elements = new ArrayList<Source>();
elements.add(new DOMSource(StaxUtils.read(new StringReader(requestBody)).getDocumentElement()));
final List<SoapHeader> headers = new ArrayList<SoapHeader>();
headers.add(new SoapHeader(qname, StaxUtils.read(new StringReader(requestHeader)).getDocumentElement()));
final CxfPayload<SoapHeader> cxfPayload = new CxfPayload<SoapHeader>(headers, elements, null);
Exchange exchange = template.request(uri, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(cxfPayload);
exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "inoutHeader");
exchange.getIn().setHeader(Header.HEADER_LIST, headers);
}
});
CxfPayload<?> out = exchange.getOut().getBody(CxfPayload.class);
assertEquals(1, out.getBodySources().size());
assertTrue(out.getBodySources().get(0) instanceof DOMSource);
assertEquals(0, out.getHeaders().size());
String responseExp = "<ns2:inoutHeaderResponse xmlns:ns2=\"http://apache.org/camel/" + "component/cxf/soap/headers\"><responseType>pass</responseType>" + "</ns2:inoutHeaderResponse>";
String response = StaxUtils.toString(out.getBody().get(0));
//REVISIT use a more reliable comparison to tolerate some namespaces being added to the root element
assertTrue(response, response.startsWith(responseExp.substring(0, 87)) && response.endsWith(responseExp.substring(88, responseExp.length())));
}
use of javax.xml.transform.dom.DOMSource in project camel by apache.
the class CxfMtomDisabledProducerPayloadModeTest method testProducer.
@Override
public void testProducer() throws Exception {
if (MtomTestHelper.isAwtHeadless(logger, null)) {
return;
}
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.MTOM_DISABLED_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 - verify response attachments
CxfPayload<?> out = exchange.getOut().getBody(CxfPayload.class);
Assert.assertEquals(1, out.getBody().size());
DataHandler dr = exchange.getOut().getAttachment(MtomTestHelper.RESP_PHOTO_CID);
Assert.assertEquals("application/octet-stream", dr.getContentType());
MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
dr = exchange.getOut().getAttachment(MtomTestHelper.RESP_IMAGE_CID);
Assert.assertEquals("image/jpeg", dr.getContentType());
BufferedImage image = ImageIO.read(dr.getInputStream());
Assert.assertEquals(560, image.getWidth());
Assert.assertEquals(300, image.getHeight());
}
Aggregations