问题
i have a code to access the web-service which in turn return me a response
<int:chain input-channel="balanceChannel" output-channel="processedItems">
<int-ws:outbound-gateway destination-provider="myDestinationProvider" />
</int:chain>
<int:service-activator input-channel="processedItems"
ref="responseHandler" method="handleResponse" output-channel="nativeQlChannel" />
i am able to get response in my responseHandler , but i also want request object which i send to web-service using channel ? how can i access same request object in responseHandler ?
回答1:
Well, since all Spring Integration endpoints are decoupled from each other via channel and we can consider them as Microservices. And that is really logical and natural then the next endpoint knows nothing about the input of the previous one.
Anyway we can reach requirement with the message headers. So, you copy request payload to the headers and get access for it in the downstream:
<int:header-enricher>
<int:header name="request" expression="payload"/>
</int:header-enricher>
Your service method handleResponse
can accept the entire Message<?>
to get access to that headers or your can just add one more method param with the @Header("request")
annotation.
来源:https://stackoverflow.com/questions/39702545/web-service-integration-how-to-access-request-object-in-response-class