List of usage examples for org.apache.http.client.methods HttpPost toString
public String toString()
From source file:metadata_crawler.Metadata.java
public Dataset packageSearchSingle(String datasetid, Connection conn) { try {/*w w w . j a v a 2 s . c om*/ Dataset ds = new Dataset(); HttpPost post = new HttpPost(DATAHUBSINGLEURL); post.setHeader("X-CKAN-API-Key", "bf317334-3107-4a25-9773-b5961ef3500b"); StringEntity input = new StringEntity("{\"id\":\"" + datasetid + "\"}"); input.setContentType("application/json"); post.setEntity(input); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(post); String responsestr = getResponseText(response); System.out.println(responsestr); JSONObject jsondataset = new JSONObject(responsestr).getJSONObject("result"); ds.dataset_id_datahub = jsondataset.getString("id"); ds.name = jsondataset.getString("name"); ds.notes = jsondataset.getString("notes"); ds.url = jsondataset.getString("url"); ds.maintainer = jsondataset.getString("maintainer"); ds.maintainer_email = jsondataset.getString("maintainer_email"); ds.author = jsondataset.getString("author"); ds.author_email = jsondataset.getString("author_email"); ds.licence_id = jsondataset.getString("license_id"); ds.revision_id = jsondataset.getString("revision_id"); ds.state = jsondataset.getString("state"); ds.title = jsondataset.getString("title"); ds.type = jsondataset.getString("type"); ds.version = jsondataset.getString("version"); loadDatasetInformation(ds, ds.name); //log the success of the operation CrawlerLogs.writeCrawlLog(Properties.crawl_log_operations.success.toString(), "packageSearchSingle", "successfully loaded metadata for " + datasetid + "\n " + post.toString(), crawl_log_global, conn); return ds; } catch (Exception e) { CrawlerLogs.writeCrawlLog(Properties.crawl_log_operations.exception.toString(), "packageSearchSingle", "exception loading metadata for " + datasetid + "\n " + e.getMessage(), crawl_log_global, conn); } return null; }
From source file:metadata_crawler.Metadata.java
public List<Dataset> loadGroupDatasetInformation(String groupid, Connection conn) { try {/*from w w w. j a v a 2s. com*/ List<Dataset> lst = new ArrayList<Dataset>(); HttpPost post = new HttpPost(DATAHUBURL); post.setHeader("X-CKAN-API-Key", "bf317334-3107-4a25-9773-b5961ef3500b"); StringEntity input = new StringEntity("{\"id\":\"" + groupid + "\"}"); input.setContentType("application/json"); post.setEntity(input); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(post); String responsestr = getResponseText(response); JSONObject jsobj = new JSONObject(responsestr).getJSONObject("result"); JSONArray jsarr = jsobj.getJSONArray("packages"); System.out.println(jsarr.toString()); for (int i = 0; i < jsarr.length(); i++) { JSONObject jsondataset = jsarr.getJSONObject(i); System.out.println(jsondataset.toString()); Dataset ds = new Dataset(); ds.dataset_id_datahub = jsondataset.getString("id"); ds.name = jsondataset.getString("name"); ds.notes = jsondataset.getString("notes"); ds.maintainer = jsondataset.getString("maintainer"); ds.maintainer_email = jsondataset.getString("maintainer_email"); ds.author = jsondataset.getString("author"); ds.author_email = jsondataset.getString("author_email"); ds.capacity = jsondataset.getString("capacity"); ds.licence_id = jsondataset.getString("license_id"); ds.revision_id = jsondataset.getString("revision_id"); ds.state = jsondataset.getString("state"); ds.title = jsondataset.getString("title"); ds.type = jsondataset.getString("type"); loadDatasetInformation(ds, ds.name); lst.add(ds); } //log the success of the operation CrawlerLogs.writeCrawlLog(Properties.crawl_log_operations.success.toString(), "loadGroupDatasetInformation", "successfully loaded metadata for " + groupid + "\n " + post.toString(), crawl_log_global, conn); return lst; } catch (Exception e) { CrawlerLogs.writeCrawlLog(Properties.crawl_log_operations.exception.toString(), "loadGroupDatasetInformation", "exception loading metadata for " + groupid + "\n " + e.getMessage(), crawl_log_global, conn); } return null; }
From source file:org.jenkinsci.plugins.skytap.ConnectToVPNTunnelStep.java
private String attachVPNToConfiguration(String confId, String networkId, String vpnId) { // build url// w ww.j ava 2 s. com String requestUrl = this.buildRequestURL(confId, networkId); // create request HttpPost hp = SkytapUtils.buildHttpPostRequest(requestUrl, this.authCredentials); // add content to request - vpn identifier BasicHttpEntity he = new BasicHttpEntity(); he.setContentEncoding("gzip"); he.setContentType("application/json"); // json string for vpn id String jsonString = "{\"id\":\"" + vpnId + "\"}"; InputStream stream; try { stream = new ByteArrayInputStream(jsonString.getBytes("UTF-8")); Integer len = jsonString.getBytes("UTF-8").length; long llen = len.longValue(); he.setContent(stream); he.setContentLength(llen); } catch (UnsupportedEncodingException e) { JenkinsLogger.error("Error encoding json string for vpn id: " + e.getMessage()); } hp.setEntity(he); JenkinsLogger.log("HTTP POST request: " + hp.toString()); // execute request String httpRespBody = ""; try { httpRespBody = SkytapUtils.executeHttpRequest(hp); } catch (SkytapException e) { JenkinsLogger.error("Skytap Exception: " + e.getMessage()); } // return response return httpRespBody; }
From source file:org.jenkinsci.plugins.skytap.SkytapUtils.java
/** * This method packages an http post request object, given a url and the * encoded Skytap authorization token./*w w w. j av a 2 s . com*/ * * @param requestUrl * @param AuthToken * @return */ public static HttpPost buildHttpPostRequest(String requestUrl, String AuthToken) { HttpPost hp = new HttpPost(requestUrl); String authHeaderValue = "Basic " + AuthToken; hp.addHeader("Authorization", authHeaderValue); hp.addHeader("Accept", "application/json"); hp.addHeader("Content-Type", "application/json"); JenkinsLogger.log("HTTP POST Request: " + hp.toString()); return hp; }