/** * Sends an HTTP request. This method uses authentication for all requests * except GET. * * @param method an HTTP method * @return HTTP status code * @throws IOException if an error occurred during the HTTP request */ public int executeMethod(HttpMethodBase method) throws IOException { boolean auth = !(method instanceof GetMethod); return executeMethod(method, auth); }
/** * <p>Get the requested URL and return the GetMethod Object afterwards. * To access more info use its method: eg. GetMethod.getStatusCode() and * GetMethod.getResponseBodyAsString()</p> * * <p>Internally wraps a Fascinator BasicHttpClient Object, so any configured * proxy details from the system will be used automatically.</p> * * @param url The URL to retrieve * @return GetMethod The instantiated and executed GetMethod Object. * @throws IOException If any network errors occur accessing the URL. Note * this does not cover HTTP errors returned from the web server; use the * returned Object to check for these. */ private GetMethod getUrl(String url) throws IOException { BasicHttpClient client = new BasicHttpClient(url); GetMethod get = new GetMethod(url); client.executeMethod(get); return get; }
private JsonSimple getMintData(DateFormat solrDateFormat) throws IOException { String url = systemConfig.getString("http://localhost:9001/mint", "proxy-urls", "Published_Records_By_Type") + "&dateFrom=" + solrDateFormat.format(fromDate) + "&dateTo=" + solrDateFormat.format(toDate); BasicHttpClient client = new BasicHttpClient(url); GetMethod get = new GetMethod(url); client.executeMethod(get); JsonSimple mintResult = new JsonSimple(get.getResponseBodyAsString()); return mintResult; }
public InputStream get(String query, Map<String, Set<String>> extras, boolean escape) throws IOException { if (query == null) { query = "*:*"; } else if (!QUERY_ALL.equals(query) && escape) { query = query.replaceAll(":", "\\\\:"); } String selectUrl = baseUrl + "/select"; NameValuePair[] postData = getPostData(query, extras); log.debug("URL:{}, POSTDATA:{}", selectUrl, postData); PostMethod method = new PostMethod(selectUrl); method.addRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); method.setRequestBody(postData); int status = client.executeMethod(method, true); if (status == HttpStatus.SC_OK) { return method.getResponseBodyAsStream(); } return null; }
long retryAfter = DEFAULT_RETRY_AFTER; do { status = client.executeMethod(getMethod);
private void getMintStats(Stat stat, String query, StatisticalReport report) throws IOException { StringBuilder param = new StringBuilder(); param.append("dateFrom="); param.append(report.getStrStartDate()); param.append("&dateTo="); param.append(report.getStrEndDate()); param.append("&published="); param.append(report.getStrPublished()); String targetUrl = stat.getUrl() + param.toString(); log.debug("Using url"+targetUrl); BasicHttpClient client = new BasicHttpClient(targetUrl); GetMethod get = new GetMethod(targetUrl); client.executeMethod(get); JsonSimple mintResult = new JsonSimple(get.getResponseBodyAsString()); for (String fldKey : stat.getFields()) { StatResult result = stat.getResults().get(fldKey); if (fldKey.indexOf(":") >= 0) { JSONArray groupList = mintResult.getArray(fldKey); for (Object entry : groupList) { String groupName = (String) entry; int counts = mintResult.getInteger(new Integer("0"), fldKey+"counts", groupName).intValue(); result.getGroupMap().put(groupName, new Integer(counts)); result.setCounts(result.getCounts()+counts); } } else { int counts = mintResult.getInteger(new Integer(-1), fldKey); result.setCounts(counts); } } }