Example usage for org.apache.commons.httpclient.methods GetMethod setQueryString

List of usage examples for org.apache.commons.httpclient.methods GetMethod setQueryString

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods GetMethod setQueryString.

Prototype

public void setQueryString(String queryString) 

Source Link

Usage

From source file:org.eclipsetrader.kdb.internal.core.Util.java

/**
 * Builds the http method for live prices snapshot download.
 *
 * @return the method.//from  w w  w  .  j  a  v  a  2s .  com
 */
public static HttpMethod getSnapshotFeedMethod(String[] symbols) {
    GetMethod method = new GetMethod("http://" + snapshotFeedHost + "/download/javasoft.beans");
    StringBuffer s = new StringBuffer();
    for (int i = 0; i < symbols.length; i++) {
        if (i != 0) {
            s.append(" "); //$NON-NLS-1$
        }
        s.append(symbols[i]);
    }
    method.setQueryString(new NameValuePair[] { new NameValuePair("symbols", s.toString()),
            new NameValuePair("format", "sl1d1t1c1ohgvbapb6a5"), });
    return method;
}

From source file:org.eclipsetrader.yahoo.internal.core.Util.java

/**
 * Builds the http method for streaming prices download.
 *
 * @return the method./*from  w ww.  j ava 2s  .  co  m*/
 */
public static HttpMethod getStreamingFeedMethod(String[] symbols) {
    GetMethod method = new GetMethod("http://" + streamingFeedHost + "/streamer/1.0");

    StringBuffer s = new StringBuffer();
    for (int i = 0; i < symbols.length; i++) {
        if (i != 0) {
            s.append(","); //$NON-NLS-1$
        }
        s.append(symbols[i]);
    }

    method.setQueryString(new NameValuePair[] { new NameValuePair("s", s.toString()),
            new NameValuePair("k", "a00,a50,b00,b60,g00,h00,j10,l10,t10,v00"),
            new NameValuePair("j", "c10,l10,p20,t10"), new NameValuePair("r", "0"),
            new NameValuePair("marketid", "us_market"), new NameValuePair("callback", "parent.yfs_u1f"),
            new NameValuePair("mktmcb", "parent.yfs_mktmcb"),
            new NameValuePair("gencallback", "parent.yfs_gencb"), });
    method.setFollowRedirects(true);

    return method;
}

From source file:org.eclipsetrader.yahoo.internal.core.Util.java

/**
 * Builds the http method for historycal prices download.
 *
 * @return the method./*from  www. j a  va 2 s. c  om*/
 */
public static HttpMethod getHistoryFeedMethod(IFeedIdentifier identifier, Date from, Date to)
        throws URIException {
    String symbol = getSymbol(identifier);

    Calendar fromDate = Calendar.getInstance();
    fromDate.setTime(from);

    Calendar toDate = Calendar.getInstance();
    toDate.setTime(to);

    String prefix = "/instrument/1.0/";
    String suffix = "/chartdata;type=quote";
    URI uri = new URI("http", "chartapi.finance.yahoo.com", prefix + symbol.toLowerCase() + suffix, "");

    GetMethod method = new GetMethod();
    method.setURI(uri);
    method.setQueryString(new NameValuePair[] { new NameValuePair("s", symbol),
            new NameValuePair("d", String.valueOf(toDate.get(Calendar.MONTH))),
            new NameValuePair("e", String.valueOf(toDate.get(Calendar.DAY_OF_MONTH))),
            new NameValuePair("f", String.valueOf(toDate.get(Calendar.YEAR))), new NameValuePair("g", "d"),
            new NameValuePair("a", String.valueOf(fromDate.get(Calendar.MONTH))),
            new NameValuePair("b", String.valueOf(fromDate.get(Calendar.DAY_OF_MONTH))),
            new NameValuePair("c", String.valueOf(fromDate.get(Calendar.YEAR))),
            new NameValuePair("ignore", ".csv"), });
    method.setFollowRedirects(true);
    try {
        System.out.println(method.getURI().toString());
    } catch (URIException e) {
        e.printStackTrace();
    }

    return method;
}

From source file:org.eclipsetrader.yahoo.internal.core.Util.java

public static HttpMethod getDividendsHistoryMethod(IFeedIdentifier identifier, Date from, Date to) {
    String symbol = getSymbol(identifier);

    Calendar fromDate = Calendar.getInstance();
    fromDate.setTime(from);//from w  ww.  j  ava 2  s  . co  m

    Calendar toDate = Calendar.getInstance();
    toDate.setTime(to);

    GetMethod method = new GetMethod("http://" + historyFeedHost + "/table.csv");
    method.setQueryString(new NameValuePair[] { new NameValuePair("s", symbol),
            new NameValuePair("d", String.valueOf(toDate.get(Calendar.MONTH))),
            new NameValuePair("e", String.valueOf(toDate.get(Calendar.DAY_OF_MONTH))),
            new NameValuePair("f", String.valueOf(toDate.get(Calendar.YEAR))), new NameValuePair("g", "v"),
            new NameValuePair("a", String.valueOf(fromDate.get(Calendar.MONTH))),
            new NameValuePair("b", String.valueOf(fromDate.get(Calendar.DAY_OF_MONTH))),
            new NameValuePair("c", String.valueOf(fromDate.get(Calendar.YEAR))),
            new NameValuePair("ignore", ".csv"), });
    method.setFollowRedirects(true);

    return method;
}

From source file:org.eclipsetrader.yahoojapan.internal.core.Util.java

/**
 * Builds the http method for live prices snapshot download.
 *
 * @return the method.//from  w  w  w.  ja v  a2s  . co m
 */
public static HttpMethod getSnapshotFeedMethod(String[] symbols, int page) {
    GetMethod method = new GetMethod("http://" + snapshotFeedHost + "/search/");
    StringBuffer s = new StringBuffer();
    for (int i = 0; i < symbols.length; i++) {
        if (i != 0) {
            s.append(" "); //$NON-NLS-1$
        }
        s.append(symbols[i]);
    }
    method.setQueryString(
            new NameValuePair[] { new NameValuePair("query", s.toString()), new NameValuePair("ei", "UTF-8"),
                    new NameValuePair("view", "l2"), new NameValuePair("p", String.valueOf(page)), });
    return method;
}

From source file:org.eclipsetrader.yahoojapan.internal.core.Util.java

/**
 * Builds the http method for historycal prices download.
 *
 * @return the method.//ww  w .  ja v  a  2s .c  o  m
 */
public static HttpMethod getHistoryFeedMethod(IFeedIdentifier identifier, Date from, Date to)
        throws URIException {
    String symbol = getSymbol(identifier);

    Calendar fromDate = Calendar.getInstance();
    fromDate.setTime(from);

    Calendar toDate = Calendar.getInstance();
    toDate.setTime(to);

    String prefix = "/history/";
    String suffix = "";
    URI uri = new URI("http", "info.finance.yahoo.co.jp", prefix + suffix, "");

    GetMethod method = new GetMethod();
    method.setURI(uri);
    method.setQueryString(new NameValuePair[] { new NameValuePair("code", symbol),
            new NameValuePair("sy", String.valueOf(fromDate.get(Calendar.YEAR))),
            new NameValuePair("sm", String.valueOf(fromDate.get(Calendar.MONTH) + 1)),
            new NameValuePair("sd", String.valueOf(fromDate.get(Calendar.DAY_OF_MONTH))),
            new NameValuePair("ey", String.valueOf(toDate.get(Calendar.YEAR))),
            new NameValuePair("em", String.valueOf(toDate.get(Calendar.MONTH) + 1)),
            new NameValuePair("ed", String.valueOf(toDate.get(Calendar.DAY_OF_MONTH))),
            new NameValuePair("tm", "d"),
            //                new NameValuePair("p", "1"),
    });
    method.setFollowRedirects(true);
    try {
        System.out.println(method.getURI().toString());
    } catch (URIException e) {
        e.printStackTrace();
    }

    return method;
}

From source file:org.eclipsetrader.yahoojapan.internal.core.Util.java

public static HttpMethod get1YearHistoryFeedMethod(IFeedIdentifier identifier, int year, int page)
        throws URIException {
    String symbol = getSymbol(identifier);

    String prefix = "/history/";
    String suffix = "";
    URI uri = new URI("http", "info.finance.yahoo.co.jp", prefix + suffix, "");

    GetMethod method = new GetMethod();
    method.setURI(uri);// w  w w .java2  s .com
    method.setQueryString(new NameValuePair[] { new NameValuePair("code", symbol),
            new NameValuePair("sy", String.valueOf(year)), new NameValuePair("sm", "1"),
            new NameValuePair("sd", "1"), new NameValuePair("ey", String.valueOf(year)),
            new NameValuePair("em", "12"), new NameValuePair("ed", "31"), new NameValuePair("tm", "d"),
            new NameValuePair("p", String.valueOf(page)), });
    method.setFollowRedirects(true);

    return method;
}

From source file:org.eclipsetrader.yahoojapan.internal.core.Util.java

public static HttpMethod getDividendsHistoryMethod(IFeedIdentifier identifier, Date from, Date to, int page) {
    String symbol = getSymbol(identifier);

    Calendar fromDate = Calendar.getInstance();
    fromDate.setTime(from);/*from  w  ww .  j  ava  2  s . c  om*/

    Calendar toDate = Calendar.getInstance();
    toDate.setTime(to);

    GetMethod method = new GetMethod("http://" + historyFeedHost + "/history/");
    method.setQueryString(new NameValuePair[] { new NameValuePair("code", symbol),
            new NameValuePair("sy", String.valueOf(toDate.get(Calendar.YEAR))),
            new NameValuePair("sm", String.valueOf(toDate.get(Calendar.MONTH) + 1)),
            new NameValuePair("sd", String.valueOf(toDate.get(Calendar.DAY_OF_MONTH))),
            new NameValuePair("ey", String.valueOf(fromDate.get(Calendar.YEAR))),
            new NameValuePair("em", String.valueOf(fromDate.get(Calendar.MONTH) + 1)),
            new NameValuePair("ed", String.valueOf(fromDate.get(Calendar.DAY_OF_MONTH))),
            new NameValuePair("tm", "d"), new NameValuePair("p", String.valueOf(page)), });
    method.setFollowRedirects(true);

    return method;
}

From source file:org.esgf.legacydatacart.LegacyOldFileTemplateController.java

private static String querySolrForFiles(String queryString, String dataset_id) {

    String marker = "\"response\":";

    String responseBody = null;/* www  . j  a va  2 s . co m*/

    // create an http client
    HttpClient client = new HttpClient();

    //attact the dataset id to the query string
    GetMethod method = new GetMethod(searchAPIURL);

    //add the dataset to the query string
    queryString += "&dataset_id=" + dataset_id;

    method.setQueryString(queryString);

    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    try {
        // execute the method
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + method.getStatusLine());

        }

        // read the response
        responseBody = method.getResponseBodyAsString();
    } catch (HTTPException e) {
        LOG.error("Fatal protocol violation");
        e.printStackTrace();
    } catch (IOException e) {
        LOG.error("Fatal transport error");
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }

    //just get the important part of the response (i.e. leave off the header and the facet info)
    int start = responseBody.lastIndexOf(marker) + marker.length();
    int end = responseBody.length();
    String responseString = responseBody.substring(start, end);

    return responseString;
}

From source file:org.esgf.legacydatacart.LegacyOldFileTemplateController.java

/**
 * //from  w  ww .  ja v a2  s  .  c o m
 * @param queryString
 * @param dataset_id
 * @return
 */
private static String getResponseBodyUsingSearchAPI(String queryString, String dataset_id) {

    String responseBody = null;
    System.out.println("In getResponseBodyUsingSearchAPI");
    System.out.println("\tDatasetId: " + dataset_id + "\n\tqueryString: " + queryString);

    // create an http client
    HttpClient client = new HttpClient();

    //attact the dataset id to the query string
    GetMethod method = null;

    method = new GetMethod(searchAPIURL);

    //add distributed search to the query string
    //queryString += "&distrib=false";

    //add the dataset to the query string
    queryString += "&dataset_id=" + dataset_id;//replica=false";//"&dataset_id=" + "a";//dataset_id;

    //take this out
    queryString = "format=application%2Fsolr%2Bjson&type=File&shards=localhost:8983/solr&variable=hus&dataset_id=obs4MIPs.NASA-JPL.AIRS.mon.v1:esg-datanode.jpl.nasa.gov";

    System.out.println("\nResponse Body QueryString: " + queryString + "\n");

    method.setQueryString(queryString);

    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    try {
        // execute the method
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + method.getStatusLine());

        }

        // read the response
        responseBody = method.getResponseBodyAsString();
    } catch (HTTPException e) {
        LOG.error("Fatal protocol violation");
        e.printStackTrace();
    } catch (IOException e) {
        LOG.error("Fatal transport error");
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }

    //System.out.println("-----RESPONSEBODY-----");
    //System.out.println(responseBody.substring(startCharIndex, endCharIndex));
    //System.out.println("-----END RESPONSEBODY-----");

    return responseBody;
}