Search in sources :

Example 1 with SoapHeader

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

the class BasicMessageFilter method doProcessSoapHeader.

/**
     * The SOAP header is populated from exchange.getOut().getHeaders() if this
     * class is used by the consumer or exchange.getIn().getHeaders() if this
     * class is used by the producer. If .getHeaders() contains under a certain
     * key a value with the QName object, it is directly added as a new header
     * element. If it contains only a String value, it is transformed into a
     * header attribute. Following headers are excluded:
     */
protected void doProcessSoapHeader(Message inOrOut, SoapMessage soapMessage) {
    SoapHeader soapHeader = soapMessage.getSoapHeader();
    Map<String, Object> headers = inOrOut.getHeaders();
    HashSet<String> headerKeySet = new HashSet<String>(headers.keySet());
    headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_SOAP_ACTION);
    headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ENDPOINT_URI);
    headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ADDRESSING_ACTION);
    headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ADDRESSING_PRODUCER_FAULT_TO);
    headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ADDRESSING_PRODUCER_REPLY_TO);
    headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ADDRESSING_CONSUMER_FAULT_ACTION);
    headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_ADDRESSING_CONSUMER_OUTPUT_ACTION);
    // This gets repeated again in the below 'for loop' and gets added as attribute to soapenv:header. 
    // This would have already been processed in SpringWebserviceProducer/Consumer instance.
    headerKeySet.remove(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER);
    // Replaced local constant 'BreadcrumbId' with the actual constant key in header 'breadcrumbId'
    // from org.apache.camel.Exchange.BREADCRUMB_ID. Because of this case mismatch, this key never
    // gets removed from header rather gets added to soapHeader all the time.
    headerKeySet.remove(Exchange.BREADCRUMB_ID);
    for (String name : headerKeySet) {
        Object value = headers.get(name);
        if (value instanceof QName) {
            soapHeader.addHeaderElement((QName) value);
        } else {
            if (value instanceof String) {
                soapHeader.addAttribute(new QName(name), value + "");
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) SoapHeader(org.springframework.ws.soap.SoapHeader) HashSet(java.util.HashSet)

Example 2 with SoapHeader

use of org.springframework.ws.soap.SoapHeader in project spring-integration by spring-projects.

the class DefaultSoapHeaderMapper method populateUserDefinedHeader.

@Override
protected void populateUserDefinedHeader(String headerName, Object headerValue, SoapMessage target) {
    SoapHeader soapHeader = target.getSoapHeader();
    if (headerValue instanceof String) {
        QName qname = QNameUtils.parseQNameString(headerName);
        soapHeader.addAttribute(qname, (String) headerValue);
    } else if (headerValue instanceof Source) {
        Result result = soapHeader.getResult();
        try {
            this.transformerHelper.transform((Source) headerValue, result);
        } catch (TransformerException e) {
            throw new SoapHeaderException("Could not transform source [" + headerValue + "] to result [" + result + "]", e);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) SoapHeader(org.springframework.ws.soap.SoapHeader) SoapHeaderException(org.springframework.ws.soap.SoapHeaderException) Source(javax.xml.transform.Source) TransformerException(javax.xml.transform.TransformerException) Result(javax.xml.transform.Result)

Example 3 with SoapHeader

use of org.springframework.ws.soap.SoapHeader in project spring-integration by spring-projects.

the class DefaultSoapHeaderMapperTests method testCustomSoapHeader.

@Test
public void testCustomSoapHeader() {
    DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
    mapper.setReplyHeaderNames("x:attr", "x:elem");
    SoapMessage soapMessage = mock(SoapMessage.class);
    SoapHeader soapHeader = mock(SoapHeader.class);
    @SuppressWarnings("unchecked") Iterator<QName> attrIterator = mock(Iterator.class);
    QName attribute = new QName("http://x", "attr", "x");
    @SuppressWarnings("unchecked") Iterator<SoapHeaderElement> elementIterator = mock(Iterator.class);
    SoapHeaderElement soapHeaderElement = mock(SoapHeaderElement.class);
    QName element = new QName("http://x", "elem", "x");
    when(soapMessage.getSoapHeader()).thenReturn(soapHeader);
    when(soapHeader.getAllAttributes()).thenReturn(attrIterator);
    when(attrIterator.hasNext()).thenReturn(true).thenReturn(false);
    when(attrIterator.next()).thenReturn(attribute);
    when(soapHeader.getAttributeValue(attribute)).thenReturn("attrValue");
    when(soapHeader.examineAllHeaderElements()).thenReturn(elementIterator);
    when(elementIterator.hasNext()).thenReturn(true).thenReturn(false);
    when(elementIterator.next()).thenReturn(soapHeaderElement);
    when(soapHeaderElement.getName()).thenReturn(element);
    Map<String, Object> headers = mapper.toHeadersFromReply(soapMessage);
    assertEquals(2, headers.size());
    assertEquals("attrValue", headers.get("x:attr"));
    assertSame(soapHeaderElement, headers.get("x:elem"));
}
Also used : SoapHeaderElement(org.springframework.ws.soap.SoapHeaderElement) QName(javax.xml.namespace.QName) SoapHeader(org.springframework.ws.soap.SoapHeader) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) SoapMessage(org.springframework.ws.soap.SoapMessage) Test(org.junit.Test)

Example 4 with SoapHeader

use of org.springframework.ws.soap.SoapHeader 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 5 with SoapHeader

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

the class TestCreateWebServiceMessage method runTest.

@Override
protected void runTest(SoapMessageFactory messageFactory) {
    SoapMessage message = messageFactory.createWebServiceMessage();
    SoapEnvelope env = message.getEnvelope();
    assertNotNull(env);
    assertEquals(spec.getEnvelopeQName(), env.getName());
    SoapHeader header = env.getHeader();
    assertNotNull(header);
    assertEquals(spec.getHeaderQName(), header.getName());
    SoapBody body = env.getBody();
    assertNotNull(body);
    assertEquals(spec.getHeaderQName(), header.getName());
}
Also used : SoapEnvelope(org.springframework.ws.soap.SoapEnvelope) SoapBody(org.springframework.ws.soap.SoapBody) SoapHeader(org.springframework.ws.soap.SoapHeader) SoapMessage(org.springframework.ws.soap.SoapMessage)

Aggregations

SoapHeader (org.springframework.ws.soap.SoapHeader)8 QName (javax.xml.namespace.QName)5 SoapHeaderElement (org.springframework.ws.soap.SoapHeaderElement)4 SoapMessage (org.springframework.ws.soap.SoapMessage)4 SaajSoapMessage (org.springframework.ws.soap.saaj.SaajSoapMessage)3 HashMap (java.util.HashMap)2 Source (javax.xml.transform.Source)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 Result (javax.xml.transform.Result)1 TransformerException (javax.xml.transform.TransformerException)1 DOMSource (javax.xml.transform.dom.DOMSource)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 AbstractWebServiceOutboundGateway (org.springframework.integration.ws.AbstractWebServiceOutboundGateway)1 MessageChannel (org.springframework.messaging.MessageChannel)1 MessageHeaders (org.springframework.messaging.MessageHeaders)1 WebServiceMessage (org.springframework.ws.WebServiceMessage)1 WebServiceMessageFactory (org.springframework.ws.WebServiceMessageFactory)1