Java Reference
In-Depth Information
As you can see in the preceding code snippet, our sample is initialized with IDs from 5 to
9 , and on every GET request, it will provide the ID as the output. When all IDs are emit-
ted, a null value will be returned. This endpoint will serve as a model of a reservation sys-
tem. For simplicity, it produces plaintext values instead of JSON. Of course, a flat file or
any other source of data could also be used for integration.
Creating a chunk-based batch step
Our integration scenario will be pretty straightforward. We need to read all of the reserva-
tion IDs from the external system to get the corresponding seats from our database and
write the changes back to the database. It would also be great to write a log with the oper-
ations made by the import. Let's start with the item reader:
package com.packtpub.wflydevelopment.chapter12.batching;
import java.io.Serializable;
import javax.batch.api.chunk.AbstractItemReader;
import javax.inject.Named;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
@Named
public class ExternalSystemReader extends
AbstractItemReader {
private WebTarget target;
@Override
public void open(Serializable checkpoint) throws
Exception {
final Client restclient = ClientBuilder.newClient();
this.target =
restclient.target("http://localhost:8080/
ticket-agency-longterm/rest/external");
}
@Override
public Object readItem() throws Exception {
Search WWH ::




Custom Search