OK; got it.
What you need to do is capture the header from a good inbound message.
If an inbound message is good and your app replies; it will contain the header.
If the inbound message fails, you'll have to populate the header as I described in the error flow.
For unsolicited outbound messages, you'll need to use the previously saved header. Something like this should work.
Code:
public class SaveHeader {
private volatile String header;
public String getHeader() {
return header;
}
public void setHeader(String header) {
this.header = header;
}
}
Code:
<int-ip:tcp-connection-factory id="crLfServer"
type="server"
port="11111"/>
<int-ip:tcp-inbound-channel-adapter connection-factory="crLfServer"
channel="inbound"/>
<int:recipient-list-router>
<int:recipient channel="saveHeader"/>
<int:recipient channel="doWork"/>
</int:recipient-list-router>
<int:channel id="saveHeader" />
<bean id="headerSav" class="foo.SaveHeader" />
<int:chain input-channel="saveHeader" >
<int:transformer expression="headers.ip_connection_id"/>
<int:service-activator ref="headerSaver" method="setHeader"/>
</int:chain>
<int:channel id="doWork" />
<!-- Your main code here including error handling as above -->
<!-- ##################################################### -->
<!-- Your unsolicited outbound -->
<int:channel id="unsolicitedMessageChannel"/>
<int:header-enricher input-channel="unsolicitedMessageChannel"
output-channel="toOutboundAdapter">
<int:header name="ip_connection_id" expression="@headerSaver.header"/>
</int:header-enricher>
Because the setHeader method returns void, that part of the flow ends and we then send the message to the next recipient (your code).
The header enricher uses a SpEL expression to get the header value by calling the getHeader() method on the headerSaver.
I haven't tested it, but hopefully you get the idea.