Java Reference
In-Depth Information
only want to make the request once in the case of an import failure. If you've already retrieved the
results, then the next time you come through, you can return null to indicate that the input has been
exhausted. Listing 10-21 shows UrlReader .
Listing 10-21. UrlReader
package com.apress.springbatch.statement.reader;
import java.util.List;
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.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import com.apress.springbatch.statement.dao.TickerDao;
public class UrlReader implements ItemStreamReader<String> {
private String host;
private String path;
private int curPage = -1;
private int pageSize = 200;
private TickerDao tickersDao;
public String read() throws Exception, UnexpectedInputException,
ParseException {
HttpClient client = new DefaultHttpClient();
String buildQueryString = buildQueryString();
if(buildQueryString == null) {
return null;
URI uri = new URI("http", host, path, buildQueryString, null);
HttpGet get = new HttpGet(uri);
HttpResponse response = client.execute(get);
Search WWH ::

Custom Search