Java Reference
In-Depth Information
public void setPath(String path) {
this.path = path;
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
The UrlReader class, like any ItemReader, begins with the read method. In it, you build a query
string and then use HttpClient to send an HTTP GET request to the web service. The results you get back
are in a CSV format: ticker , price .
To create the query string, you call the ticker DAO to obtain the current page of stock tickers to
price. This reader is stateful, so it keeps track of where it is in the list of stocks by page number. You use
the ItemStream's open and update methods to reset the page count on a restart and update the current
page you're processing, respectively.
The last step of putting this reader to use is to configure it and your DAO. The DAO has a single
dependency of a datasource. UrlReader takes three dependencies: a host name, a path, and a reference
to the DAO. Finally, you can add the second step, retrieveStockPrices , with references to your reader.
The configuration for these pieces is shown in Listing 10-22.
Listing 10-22. Configuring the retrieveStockPrices Step
<beans:bean id="stockPriceWebServiceReader"
<beans:property name="host" value=""/>
<beans:property name="path" value="/d/quotes.csv"/>
<beans:property name="tickersDao" ref="tickerDao"/>
<step id="retrieveStockPrices">
<chunk reader="stockPriceWebServiceReader" writer="stockFileWriter" commit-interval="1"/>
<job id="statementJob">
<step id="step1" parent="importCustomerAndTransactionData" next="step2"/>
<step id="step2" parent="retrieveStockPrices"/>
With the input side of step 2 complete, let's look at writing the values you get back from the web
service to a file. This couldn't be easier using Spring Batch's declarative ItemWriters.
Writing the Stock File
Because the output from the web service is in CSV format when you receive it, all you needed to do is
some simple cleanup (removing whitespace at the start and end of each chunk, which was done in your
Search WWH ::

Custom Search