Search in sources :

Example 6 with OutofBandHeader

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;
}
Also used : Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) List(java.util.List) MessageContext(javax.xml.ws.handler.MessageContext)

Aggregations

Header (org.apache.cxf.headers.Header)6 OutofBandHeader (org.apache.cxf.outofband.header.OutofBandHeader)6 JAXBElement (javax.xml.bind.JAXBElement)5 JAXBException (javax.xml.bind.JAXBException)5 Node (org.w3c.dom.Node)4 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)3 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 MessageContext (javax.xml.ws.handler.MessageContext)2 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)2 List (java.util.List)1