use of org.apache.cxf.outofband.header.OutofBandHeader in project camel by apache.
the class HeaderTesterImpl method validateOutOfBandHander.
protected boolean validateOutOfBandHander() {
MessageContext ctx = context == null ? null : context.getMessageContext();
if (!relayHeaders) {
if (ctx != null && !ctx.containsKey(Header.HEADER_LIST) || (ctx.containsKey(Header.HEADER_LIST) && ((List<?>) ctx.get(Header.HEADER_LIST)).size() == 0)) {
return true;
}
return false;
}
boolean success = false;
if (ctx != null && ctx.containsKey(Header.HEADER_LIST)) {
List<?> oobHdr = (List<?>) ctx.get(Header.HEADER_LIST);
Iterator<?> iter = oobHdr.iterator();
while (iter.hasNext()) {
Object hdr = iter.next();
if (hdr instanceof Header && ((Header) hdr).getObject() instanceof Node) {
Header hdr1 = (Header) hdr;
try {
JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
OutofBandHeader ob = (OutofBandHeader) job.getValue();
if ("testOobHeader".equals(ob.getName()) && "testOobHeaderValue".equals(ob.getValue())) {
if ("testHdrAttribute".equals(ob.getHdrAttribute())) {
success = true;
//mark it processed
iter.remove();
} else if ("dontProcess".equals(ob.getHdrAttribute())) {
//we won't remove it so we won't let the runtime know
//it's processed. It SHOULD throw an exception
//saying the mustunderstand wasn't processed
success = true;
}
} else {
throw new RuntimeException("test failed");
}
} catch (JAXBException ex) {
ex.printStackTrace();
}
}
}
} else {
throw new RuntimeException("MessageContext is null or doesnot contain OOBHeaders");
}
return success;
}
Aggregations