List of usage examples for org.apache.commons.httpclient HttpMethod getURI
public abstract URI getURI() throws URIException;
From source file:org.eclipsetrader.yahoo.internal.core.connector.BackfillConnector.java
private IOHLC[] backfillDailyHistory(IFeedIdentifier identifier, Date from, Date to) { List<OHLC> list = new ArrayList<OHLC>(); Calendar c = Calendar.getInstance(); c.setTime(from);/* w ww . j a va 2s . c om*/ int firstYear = c.get(Calendar.YEAR); c.setTime(to); int lastYear = c.get(Calendar.YEAR); HttpClient client = new HttpClient(); for (int ys = firstYear; ys <= lastYear; ys++) { try { HttpMethod method = Util.get1YearHistoryFeedMethod(identifier, ys); Util.setupProxy(client, method.getURI().getHost()); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); readDailyBackfillStream(list, in); in.close(); } catch (Exception e) { Status status = new Status(IStatus.ERROR, YahooActivator.PLUGIN_ID, 0, "Error reading data", e); YahooActivator.log(status); } } Collections.sort(list, new Comparator<OHLC>() { @Override public int compare(OHLC o1, OHLC o2) { return o1.getDate().compareTo(o2.getDate()); } }); for (Iterator<OHLC> iter = list.iterator(); iter.hasNext();) { OHLC ohlc = iter.next(); if (ohlc.getDate().before(from) || ohlc.getDate().after(to)) { iter.remove(); } } return list.toArray(new IOHLC[list.size()]); }
From source file:org.eclipsetrader.yahoo.internal.core.connector.BackfillConnector.java
private IOHLC[] backfill1DayHistory(IFeedIdentifier identifier) throws Exception { List<OHLC> list = new ArrayList<OHLC>(); HttpMethod method = Util.get1DayHistoryFeedMethod(identifier); method.setFollowRedirects(true);// w ww. j a v a2 s. com HttpClient client = new HttpClient(); Util.setupProxy(client, method.getURI().getHost()); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); read1DayBackfillStream(list, in); in.close(); return list.toArray(new IOHLC[list.size()]); }
From source file:org.eclipsetrader.yahoo.internal.core.connector.BackfillConnector.java
private IOHLC[] backfill5DayHistory(IFeedIdentifier identifier) throws Exception { List<OHLC> list = new ArrayList<OHLC>(); HttpMethod method = Util.get5DayHistoryFeedMethod(identifier); method.setFollowRedirects(true);/*from w w w .j a v a2 s . c om*/ HttpClient client = new HttpClient(); Util.setupProxy(client, method.getURI().getHost()); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); read1DayBackfillStream(list, in); in.close(); return list.toArray(new IOHLC[list.size()]); }
From source file:org.eclipsetrader.yahoo.internal.core.connector.BackfillConnector.java
@Override public IDividend[] backfillDividends(IFeedIdentifier identifier, Date from, Date to) { List<IDividend> list = new ArrayList<IDividend>(); try {/*from ww w. ja v a 2 s. c om*/ HttpMethod method = Util.getDividendsHistoryMethod(identifier, from, to); method.setFollowRedirects(true); HttpClient client = new HttpClient(); Util.setupProxy(client, method.getURI().getHost()); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); // The first line is the header, ignoring String inputLine = in.readLine(); while ((inputLine = in.readLine()) != null) { if (inputLine.startsWith("<")) { continue; } try { Dividend dividend = parseDividendsResponseLine(inputLine); if (dividend != null) { list.add(dividend); } } catch (ParseException e) { Status status = new Status(IStatus.ERROR, YahooActivator.PLUGIN_ID, 0, "Error parsing data: " + inputLine, e); YahooActivator.log(status); } } in.close(); } catch (Exception e) { Status status = new Status(IStatus.ERROR, YahooActivator.PLUGIN_ID, 0, "Error reading data", e); YahooActivator.log(status); } return list.toArray(new IDividend[list.size()]); }
From source file:org.eclipsetrader.yahoo.internal.core.UtilTest.java
public void testGet1YearBackfillMethod() throws Exception { FeedIdentifier identifier = new FeedIdentifier("MSFT", new FeedProperties()); String expected = "http://chartapi.finance.yahoo.com/instrument/1.0/msft/chartdata;type=quote;ys=2011;yz=1/csv/"; HttpMethod method = Util.get1YearHistoryFeedMethod(identifier, 2011); assertEquals(expected, method.getURI().toString()); }
From source file:org.eclipsetrader.yahoo.internal.core.UtilTest.java
public void testGet1DaysBackfillMethod() throws Exception { FeedIdentifier identifier = new FeedIdentifier("MSFT", new FeedProperties()); String expected = "http://chartapi.finance.yahoo.com/instrument/1.0/msft/chartdata;type=quote;range=1d/csv/"; HttpMethod method = Util.get1DayHistoryFeedMethod(identifier); assertEquals(expected, method.getURI().toString()); }
From source file:org.eclipsetrader.yahoo.internal.core.UtilTest.java
public void testGet5DaysBackfillMethod() throws Exception { FeedIdentifier identifier = new FeedIdentifier("MSFT", new FeedProperties()); String expected = "http://chartapi.finance.yahoo.com/instrument/1.0/msft/chartdata;type=quote;range=5d/csv/"; HttpMethod method = Util.get5DayHistoryFeedMethod(identifier); assertEquals(expected, method.getURI().toString()); }
From source file:org.eclipsetrader.yahoo.internal.core.UtilTest.java
public void testGetBackfillMethodForIndex() throws Exception { FeedIdentifier identifier = new FeedIdentifier("^IXIC", new FeedProperties()); String expected = "http://chartapi.finance.yahoo.com/instrument/1.0/%5Eixic/chartdata;type=quote;ys=2011;yz=1/csv/"; HttpMethod method = Util.get1YearHistoryFeedMethod(identifier, 2011); assertEquals(expected, method.getURI().toString()); }
From source file:org.eclipsetrader.yahoojapan.internal.core.connector.BackfillConnector.java
private IOHLC[] backfillDailyHistory(IFeedIdentifier identifier, Date from, Date to) { List<OHLC> list = new ArrayList<OHLC>(); Calendar c = Calendar.getInstance(); c.setTime(from);/*from www . j ava2s . co m*/ int firstYear = c.get(Calendar.YEAR); c.setTime(to); int lastYear = c.get(Calendar.YEAR); //limit 3 years if (firstYear < lastYear - 3) { firstYear = lastYear - 3; } HttpClient client = new HttpClient(); for (int ys = firstYear; ys <= lastYear; ys++) { try { for (int page = 1; page < 21; page++) { HttpMethod method = Util.get1YearHistoryFeedMethod(identifier, ys, page); Util.setupProxy(client, method.getURI().getHost()); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); // readDailyBackfillStream(list, in); boolean hasNextPage = readBackfillStream(list, in); in.close(); if (!hasNextPage) { break; } } } catch (Exception e) { Status status = new Status(IStatus.ERROR, YahooJapanActivator.PLUGIN_ID, 0, "Error reading data", e); YahooJapanActivator.log(status); } } Collections.sort(list, new Comparator<OHLC>() { @Override public int compare(OHLC o1, OHLC o2) { return o1.getDate().compareTo(o2.getDate()); } }); for (Iterator<OHLC> iter = list.iterator(); iter.hasNext();) { OHLC ohlc = iter.next(); if (ohlc.getDate().before(from) || ohlc.getDate().after(to)) { iter.remove(); } } return list.toArray(new IOHLC[list.size()]); }
From source file:org.eclipsetrader.yahoojapan.internal.core.connector.BackfillConnector.java
@Override public ISplit[] backfillSplits(IFeedIdentifier identifier, Date from, Date to) { List<ISplit> list = new ArrayList<ISplit>(); System.out.println(from.toString()); System.out.println(to.toString()); Calendar c = Calendar.getInstance(); c.setTime(to);//from ww w.ja v a2 s . com int lastYear = c.get(Calendar.YEAR); c.setTime(from); int firstYear = c.get(Calendar.YEAR); //limit 3 years if (firstYear < lastYear - 3) { firstYear = lastYear - 3; c.set(Calendar.YEAR, firstYear); } try { for (int page = 1; page < 21; page++) { HttpMethod method = Util.getDividendsHistoryMethod(identifier, to, c.getTime(), page); method.setFollowRedirects(true); HttpClient client = new HttpClient(); Util.setupProxy(client, method.getURI().getHost()); client.executeMethod(method); System.out.println(method.getURI().toString()); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); StringBuilder line = new StringBuilder(); // The first line is the header, ignoring String inputLine = in.readLine(); while ((inputLine = in.readLine()) != null) { // System.out.println("****" + inputLine); if (inputLine.indexOf("<!---->") >= 0) { break; } } while ((inputLine = in.readLine()) != null) { // System.out.println("+++" + inputLine); if (inputLine.indexOf("<!--/-->") >= 0) { String[] work = line.toString().split("</tr><tr><td>"); for (int i = 1; i < work.length; i++) { try { Split split = parseSplitsResponseLine(work[i]); if (split != null) { list.add(split); } } catch (ParseException e) { Status status = new Status(IStatus.ERROR, YahooJapanActivator.PLUGIN_ID, 0, "Error parsing data: " + work[i], e); YahooJapanActivator.log(status); } } break; } if (inputLine.startsWith("</tr><tr><td>")) { if (!inputLine.startsWith("</tr><tr><td>2")) { line = new StringBuilder(); } line.append(inputLine); } else if (inputLine.startsWith("</tr>")) { line.append(inputLine); } if (inputLine.startsWith("<td>")) { line.append(inputLine); } } boolean hasNextPage = false; if (inputLine.indexOf("<!---->") >= 0) { if (inputLine.indexOf("?") >= 0) { hasNextPage = true; } } else { while ((inputLine = in.readLine()) != null) { if (inputLine.indexOf("<!---->") >= 0) { if (inputLine.indexOf("?") >= 0) { hasNextPage = true; break; } } } } in.close(); if (!hasNextPage) { break; } } } catch (Exception e) { Status status = new Status(IStatus.ERROR, YahooJapanActivator.PLUGIN_ID, 0, "Error reading data", e); YahooJapanActivator.log(status); } return list.toArray(new ISplit[list.size()]); }