@Override
public List<IContract> searchContracts(IContract criteria, ITaskMonitor taskMonitor) throws ConnectException, RequestFailedException {
String symbol = criteria.getSymbol();
if (symbol == null || symbol.trim().length() == 0) {
throw new RequestFailedException("Symbol must be speficied for Yahoo! Finance ticker query");
}
String quotedSymbol;
try {
quotedSymbol = URLEncoder.encode(symbol, URL_ENCODING_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new RequestFailedException("Exception encoding symbol: " + symbol, e);
}
String queryUrl = String.format(YAHOO_TICKER_QUERY_URL, quotedSymbol);
logger.log(Level.INFO, "Query Yahoo!Finance for tickers: " + queryUrl);
JSON response = null;
try {
String responseString = httpQuery(queryUrl);
String jsonResponse = responseString.replace("YAHOO.Finance.SymbolSuggest.ssCallback(", "").replace(")","");
Reader responseReader = new StringReader(jsonResponse);
logger.log(Level.FINE, "Response from Yahoo!Finance: " + jsonResponse);
response = JSON.parse(responseReader);
} catch (IOException e) {
throw new ConnectException("Exception while connecting to: " + queryUrl + " [" + e.getMessage() + "]");
} catch (JSONException e) {
throw new RequestFailedException("Exception parsing response data from: " + queryUrl, e);
}
@SuppressWarnings("unchecked")
List<JSON> securityList = (List<JSON>) response.get("ResultSet").get("Result").getValue();
List<IContract> contractList = new LinkedList<IContract>();
for (JSON security : securityList) {