Example usage for org.apache.commons.httpclient HttpMethod getURI

List of usage examples for org.apache.commons.httpclient HttpMethod getURI

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpMethod getURI.

Prototype

public abstract URI getURI() throws URIException;

Source Link

Usage

From source file:org.cruk.genologics.api.debugging.HttpClientTimingAspect.java

/**
 * Join point that, if the logging is set to DEBUG, will report on the
 * call made with the HttpClient and the time taken to get a response.
 *
 * @param pjp The AspectJ join point object. One of the arguments in
 * this object must be the HttpMethod being invoked.
 *
 * @return The result of proceeding with the join point.
 *
 * @throws Throwable if there is any failure.
 *
 * @see HttpClient#executeMethod(HttpMethod)
 *///from w w w  .j  a  va  2s  . c om
public Object timeCall(ProceedingJoinPoint pjp) throws Throwable {
    if (!logger.isDebugEnabled()) {
        return pjp.proceed();
    }

    String uri = "<no url>";
    String method = "<unknown>";

    for (Object arg : pjp.getArgs()) {
        if (arg instanceof HttpMethod) {
            HttpMethod httpMethod = (HttpMethod) arg;
            uri = httpMethod.getURI().getEscapedURI();
            method = httpMethod.getName();
            break;
        }
    }

    long startTime = System.currentTimeMillis();

    try {
        return pjp.proceed();
    } finally {
        long endTime = System.currentTimeMillis();

        double timeTaken = (endTime - startTime) / 1000.0;

        logger.debug("HTTP " + method + " call to " + uri + " took " + timeTaken + " seconds.");
    }
}

From source file:org.eclipse.smarthome.io.net.http.HttpUtil.java

/**
 * Executes the given <code>url</code> with the given <code>httpMethod</code>
 * /*from   w  w  w. j a va  2  s  . c  om*/
 * @param httpMethod the HTTP method to use
 * @param url the url to execute (in milliseconds)
 * @param httpHeaders optional HTTP headers which has to be set on request
 * @param content the content to be send to the given <code>url</code> or 
 * <code>null</code> if no content should be send.
 * @param contentType the content type of the given <code>content</code>
 * @param timeout the socket timeout to wait for data
 * @param proxyHost the hostname of the proxy
 * @param proxyPort the port of the proxy
 * @param proxyUser the username to authenticate with the proxy
 * @param proxyPassword the password to authenticate with the proxy
 * @param nonProxyHosts the hosts that won't be routed through the proxy
 * @return the response body or <code>NULL</code> when the request went wrong
 */
public static String executeUrl(String httpMethod, String url, Properties httpHeaders, InputStream content,
        String contentType, int timeout, String proxyHost, Integer proxyPort, String proxyUser,
        String proxyPassword, String nonProxyHosts) {

    HttpClient client = new HttpClient();

    // only configure a proxy if a host is provided
    if (StringUtils.isNotBlank(proxyHost) && proxyPort != null && shouldUseProxy(url, nonProxyHosts)) {
        client.getHostConfiguration().setProxy(proxyHost, proxyPort);
        if (StringUtils.isNotBlank(proxyUser)) {
            client.getState().setProxyCredentials(AuthScope.ANY,
                    new UsernamePasswordCredentials(proxyUser, proxyPassword));
        }
    }

    HttpMethod method = HttpUtil.createHttpMethod(httpMethod, url);
    method.getParams().setSoTimeout(timeout);
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));
    if (httpHeaders != null) {
        for (String httpHeaderKey : httpHeaders.stringPropertyNames()) {
            method.addRequestHeader(new Header(httpHeaderKey, httpHeaders.getProperty(httpHeaderKey)));
        }
    }
    // add content if a valid method is given ...
    if (method instanceof EntityEnclosingMethod && content != null) {
        EntityEnclosingMethod eeMethod = (EntityEnclosingMethod) method;
        eeMethod.setRequestEntity(new InputStreamRequestEntity(content, contentType));
    }

    Credentials credentials = extractCredentials(url);
    if (credentials != null) {
        client.getParams().setAuthenticationPreemptive(true);
        client.getState().setCredentials(AuthScope.ANY, credentials);
    }

    if (logger.isDebugEnabled()) {
        try {
            logger.debug("About to execute '" + method.getURI().toString() + "'");
        } catch (URIException e) {
            logger.debug(e.getMessage());
        }
    }

    try {

        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            logger.warn("Method failed: " + method.getStatusLine());
        }

        String responseBody = IOUtils.toString(method.getResponseBodyAsStream());
        if (!responseBody.isEmpty()) {
            logger.debug(responseBody);
        }

        return responseBody;
    } catch (HttpException he) {
        logger.error("Fatal protocol violation: {}", he.toString());
    } catch (IOException ioe) {
        logger.error("Fatal transport error: {}", ioe.toString());
    } finally {
        method.releaseConnection();
    }

    return null;
}

From source file:org.eclipse.winery.highlevelrestapi.LowLevelRestApi.java

/**
 * Executes a passed HttpMethod (Method type is either PUT, POST, GET or
 * DELETE) and returns a HttpResponseMessage
 * /*from  w  ww  .j  av  a2  s .c  o m*/
 * @param method Method to execute
 * @return HttpResponseMessage which contains all information about the
 *         execution
 */
public static HttpResponseMessage executeHttpMethod(HttpMethod method) {

    HttpResponseMessage responseMessage = null;

    try {
        System.out.println("Method invocation on URI: \n");
        System.out.println(method.getURI().toString());
        // Execute Request
        LowLevelRestApi.httpClient.executeMethod(method);
        responseMessage = LowLevelRestApi.extractResponseInformation(method);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {

        // Release Connection anyway
        method.releaseConnection();
    }

    // Extract response information and return
    return responseMessage;
}

From source file:org.eclipsetrader.borsaitalia.internal.core.BackfillConnector.java

@Override
public IOHLC[] backfillHistory(IFeedIdentifier identifier, Date from, Date to, TimeSpan timeSpan) {
    String code = identifier.getSymbol();
    String isin = null;//from  w  w  w.  j  ava2 s .c  om

    IFeedProperties properties = (IFeedProperties) identifier.getAdapter(IFeedProperties.class);
    if (properties != null) {
        if (properties.getProperty(Activator.PROP_ISIN) != null) {
            isin = properties.getProperty(Activator.PROP_ISIN);
        }
        if (properties.getProperty(Activator.PROP_CODE) != null) {
            code = properties.getProperty(Activator.PROP_CODE);
        }
    }

    if (code == null || isin == null) {
        return null;
    }

    String period = String.valueOf(timeSpan.getLength())
            + (timeSpan.getUnits() == Units.Minutes ? "MIN" : "DAY"); //$NON-NLS-1$ //$NON-NLS-2$

    List<OHLC> list = new ArrayList<OHLC>();

    try {
        HttpMethod method = new GetMethod("http://" + host + "/scripts/cligipsw.dll"); //$NON-NLS-1$ //$NON-NLS-2$
        method.setQueryString(new NameValuePair[] { new NameValuePair("app", "tic_d"), //$NON-NLS-1$ //$NON-NLS-2$
                new NameValuePair("action", "dwnld4push"), //$NON-NLS-1$ //$NON-NLS-2$
                new NameValuePair("cod", code), //$NON-NLS-1$
                new NameValuePair("codneb", isin), //$NON-NLS-1$
                new NameValuePair("req_type", "GRAF_DS"), //$NON-NLS-1$ //$NON-NLS-2$
                new NameValuePair("ascii", "1"), //$NON-NLS-1$ //$NON-NLS-2$
                new NameValuePair("form_id", ""), //$NON-NLS-1$ //$NON-NLS-2$
                new NameValuePair("period", period), //$NON-NLS-1$
                new NameValuePair("From", new SimpleDateFormat("yyyyMMdd000000").format(from)), //$NON-NLS-1$ //$NON-NLS-2$
                new NameValuePair("To", new SimpleDateFormat("yyyyMMdd000000").format(to)), //$NON-NLS-1$ //$NON-NLS-2$
        });
        method.setFollowRedirects(true);

        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        client.executeMethod(method);

        BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));

        String inputLine = in.readLine();
        if (inputLine.startsWith("@")) { //$NON-NLS-1$
            while ((inputLine = in.readLine()) != null) {
                if (inputLine.startsWith("@") || inputLine.length() == 0) { //$NON-NLS-1$
                    continue;
                }

                try {
                    String[] item = inputLine.split("\\|"); //$NON-NLS-1$
                    OHLC bar = new OHLC(df.parse(item[0]), nf.parse(item[1]).doubleValue(),
                            nf.parse(item[2]).doubleValue(), nf.parse(item[3]).doubleValue(),
                            nf.parse(item[4]).doubleValue(), nf.parse(item[5]).longValue());
                    list.add(bar);
                } catch (Exception e) {
                    Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0,
                            "Error parsing data: " + inputLine, e); //$NON-NLS-1$
                    Activator.getDefault().getLog().log(status);
                }
            }
        } else {
            Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0,
                    NLS.bind("Unexpected response from {0}: {1}", new Object[] { //$NON-NLS-1$
                            method.getURI().toString(), inputLine }),
                    null);
            Activator.getDefault().getLog().log(status);
        }

        in.close();

    } catch (Exception e) {
        Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error reading data", e); //$NON-NLS-1$
        Activator.getDefault().getLog().log(status);
    }

    return list.toArray(new IOHLC[list.size()]);
}

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 ww w .  j  a v a2s .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 {/*  w w  w .j a  va2s . co m*/
            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  w w  .j  a va2 s . c o 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;/* w  w w  .  j a va  2 s.  c o  m*/
    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.kdb.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  .  jav a 2 s .  c  o  m*/
    int firstYear = c.get(Calendar.YEAR);
    c.setTime(to);
    int lastYear = c.get(Calendar.YEAR);
    firstYear = lastYear - 2;

    HttpClient client = new HttpClient();
    for (int ys = lastYear; ys > firstYear; ys--) {
        try {
            HttpMethod method = Util.get1YearHistoryFeedMethod(identifier, ys);
            Util.setupProxy(client, method.getURI().getHost());
            System.out.println(method.getURI());
            client.getHttpConnectionManager().closeIdleConnections(100);
            client.executeMethod(method);

            BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
            readDailyBackfillStream(list, in);
            in.close();
            method.releaseConnection();
            Thread.sleep(3000);

        } catch (Exception e) {
            Status status = new Status(IStatus.ERROR, KdbActivator.PLUGIN_ID, 0, "Error reading data", e);
            KdbActivator.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();
        }
    }

    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }

    return list.toArray(new IOHLC[list.size()]);
}

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);/*w ww  .  j  ava 2s  .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();
    method.releaseConnection();

    return list.toArray(new IOHLC[list.size()]);
}