Spring JDBC Outbound Gateway To Return Original Payload

379 views Asked by At

Using JdbcOutboundGateway, how do I get the reply to be original payload?

Currently, the response payload is {UPDATED=1}. Neither reference document (Spring 5.2.x) nor the source code seems to offer an alternative.

Should I extend the class and override handleRequestMessage to return the original payload? The method is protected which reads to me as an invite to extend or is there a preferred 'pattern' in Spring Integration to handle {UPDATED=1} in the next @ServiceActivator and somehow restore the payload.

If someone is kind enough to respond, please give an example using configuration/annotations and not XML or DSL.

Edit

I ended up doing something like below. Is it advisable to do this? Am I missing something by not using the 'integration-jdbc' methods?

@Bean
@ServiceActivator(inputChannel="myIn", outputChannel="myOut")
public GenericHandler<String> saveToDb(@Autowired MyRepository myRepo) {
  return (payload, header) -> {
    MyClass x = (MyClass) headers.get("MyClassObject")
    myRepo.save(x);
    return payload;
  };
}
1

There are 1 answers

2
Gary Russell On

The simplest solution is to add a header enricher before the gateway and copy the payload into a header.