Search code examples
spring-integrationspring-integration-dsl

What is the preferred way of specifying a transformer for the response of an outgoing gateway using DSL


I have the following piece of code:

@Configuration
@EnableConfigurationProperties(ISOGatewayProperties::class)
class ISOGatewayConfig {

    @Bean
    fun isoGatewayFlow(
        isoProps: ISOGatewayProperties,
        isoTransformer: ISOTransformer) : IntegrationFlow =
            IntegrationFlows
                .from(MessageChannels.direct("isoInChannel"))
                .log()
                .transform(isoTransformer)
                .handle(Tcp.outboundGateway(
                    Tcp.netClient(isoProps.host, isoProps.port)))
                .get()
}

This code correctly converts the request which is an object to a byte[] for sending to the remote server

My questions are the following:

  1. What is the preferred way of transforming the response from the server?
  2. Is it possible to use a single class for both transformations?

Answered by Artem The correct way of doing custom protocols is to use custom serializer/deserializer.


Solution

  • You just need to add a .transform(...) after that .handle(Tcp.outboundGateway(...)) in the flow.

    Well, you can use the same class for both request and response, but I believe in case of response you need to create an ISO object from the byte[], therefore you would need to specify a method name as a second .transform() argument to make things clear for the target transformation endpoint.