Search in sources :

Example 66 with Header

use of org.apache.cxf.headers.Header in project cxf by apache.

the class MAPCodecTest method setUpHeaderDecode.

private <T> void setUpHeaderDecode(List<Header> headers, String uri, String name, Class<?> clz, int index, Unmarshaller unmarshaller) throws Exception {
    Element headerElement = control.createMock(Element.class);
    headers.add(new Header(new QName(uri, name), headerElement));
    headerElement.getNamespaceURI();
    EasyMock.expectLastCall().andReturn(uri);
    headerElement.getLocalName();
    EasyMock.expectLastCall().andReturn(name);
    Object v = expectedValues[index];
    @SuppressWarnings("unchecked") JAXBElement<?> jaxbElement = new JAXBElement<Object>(new QName(uri, name), (Class<Object>) clz, clz.cast(v));
    unmarshaller.unmarshal(headerElement, clz);
    EasyMock.expectLastCall().andReturn(jaxbElement);
}
Also used : Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) JAXBElement(javax.xml.bind.JAXBElement)

Example 67 with Header

use of org.apache.cxf.headers.Header in project cxf by apache.

the class HeaderVerifier method addPartialResponseHeader.

private void addPartialResponseHeader(SoapMessage message) {
    try {
        // add piggybacked wsa:From header to partial response
        List<Header> header = message.getHeaders();
        Document doc = DOMUtils.getEmptyDocument();
        SoapVersion ver = message.getVersion();
        Element hdr = doc.createElementNS(ver.getHeader().getNamespaceURI(), ver.getHeader().getLocalPart());
        hdr.setPrefix(ver.getHeader().getPrefix());
        marshallFrom("urn:piggyback_responder", hdr, getMarshaller());
        Element elem = DOMUtils.getFirstElement(hdr);
        while (elem != null) {
            Header holder = new Header(new QName(elem.getNamespaceURI(), elem.getLocalName()), elem, null);
            header.add(holder);
            elem = DOMUtils.getNextElement(elem);
        }
    } catch (Exception e) {
        verificationCache.put("SOAP header addition failed: " + e);
        e.printStackTrace();
    }
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) SOAPException(javax.xml.soap.SOAPException) JAXBException(javax.xml.bind.JAXBException)

Example 68 with Header

use of org.apache.cxf.headers.Header in project tesb-rt-se by Talend.

the class FlowIdSoapCodec method readFlowId.

/**
 * Read flow id.
 *
 * @param message the message
 * @return flow id from the message
 */
public static String readFlowId(Message message) {
    if (!(message instanceof SoapMessage)) {
        return null;
    }
    String flowId = null;
    Header hdFlowId = ((SoapMessage) message).getHeader(FLOW_ID_QNAME);
    if (hdFlowId != null) {
        if (hdFlowId.getObject() instanceof String) {
            flowId = (String) hdFlowId.getObject();
        } else if (hdFlowId.getObject() instanceof Node) {
            Node headerNode = (Node) hdFlowId.getObject();
            flowId = headerNode.getTextContent();
        } else {
            LOG.warning("Found FlowId soap header but value is not a String or a Node! Value: " + hdFlowId.getObject().toString());
        }
    }
    return flowId;
}
Also used : Header(org.apache.cxf.headers.Header) Node(org.w3c.dom.Node) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 69 with Header

use of org.apache.cxf.headers.Header in project tesb-rt-se by Talend.

the class FlowIdSoapCodec method writeFlowId.

/**
 * Write flow id to message.
 *
 * @param message the message
 * @param flowId the flow id
 */
public static void writeFlowId(Message message, String flowId) {
    if (!(message instanceof SoapMessage)) {
        return;
    }
    SoapMessage soapMessage = (SoapMessage) message;
    Header hdFlowId = soapMessage.getHeader(FLOW_ID_QNAME);
    if (hdFlowId != null) {
        LOG.warning("FlowId already existing in soap header, need not to write FlowId header.");
        return;
    }
    try {
        soapMessage.getHeaders().add(new Header(FLOW_ID_QNAME, flowId, new JAXBDataBinding(String.class)));
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Stored flowId '" + flowId + "' in soap header: " + FLOW_ID_QNAME);
        }
    } catch (JAXBException e) {
        LOG.log(Level.SEVERE, "Couldn't create flowId header.", e);
    }
}
Also used : Header(org.apache.cxf.headers.Header) JAXBException(javax.xml.bind.JAXBException) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 70 with Header

use of org.apache.cxf.headers.Header in project tesb-rt-se by Talend.

the class RuntimeESBEndpointRegistry method listSoapHeaders.

@SuppressWarnings("unchecked")
private List<Header> listSoapHeaders(Object soapHeadersObject) throws TransformerFactoryConfigurationError {
    if (null != soapHeadersObject) {
        if (soapHeadersObject instanceof org.dom4j.Document) {
            List<Header> soapHeaders = new ArrayList<Header>();
            try {
                DOMResult result = new DOMResult();
                TransformerFactory.newInstance().newTransformer().transform(new org.dom4j.io.DocumentSource((org.dom4j.Document) soapHeadersObject), result);
                for (Node node = ((Document) result.getNode()).getDocumentElement().getFirstChild(); node != null; node = node.getNextSibling()) {
                    if (Node.ELEMENT_NODE == node.getNodeType()) {
                        soapHeaders.add(new Header(new QName(node.getNamespaceURI(), node.getLocalName()), node));
                    }
                }
            } catch (Exception e) {
                LOG.log(Level.SEVERE, "Uncaught exception during SOAP headers transformation: ", e);
            }
        } else if (soapHeadersObject instanceof List) {
            return (List<Header>) soapHeadersObject;
        }
    }
    return null;
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.w3c.dom.Document)

Aggregations

Header (org.apache.cxf.headers.Header)78 QName (javax.xml.namespace.QName)29 Element (org.w3c.dom.Element)27 ArrayList (java.util.ArrayList)25 JAXBException (javax.xml.bind.JAXBException)24 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)18 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)17 Node (org.w3c.dom.Node)16 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)15 JAXBElement (javax.xml.bind.JAXBElement)14 List (java.util.List)13 OutofBandHeader (org.apache.cxf.outofband.header.OutofBandHeader)13 MessageContext (javax.xml.ws.handler.MessageContext)9 Test (org.junit.Test)9 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)8 SoapVersion (org.apache.cxf.binding.soap.SoapVersion)7 Message (org.apache.cxf.message.Message)7 HashMap (java.util.HashMap)6 Fault (org.apache.cxf.interceptor.Fault)6 Exchange (org.apache.cxf.message.Exchange)6