List of usage examples for org.apache.commons.httpclient HttpMethod setFollowRedirects
public abstract void setFollowRedirects(boolean paramBoolean);
From source file:org.eclipsetrader.directa.internal.core.connector.StreamingConnector.java
protected void fetchLatestSnapshot(String[] sTit) { int flag[] = new int[sTit.length]; for (int i = 0; i < flag.length; i++) { flag[i] = 1;/*from w ww.jav a 2s . co m*/ } try { String s = "[!QUOT]"; //$NON-NLS-1$ byte byte0 = 43; Hashtable<String, Map<String, String>> hashTable = new Hashtable<String, Map<String, String>>(); try { HttpMethod method = createSnapshotMethod(sTit, INFO, streamingServer, WebConnector.getInstance().getUrt(), WebConnector.getInstance().getPrt()); method.setFollowRedirects(true); logger.debug(method.getURI().toString()); HttpClient client = new HttpClient(); setupProxy(client, streamingServer); client.executeMethod(method); BufferedReader bufferedreader = new BufferedReader( new InputStreamReader(method.getResponseBodyAsStream())); String s5; while ((s5 = bufferedreader.readLine()) != null && !s5.startsWith(s)) { logger.debug(s5); } if (s5 != null) { do { logger.debug(s5); if (s5.startsWith(s)) { Map<String, String> as = new HashMap<String, String>(); StringTokenizer stringtokenizer = new StringTokenizer(s5, ",\t"); //$NON-NLS-1$ String s2 = stringtokenizer.nextToken(); s2 = s2.substring(s2.indexOf(s) + s.length()).trim(); for (int j = 0; j < byte0; j++) { String s4; try { s4 = stringtokenizer.nextToken().trim(); int sq = s4.indexOf("]"); as.put(s4.substring(0, sq + 1), s4.substring(sq + 1)); } catch (NoSuchElementException nosuchelementexception) { hashTable.put(s2, as); break; } } hashTable.put(s2, as); } } while ((s5 = bufferedreader.readLine()) != null); } } catch (Exception e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error reading snapshot data", e); //$NON-NLS-1$ Activator.log(status); } processSnapshotData(sTit, hashTable); wakeupNotifyThread(); } catch (Exception e) { Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error reading snapshot data", e)); //$NON-NLS-1$ } }
From source file:org.eclipsetrader.directa.internal.core.WebConnector.java
public synchronized void login() { final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); final ISecurePreferences securePreferences; if (preferenceStore.getBoolean(Activator.PREFS_USE_SECURE_PREFERENCE_STORE)) { securePreferences = SecurePreferencesFactory.getDefault().node(Activator.PLUGIN_ID); try {//from w ww .ja v a2 s . com if (userName == null) { userName = securePreferences.get(Activator.PREFS_USERNAME, ""); //$NON-NLS-1$ } if (password == null) { password = securePreferences.get(Activator.PREFS_PASSWORD, ""); //$NON-NLS-1$ } } catch (Exception e) { final Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error accessing secure storage", e); //$NON-NLS-1$ Display.getDefault().syncExec(new Runnable() { @Override public void run() { Activator.log(status); ErrorDialog.openError(null, null, null, status); } }); } } else { securePreferences = null; if (userName == null) { userName = preferenceStore.getString(Activator.PREFS_USERNAME); } if (password == null) { password = preferenceStore.getString(Activator.PREFS_PASSWORD); } } prt = ""; //$NON-NLS-1$ urt = ""; //$NON-NLS-1$ user = ""; //$NON-NLS-1$ do { if (userName == null || password == null || "".equals(userName) || "".equals(password)) { //$NON-NLS-1$ //$NON-NLS-2$ Display.getDefault().syncExec(new Runnable() { @Override public void run() { LoginDialog dlg = new LoginDialog(null, userName, password); if (dlg.open() == Window.OK) { userName = dlg.getUserName(); password = dlg.getPassword(); if (dlg.isSavePassword()) { if (preferenceStore.getBoolean(Activator.PREFS_USE_SECURE_PREFERENCE_STORE)) { try { securePreferences.put(Activator.PREFS_USERNAME, userName, true); securePreferences.put(Activator.PREFS_PASSWORD, dlg.isSavePassword() ? password : "", true); //$NON-NLS-1$ } catch (Exception e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error accessing secure storage", e); //$NON-NLS-1$ Activator.log(status); ErrorDialog.openError(null, null, null, status); } } else { preferenceStore.putValue(Activator.PREFS_USERNAME, userName); preferenceStore.putValue(Activator.PREFS_PASSWORD, dlg.isSavePassword() ? password : ""); //$NON-NLS-1$ } } } else { userName = null; password = null; } } }); if (userName == null || password == null) { return; } } if (client == null) { client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(30000); try { setupProxy(client, HOST); } catch (URISyntaxException e) { final Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error setting proxy", e); //$NON-NLS-1$ Display.getDefault().syncExec(new Runnable() { @Override public void run() { Activator.log(status); ErrorDialog.openError(null, null, null, status); } }); } } try { HttpMethod method = new GetMethod("https://" + HOST + "/trading/collegc_3"); //$NON-NLS-1$ //$NON-NLS-2$ method.setFollowRedirects(true); method.setQueryString(new NameValuePair[] { new NameValuePair("USER", userName), //$NON-NLS-1$ new NameValuePair("PASSW", password), //$NON-NLS-1$ new NameValuePair("PAG", "VT4.4.0.6"), //$NON-NLS-1$ //$NON-NLS-2$ new NameValuePair("TAPPO", "X"), //$NON-NLS-1$ //$NON-NLS-2$ }); logger.debug(method.getURI().toString()); client.executeMethod(method); Parser parser = Parser.createParser(method.getResponseBodyAsString(), ""); //$NON-NLS-1$ NodeList list = parser.extractAllNodesThatMatch(new NodeClassFilter(RemarkNode.class)); for (SimpleNodeIterator iter = list.elements(); iter.hasMoreNodes();) { RemarkNode node = (RemarkNode) iter.nextNode(); String text = node.getText(); if (text.startsWith("USER")) { //$NON-NLS-1$ user = text.substring(4); } if (text.startsWith("URT")) { //$NON-NLS-1$ urt = text.substring(3); } else if (text.startsWith("PRT")) { //$NON-NLS-1$ prt = text.substring(3); } } } catch (Exception e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error connecting to login server", e); //$NON-NLS-1$ Activator.log(status); return; } if (user.equals("") || prt.equals("") || urt.equals("")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ password = ""; //$NON-NLS-1$ } } while (user.equals("") || prt.equals("") || urt.equals("")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ account.setId(userName); }
From source file:org.eclipsetrader.directa.internal.core.WebConnector.java
protected void getWatchlist(String id, String title) { try {/*from w ww .j av a 2 s. co m*/ HttpMethod method = new GetMethod("https://" + HOST + "/trading/tabelc_4"); //$NON-NLS-1$ //$NON-NLS-2$ method.setFollowRedirects(true); method.setQueryString(new NameValuePair[] { new NameValuePair("USER", user), //$NON-NLS-1$ new NameValuePair("DEVAR", id), //$NON-NLS-1$ }); logger.debug(method.getURI().toString()); client.executeMethod(method); Parser parser = Parser.createParser(method.getResponseBodyAsString(), ""); //$NON-NLS-1$ NodeList list = parser.extractAllNodesThatMatch(new NodeClassFilter(TableRow.class)); for (SimpleNodeIterator iter = list.elements(); iter.hasMoreNodes();) { TableRow row = (TableRow) iter.nextNode(); if (row.getChildCount() == 23) { if (row.getChild(1) instanceof TableHeader) { continue; } String symbol = ""; //$NON-NLS-1$ String isin = ""; //$NON-NLS-1$ String description = ""; //$NON-NLS-1$ LinkTag link = (LinkTag) ((TableColumn) row.getChild(1)).getChild(1); int s = link.getText().indexOf("TITO="); //$NON-NLS-1$ if (s != -1) { s += 5; int e = link.getText().indexOf("&", s); //$NON-NLS-1$ if (e == -1) { e = link.getText().length(); } symbol = link.getText().substring(s, e); } description = link.getFirstChild().getText(); description = description.replaceAll("[\r\n]", " ").trim(); //$NON-NLS-1$ //$NON-NLS-2$ link = (LinkTag) ((TableColumn) row.getChild(5)).getChild(0); s = link.getText().indexOf("tlv="); //$NON-NLS-1$ if (s != -1) { s += 4; int e = link.getText().indexOf("&", s); //$NON-NLS-1$ if (e == -1) { e = link.getText().length(); } isin = link.getText().substring(s, e); } System.out.println(symbol + " " + isin + " (" + description + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } } catch (Exception e) { logger.error(e.toString(), e); } }
From source file:org.eclipsetrader.directaworld.internal.core.connector.SnapshotConnector.java
protected void fetchLatestSnapshot() { BufferedReader in = null;//from w w w .j av a 2 s . com try { String[] symbols; synchronized (symbolSubscriptions) { symbols = symbolSubscriptions.keySet().toArray(new String[symbolSubscriptions.size()]); } StringBuilder url = new StringBuilder("http://" + HOST + "/cgi-bin/qta?idx=alfa&modo=t&appear=n"); //$NON-NLS-1$ //$NON-NLS-2$ int x = 0; for (; x < symbols.length; x++) { url.append("&id" + (x + 1) + "=" + symbols[x]); //$NON-NLS-1$ //$NON-NLS-2$ } for (; x < 30; x++) { url.append("&id" + (x + 1) + "="); //$NON-NLS-1$ //$NON-NLS-2$ } url.append("&u=" + userName + "&p=" + password); //$NON-NLS-1$ //$NON-NLS-2$ HttpMethod method = new GetMethod(url.toString()); method.setFollowRedirects(true); logger.debug(method.getURI().toString()); client.executeMethod(method); requiredDelay = 15; String inputLine; in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((inputLine = in.readLine()) != null) { logger.debug(inputLine); if (inputLine.indexOf("<!--QT START HERE-->") != -1) { //$NON-NLS-1$ while ((inputLine = in.readLine()) != null) { logger.debug(inputLine); if (inputLine.indexOf("<!--QT STOP HERE-->") != -1) { //$NON-NLS-1$ break; } try { parseLine(inputLine); } catch (Exception e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error parsing line: " + inputLine, e); //$NON-NLS-1$ Activator.log(status); } } } else if (inputLine.indexOf("Sara' possibile ricaricare la pagina tra") != -1) { //$NON-NLS-1$ int beginIndex = inputLine.indexOf("tra ") + 4; //$NON-NLS-1$ int endIndex = inputLine.indexOf("sec") - 1; //$NON-NLS-1$ try { requiredDelay = Integer.parseInt(inputLine.substring(beginIndex, endIndex)) + 1; } catch (Exception e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error parsing required delay", e); //$NON-NLS-1$ Activator.log(status); } } } in.close(); FeedSubscription[] subscriptions; synchronized (symbolSubscriptions) { Collection<FeedSubscription> c = symbolSubscriptions.values(); subscriptions = c.toArray(new FeedSubscription[c.size()]); } for (int i = 0; i < subscriptions.length; i++) { subscriptions[i].fireNotification(); } } catch (Exception e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error reading data", e); //$NON-NLS-1$ Activator.log(status); } finally { try { if (in != null) { in.close(); } } catch (Exception e) { // We can't do anything at this time, ignore } } }
From source file:org.eclipsetrader.directaworld.internal.core.connector.SnapshotConnector.java
protected boolean checkLogin() { boolean result = false; BufferedReader in = null;/*from ww w . j av a2 s. co m*/ try { StringBuilder url = new StringBuilder("http://" + HOST + "/cgi-bin/qta?idx=alfa&modo=t&appear=n"); //$NON-NLS-1$ //$NON-NLS-2$ int x = 0; for (; x < 30; x++) { url.append("&id" + (x + 1) + "="); //$NON-NLS-1$ //$NON-NLS-2$ } url.append("&u=" + userName + "&p=" + password); //$NON-NLS-1$ //$NON-NLS-2$ HttpMethod method = new GetMethod(url.toString()); method.setFollowRedirects(true); client.executeMethod(method); requiredDelay = 15; String inputLine; in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((inputLine = in.readLine()) != null) { if (inputLine.indexOf("<!--QT START HERE-->") != -1) { //$NON-NLS-1$ result = true; } } in.close(); } catch (Exception e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error reading data", e); //$NON-NLS-1$ Activator.log(status); } finally { try { if (in != null) { in.close(); } } catch (Exception e) { // We can't do anything at this time, ignore } } return result; }
From source file:org.eclipsetrader.kdb.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); HttpClient client = new HttpClient(); Util.setupProxy(client, method.getURI().getHost()); client.executeMethod(method);/*from w ww . j av a2 s . co m*/ BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); read1DayBackfillStream(list, in); in.close(); method.releaseConnection(); 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); HttpClient client = new HttpClient(); Util.setupProxy(client, method.getURI().getHost()); client.executeMethod(method);/*from w ww . ja va 2 s.c o m*/ 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); HttpClient client = new HttpClient(); Util.setupProxy(client, method.getURI().getHost()); client.executeMethod(method);/*www .j av a 2 s .c o m*/ 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 . j a va2s . c o m*/ 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.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);// www .ja v a 2 s .c o m 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()]); }