Search in sources :

Example 1 with SoapHeaderElement

use of org.springframework.ws.soap.SoapHeaderElement in project camel by apache.

the class SpringWebserviceConsumer method extractSourceFromSoapHeader.

/**
     * Extracts the SOAP headers and set them as headers in the Exchange. Also sets
     * it as a header with the key SpringWebserviceConstants.SPRING_WS_SOAP_HEADER
     * and a value of type Source.
     *
     * @param headers the Exchange Headers
     * @param request the WebService Request
     */
private void extractSourceFromSoapHeader(Map<String, Object> headers, WebServiceMessage request) {
    if (request instanceof SoapMessage) {
        SoapMessage soapMessage = (SoapMessage) request;
        SoapHeader soapHeader = soapMessage.getSoapHeader();
        if (soapHeader != null) {
            //Set the raw soap header as a header in the exchange.
            headers.put(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER, soapHeader.getSource());
            //Set header values for the soap header attributes
            Iterator<QName> attIter = soapHeader.getAllAttributes();
            while (attIter.hasNext()) {
                QName name = attIter.next();
                headers.put(name.getLocalPart(), soapHeader.getAttributeValue(name));
            }
            //Set header values for the soap header elements
            Iterator<SoapHeaderElement> elementIter = soapHeader.examineAllHeaderElements();
            while (elementIter.hasNext()) {
                SoapHeaderElement element = elementIter.next();
                QName name = element.getName();
                headers.put(name.getLocalPart(), element);
            }
        }
    }
}
Also used : SoapHeaderElement(org.springframework.ws.soap.SoapHeaderElement) QName(javax.xml.namespace.QName) SoapHeader(org.springframework.ws.soap.SoapHeader) SoapMessage(org.springframework.ws.soap.SoapMessage) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage)

Example 2 with SoapHeaderElement

use of org.springframework.ws.soap.SoapHeaderElement in project camel by apache.

the class SpringWebserviceProducer method populateMessageHeaderFromResponse.

/**
     * Populates message headers from soapHeader response
     * 
     * @param message
     *            Message
     * @param soapHeader
     *            SoapHeader
     */
private void populateMessageHeaderFromResponse(Message message, SoapHeader soapHeader) {
    message.setHeader(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER, soapHeader.getSource());
    // Set header values for the soap header attributes
    Iterator<QName> attIter = soapHeader.getAllAttributes();
    while (attIter.hasNext()) {
        QName name = attIter.next();
        message.getHeaders().put(name.getLocalPart(), soapHeader.getAttributeValue(name));
    }
    // Set header values for the soap header elements
    Iterator<SoapHeaderElement> elementIter = soapHeader.examineAllHeaderElements();
    while (elementIter.hasNext()) {
        SoapHeaderElement element = elementIter.next();
        QName name = element.getName();
        message.getHeaders().put(name.getLocalPart(), element);
    }
}
Also used : SoapHeaderElement(org.springframework.ws.soap.SoapHeaderElement) QName(javax.xml.namespace.QName)

Example 3 with SoapHeaderElement

use of org.springframework.ws.soap.SoapHeaderElement in project webservices-axiom by apache.

the class AxiomSoapMessageTest method testSetDocument.

/**
     * Tests that {@link AxiomSoapMessage#setDocument(Document)} works correctly. There have been
     * issues with that method because Spring-WS instantiates {@link SOAPFactory} implementations
     * directly instead of using {@link OMAbstractFactory}.
     * 
     * @throws Exception
     */
public void testSetDocument() throws Exception {
    AxiomSoapMessageFactory mf = new AxiomSoapMessageFactory();
    mf.afterPropertiesSet();
    AxiomSoapMessage message = mf.createWebServiceMessage();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document document = dbf.newDocumentBuilder().parse(AxiomSoapMessageTest.class.getResource("soap-message.xml").toString());
    message.setDocument(document);
    Iterator<SoapHeaderElement> it = message.getEnvelope().getHeader().examineAllHeaderElements();
    assertTrue(it.hasNext());
    SoapHeaderElement headerElement = it.next();
    assertEquals(new QName("urn:test", "myHeader"), headerElement.getName());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) SoapHeaderElement(org.springframework.ws.soap.SoapHeaderElement) AxiomSoapMessageFactory(org.springframework.ws.soap.axiom.AxiomSoapMessageFactory) QName(javax.xml.namespace.QName) Document(org.w3c.dom.Document) AxiomSoapMessage(org.springframework.ws.soap.axiom.AxiomSoapMessage)

Aggregations

QName (javax.xml.namespace.QName)3 SoapHeaderElement (org.springframework.ws.soap.SoapHeaderElement)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 SoapHeader (org.springframework.ws.soap.SoapHeader)1 SoapMessage (org.springframework.ws.soap.SoapMessage)1 AxiomSoapMessage (org.springframework.ws.soap.axiom.AxiomSoapMessage)1 AxiomSoapMessageFactory (org.springframework.ws.soap.axiom.AxiomSoapMessageFactory)1 SaajSoapMessage (org.springframework.ws.soap.saaj.SaajSoapMessage)1 Document (org.w3c.dom.Document)1