如何在Spring Integration XML中添加WS-A属性构建请求
Got it, let's work through this problem together. The main challenge here is that your incoming JMS message only holds the raw SOAP Body content—we can't wrap it in an extra <soapenv:Body> tag, but we still need to inject the required WS-A headers like wsa:From and wsa:To into the SOAP envelope. Here's a complete XML configuration example and breakdown of how it works:
Make sure your project includes Spring Web Services' WS-A support. If you're using Maven, add this to your pom.xml:
<dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-support</artifactId> <version>${spring-ws.version}</version> </dependency>
Note: Match the version to your existing Spring Integration/Spring WS setup to avoid compatibility issues.
We'll use Spring WS's built-in ActionCallback to automatically populate the required WS-A headers. This bean handles adding wsa:Action, wsa:From, wsa:To, and other optional headers like wsa:MessageID or wsa:ReplyTo:
<!-- WS-A callback to inject required headers --> <bean id="wsAddressingCallback" class="org.springframework.ws.soap.addressing.client.ActionCallback"> <!-- Required: Set the WS-A Action URI --> <constructor-arg value="http://your-target-service-namespace/your-operation-action"/> <!-- Set wsa:From header --> <property name="from" value="http://your-client-endpoint-identifier/from"/> <!-- Set wsa:To header --> <property name="to" value="http://target-web-service-endpoint-url"/> <!-- Optional: Add MessageID if required by the service --> <!-- <property name="messageId" value="urn:uuid:${random.uuid}" /> --> <!-- Optional: Configure ReplyTo address if needed --> <!-- <property name="replyTo" ref="replyToEndpoint" /> --> </bean> <!-- Optional: Define a ReplyTo endpoint reference if needed --> <bean id="replyToEndpoint" class="org.springframework.ws.soap.addressing.core.EndpointReference"> <constructor-arg value="http://your-client-endpoint/reply-to"/> </bean>
The key here is transforming the raw JMS payload (SOAP Body content) into a valid SOAP envelope without adding an extra <soapenv:Body> tag, then attaching the WS-A headers before sending:
<!-- 1. Receive messages from your JMS queue --> <int-jms:message-driven-channel-adapter id="jmsInboundAdapter" destination="yourJmsRequestQueue" channel="wsRequestChannel"/> <!-- 2. Convert raw JMS payload (SOAP Body content) to a SOAP message --> <!-- This transformer uses the raw XML directly as the SOAP Body, no extra wrapping --> <int:transformer input-channel="wsRequestChannel" output-channel="wsEnrichedChannel"> <bean class="org.springframework.integration.ws.PayloadRootSoapMessageTransformer"> <!-- Replace with your payload's namespace and root element name --> <constructor-arg value="http://your-payload-namespace"/> <constructor-arg value="YourPayloadRootElement"/> </bean> </int:transformer> <!-- 3. Send the SOAP message with WS-A headers to the target service --> <int-ws:outbound-gateway id="wsOutboundGateway" request-channel="wsEnrichedChannel" uri="http://target-web-service-endpoint-url" message-callback="wsAddressingCallback"/>
PayloadRootSoapMessageTransformer: This is critical—it takes your raw JMS payload (the SOAP Body content) and inserts it directly into the SOAP envelope's Body section, no extra<soapenv:Body>tag added. Perfect for your requirement.ActionCallback: This bean handles all WS-A header injection, which resolves the "1100 Missing required wsa:From header" error. It adheres to WS-Addressing standards so the target service will recognize the headers.- Debugging: If you need to verify the generated SOAP request, enable debug logging for Spring WS:
This will log the full SOAP envelope, letting you confirm headers are present and the Body is correctly formatted.<logger name="org.springframework.ws.client.MessageTracing.sent" level="DEBUG"/>
内容的提问来源于stack exchange,提问作者Kris Swat

