Search code examples
springspring-integrationmq

How to create a request with WS-A attributes in Spring-integration xml


Please can you help in creating a request that includes WS-A parameters From: To: etc

<int:chain input-channel="msoapInChannel" output-channel="justLog">
<ws:header-enricher >
    <ws:soap-action value="http://yeah.com/Txns/port/sPortType/getesRequest"/>
</ws:header-enricher>
<ws:outbound-gateway uri="http://g.tst.b.l/wsb/router"/>
</int:chain>

I want to add wsa:From wsa:To to the request

Error: 1100 A header representing a Message Addressing Property is not present. (Reason: the required header element wsa:From is absent)

How to do this in xml based config?

EDIT: We create request and use JMS queues. The request looks like below

String requestXml =  
"<getnNames xmlns=\"http://b.do.com/DTositeTxns/port\">" +
    "<RequestControl xmlns=\"http://www.im.com/mm/schema\">" + 
"<requestID>123896</requestID>" +
"<DLControl>" + 
    "<requesterName>LW</requesterName>" + 
    "<requesterLocale>RTnl</requesterLocale>" + 
"</DLControl>" +
    "</RequestControl>" +
    "<InquiryParam xmlns=\"http://www.im.com/mm/schema\">" + 
"<tcrmParam name=\"identiftionNumber\">" + bn + "</tcrmParam>" + 
"<tcrmParam name=\"PartficationType\">1000001</tcrmParam>" +
"<tcrmParam name=\"Filter\">ACTIVE</tcrmParam>" + 
    "</InquiryParam>" +
"</getnNames>" ;

TextMessage outMessage = session.createTextMessage(requestXml);

and send to queue. If I use soapenv:Body, the request is not accepted as valid. So my request is only tags inside body. Not sure how to add header bits.

Please point me to an example that creates request with wsa:To and wsa:From , Relates To , Fault to etc


Solution

  • The wsa:From and wsa:To are Element headers, they are not simple strings like the mentioned soap-action. There the <ws:header-enricher> won't help you.

    However you still can declare a bean for the plain <int:header-enricher> and provide a javax.xml.transform.Source for your headers as values.

    Starting with version 5.0, the Spring Integration's DefaultSoapHeaderMapper can add elements into the <soapenv:Header>: https://docs.spring.io/spring-integration/docs/5.0.5.RELEASE/reference/html/ws.html#ws-message-headers.

    See the sample there is Docs:

    Map<String, Object> headers = new HashMap<>();
    
    String authXml =
         "<auth xmlns='http://test.auth.org'>"
               + "<username>user</username>"
               + "<password>pass</password>"
               + "</auth>";
    headers.put("auth", new StringSource(authXml));
    ...
    DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
    mapper.setRequestHeaderNames("auth");
    

    UPDATE

    The <ws:outbound-gateway> has an attribute like:

    <xsd:attribute name="request-callback" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation>
    Reference to a Spring Web Services WebServiceMessageCallback. This enables changing
    the Web Service request message after the payload has been written to it but prior
    to invocation of the actual Web Service.
                    </xsd:documentation>
                    <xsd:appinfo>
                        <tool:annotation kind="ref">
                            <tool:expected-type type="org.springframework.ws.client.core.WebServiceMessageCallback"/>
                        </tool:annotation>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:attribute>
    

    So, what you need is to configure a bean for the ActionCallback and refer to it from this attribute.

    More info about ActionCallback is in the Spring WS Reference Manual.