use of javax.xml.transform.Source in project camel by apache.
the class CxfPayLoadMessageXmlBindingRouterTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("cxf:bean:routerEndpoint?dataFormat=PAYLOAD").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("cxf:bean:serviceEndpoint?dataFormat=PAYLOAD");
}
};
}
use of javax.xml.transform.Source 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.Source 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.Source 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());
}
use of javax.xml.transform.Source in project camel by apache.
the class XsltBuilderTest method testXsltTemplates.
public void testXsltTemplates() throws Exception {
File file = new File("src/test/resources/org/apache/camel/builder/xml/example.xsl");
Source source = new SAXSource(new InputSource(new FileInputStream(file)));
XmlConverter converter = new XmlConverter();
Templates styleSheet = converter.getTransformerFactory().newTemplates(source);
XsltBuilder builder = XsltBuilder.xslt(styleSheet);
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("<hello>world!</hello>");
builder.process(exchange);
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye>world!</goodbye>", exchange.getOut().getBody());
}
Aggregations