I am facing some issues in getting the values from the payload in jdbc-outbound-adapter. The details are given below
a) Downloading csv files from remote server using int-sftp:inbound-channel-adapter
b). Adding filename to the header using header-enricher
<int:transformer id="filetoPojoTransformer" input-channel="outputChannel" method="processContent"
output-channel="fileOutputChannel" ref="FileToPOJOTransformer" />
c. Transforming the file content to POJO using custom transformer (used openCSV library to acheive this)
<int:transformer id="filetoPojoTransformer" input-channel="outputChannel" method="processContent"
output-channel="fileOutputChannel" ref="FileToPOJOTransformer" />
d) FileToPOJOTransformer class below
public class FileToPOJOTransformer {
public List processContent(File file){
String[] columns = null;
List<String> lines = null;
List<Model1> list = null;
try {
lines = Files.readAllLines(file.toPath(),
StandardCharsets.UTF_8);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
columns = lines.get(0).split(",");
final ColumnPositionMappingStrategy<Model1> strategy = new ColumnPositionMappingStrategy<>();
strategy.setType(Model1.class);
strategy.setColumnMapping(columns);
final CsvToBean<Model1> csvToBean = new CsvToBean<>();
try (final Reader reader = new FileReader(file)) {
list = csvToBean.parse(strategy, reader);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return list;
}
}
e) Using router delegating to corresponding channels based on the file name
<int:recipient-list-router id="customRouter" input-channel="fileOutputChannel" default-output-channel="nullChannel">
<int:recipient channel="channel1" selector-expression="headers['fileName'].startsWith('File1')"/>
<int:recipient channel="channel2" selector-expression="headers['fileName'].startsWith('File2')"/>
</int:recipient-list-router>
f) Now I have to store the content of CSV to database so I have used jdbc-outbound-adapter
<int-jdbc:outbound-channel-adapter
id="jdbcOutBoundAdapterEndpoint1" channel="channel1"
query="insert into ImodiumTracking.ResponsesSent (Col1)
values(:payload.get(0).Col1)"
data-source="dataSource">
</int-jdbc:outbound-channel-adapter>
I have tried different options to get the bean values but didn't work. How to obtain the bean values in the jdbc-outbound-adapter from the payload which contains list of POJOs