Java Reference
In-Depth Information
return cust;
Because the object and table are both straightforward, the RowMapper consists of nothing more
than moving each column from the result set to its related customer attribute.
The final piece of the job is the ItemProcessor you use to call the web service and geocode
customers' addresses. Most of this code matches the code you used in the statement job previously to
obtain stock prices. Using HttpClient , you build a GET request and parse the comma-delimited results
into the customer's latitude and longitude. Listing 11-22 shows the code for GeocodingItemProcessor .
Listing 11-22. GeocodingItemProcessor
package com.apress.springbatch.chapter11.processor;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.springframework.batch.item.ItemProcessor;
import com.apress.springbatch.chapter11.domain.Customer;
public class GeocodingItemProcessor implements ItemProcessor<Customer, Customer> {
private static final String COMMA = ",";
private static final String UTF_8 = "UTF-8";
private String url;
public Customer process(Customer customer) throws Exception {
System.out.println("******** I'm going to process " + customer);
HttpClient client = new DefaultHttpClient();
String address = buildAddress(customer);
if(address == null) {
return null;
HttpGet get = new HttpGet(url + "?q=" + address);
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
String coordinantes = IOUtils.toString(entity.getContent());
Search WWH ::

Custom Search