I am very new to Spring Integration and trying to figure out how to return a stream of data, but cannot find any examples. I found documentation around the ByteStreamWritingMessageHandler, but it seems kind of vague to me and doesn't provide an example of usage (other than bean definition). I'm assuming what I need to do is define a channel that uses the ByteStreamWritingMessageHandler and reference it in my inbound-gateway (via reply-channel), but I have some questions:
First, am I right? Can I use the default channel type? Do I need a channel adapter? Can I just return a ByteArrayOutputStream from my service method? What would the channel definition look like?
Any help would be greatly appreciated.
---------------UPDATE-----------
Our current endpoints are structured like this:
<int:channel id="httpReplyChannel"/>
<int:channel id="exampleService.exampleMethod"/>
<int-http:inbound-gateway path="/example"
supported-methods="POST"
request-channel="exampleService.exampleMethod"
request-payload-type="java.lang.Integer"
reply-channel="httpReplyChannel"
message-converters="jsonMessageConverter"
mapped-request-headers="*"/>
<int:service-activator input-channel="exampleService.exampleMethod"
ref="exampleService"
method="exampleMethod"/>
So we use two channels one for inbound and one for outbound and use the reply-channel attribute of the http:inbound-gateway to configure the outbound channel. I would like to follow the same pattern, but create a new outbound channel. My problem is that I'm not sure what type of channel would work best for returning a stream. The endpoint will return an a stream containing an image directly to the browser (which will make the request via the HTML img tag). So, I need my exampleMethod to return a stream (ByteArrayOutputStream) and I need to have access to dynamically set headers based on what type of image is being returned.
MessageHandler
s such as that one are 'one-way' endoints (outbound). You can't just "hook one up" to an inbound gateway. To answer your question further, I need to know what kind of gateway you are talking about and more detail about what you are trying to do. There are many possibilities but I don't want to waste my (or your) time with speculation. – Gary Russell