Java Reference
In-Depth Information
coordinantes = StringUtils.strip(coordinantes);
if(coordinantes.length() > 0) {
String [] values = coordinantes.split(COMMA);
return customer;
private String buildAddress(Customer customer) throws Exception {
if(customer.getCity() == null && customer.getZip() == null) {
return null;
} else {
StringBuilder address = new StringBuilder();
URLEncoder.encode(customer.getCity(), UTF_8) + COMMA, ""));
URLEncoder.encode(customer.getState(), UTF_8) + COMMA, ""));
URLEncoder.encode(customer.getZip(), UTF_8) + COMMA, ""));
return address.substring(0, address.length() - 1);
public void setUrl(String url) {
this.url = url;
Although GeocodingItemProcessor doesn't contain anything truly unusual that you haven't seen
already, look at the first line of the process method. You call System.out.println on each customer so
that when you run the job, you can see where each customer is processed. This way, you can see in the
output of each console who processed what items.
The rest of the code consists of the construction of the HTTP GET request you send to obtain each
customer's longitude and latitude. That's all the coding you need to do for the batch job. You need
another class for the remote-chunking piece, but you look at that in a bit. For now, let's configure the job
and make sure it works before you attempt to tackle the added complexity of remote chunking.
To configure the job, you start with a JdbcCursorItemReader that selects all customers that have null
for either longitude or latitude. That reader requires a RowMapper, which is configured next. Then, you
configure the ItemProcessor that does the heavy lifting of determining the customer's coordinates. The
service you use to geocode the addresses is called TinyGeocoder. You provide the URL to the service as
the ItemProcessor's only dependency. Next is the ItemWriter, a JdbcBatchItemWriter in this job. In this
case, you update the customer records, setting the longitude and latitude for each item as required. The
Search WWH ::

Custom Search