Reputation: 31
I have to write a batch (read/process/write) that call a web service (SOAP) as input and then process the result (list of items) to finally write them in a database. How can i call a web service
Upvotes: 2
Views: 11230
Reputation: 3784
We did similar thing and here is our approach:
SOAP part:
marshalSendAndReceive
which basically sends xml request to some url and returns xml responseJaxb2Marshaller
for serialization and deserialization and POJO generating from wsdl Spring batch part:
ItemReader
where in @BeforeStep
we fetch list of items to process from SOAP server (I am not sure if this is best approach but with retry mechanism in place this is robust enough), our @Override
of read method is nothing special, it is walking over list until exhausted Example:
Item reader is using SoapClient
which is my wrapper around web template and it is doing soap call, unmarshalling response and returning list of items.
@Component
@StepScope
public class CustomItemReader implements ItemReader<SoapItem> {
private List<SoapItem> soapItems;
@Autowired
private SoapClient soapClient;
@BeforeStep
public void beforeStep(final StepExecution stepExecution) throws Exception {
soapItems = soapClient.getItems();
}
@Override
public SoapItem read() {
if (!soapItems.isEmpty()) {
return soapItems.remove(0);
}
return null;
}
}
Upvotes: 7