Anil Bhaskaran
Anil Bhaskaran

Reputation: 535

Spring Integration File Outbound Adapter

Is there any way we can use file outbound adapter to write the entire SOAP envelop to file rather than just payload ? (I am able to write the payload into a file).

Upvotes: 1

Views: 663

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121552

Assuming you use there <int-ws:inbound-gateway>. Or it doesn't matter for the target solution...

You should implement some EndpointInterceptor add it to the UriEndpointMapping. With the handleRequest implementation you have access to the whole MessageContext where you are able to do something like:

((SoapMessage) messageContext.getRequest()).getEnvelope()

And send this object to the channel for the outbound-channel-adapter to stream its Source to the file.

From the gateway perspective you don't have the access to the messageContext anymore.

UPDATE

According to your comment below (please, consider to place similar info in the question directly in the future), I can suggests something like headers trick:

You implement custom SoapHeaderMapper (extends DefaultSoapHeaderMapper) and overriding toHeadersFromRequest() store passed in SoapMessage to your won header and use it the same way as we discussed in the EndpointInterceptor case. From the <int-file:outbound-channel-adapter> perspective you just should consult that header to extract the Source and its InputStream to store in the file.

UPDATE 2

public class MySoapHeaderMapper extends DefaultSoapHeaderMapper {

    @Override
    public Map<String, Object> toHeadersFromRequest(SoapMessage source) {
        Map<String, Object> headers = super.toHeadersFromRequest(source);
        headers.put("soapMessage", source);
        return headers;
    }

}

You should inject it into <int-ws:inbound-gateway> as a header-mapper. Afterwards that soapMessage header will be available in any downstream component. E.g.

<chain input-channel="storeToFile">
    <transformer expression="headers.soapMessage.envelope.source.inputStream"/>
    <int-file:outbound-channel-adapter /> 
</chain>

Upvotes: 0

Related Questions