use of org.apache.cxf.binding.soap.SoapHeader in project camel by apache.
the class CxfMessageHeadersRelayTest method buildOutOfBandHeaderList.
protected static List<Header> buildOutOfBandHeaderList(boolean invalid) throws JAXBException {
OutofBandHeader ob = new OutofBandHeader();
ob.setName("testOobHeader");
ob.setValue("testOobHeaderValue");
ob.setHdrAttribute(invalid ? "dontProcess" : "testHdrAttribute");
SoapHeader hdr = new SoapHeader(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_REQUEST_ELEM), ob, new JAXBDataBinding(ob.getClass()));
hdr.setMustUnderstand(invalid);
List<Header> headers = new ArrayList<Header>();
headers.add(hdr);
return headers;
}
use of org.apache.cxf.binding.soap.SoapHeader in project camel by apache.
the class CxfMtomProducerPayloadModeTest method testProducer.
@SuppressWarnings("unchecked")
@Test
public void testProducer() throws Exception {
if (MtomTestHelper.isAwtHeadless(logger, null)) {
return;
}
// START SNIPPET: producer
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.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
CxfPayload<SoapHeader> out = exchange.getOut().getBody(CxfPayload.class);
Assert.assertEquals(1, out.getBody().size());
Map<String, String> ns = new HashMap<String, String>();
ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
ns.put("xop", MtomTestHelper.XOP_NS);
XPathUtils xu = new XPathUtils(ns);
Element oute = new XmlConverter().toDOMElement(out.getBody().get(0));
Element ele = (Element) xu.getValue("//ns:DetailResponse/ns:photo/xop:Include", oute, XPathConstants.NODE);
// skip "cid:"
String photoId = ele.getAttribute("href").substring(4);
ele = (Element) xu.getValue("//ns:DetailResponse/ns:image/xop:Include", oute, XPathConstants.NODE);
// skip "cid:"
String imageId = ele.getAttribute("href").substring(4);
DataHandler dr = exchange.getOut().getAttachment(decodingReference(photoId));
Assert.assertEquals("application/octet-stream", dr.getContentType());
MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
dr = exchange.getOut().getAttachment(decodingReference(imageId));
Assert.assertEquals("image/jpeg", dr.getContentType());
BufferedImage image = ImageIO.read(dr.getInputStream());
Assert.assertEquals(560, image.getWidth());
Assert.assertEquals(300, image.getHeight());
// END SNIPPET: producer
}
Aggregations