/** * this is the primary method that sends a query to the CIPRes REST service. It expects to receive * an XML file, which it returns in Document if the root tag matc hes xmlRootTag */ public Document cipresQuery(HttpClient httpclient, String URL, String xmlRootTag) { if (StringUtil.blank(URL)) return null; try { HttpGet httpget = new HttpGet(URL); httpget.addHeader("cipres-appkey", CIPRESkey); try { HttpResponse response = httpclient.execute(httpget); HttpEntity responseEntity = response.getEntity(); InputStream instream = responseEntity.getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(instream)); String line = ""; StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line + StringUtil.lineEnding()); } Document cipresResponseDoc = loadXMLFile(xmlRootTag, sb.toString()); if (cipresResponseDoc != null && verbose) { ownerModule.logln(sb.toString()); } if (cipresResponseDoc == null) { Document errorDoc = loadXMLFile(sb.toString()); if (errorDoc != null) reportError(errorDoc, "Error in communicating with CIPRes", true); } EntityUtils.consume(response.getEntity()); return cipresResponseDoc; } catch (IOException e) { Debugg.printStackTrace(e); } catch (Exception e) { Debugg.printStackTrace(e); } } catch (Exception e) { Debugg.printStackTrace(e); } return null; }
/*.................................................................................................................*/ public void appendToConfigFileGeneral(StringBuffer config) { if (config != null) { config.append("\ndatafname=" + dataFileName); config.append("\nofprefix=" + ofprefix); if (useConstraintTree == 0) config.append("\nconstraintfile = none"); else config.append("\nconstraintfile = constraintTree"); // important to be user-editable config.append("\nstreefname = random"); config.append("\navailablememory = " + availMemory + " \n"); config.append(" \noutputmostlyuselessfiles = 0"); config.append("\n\nrandseed = " + randseed); // important to be user-editable config.append("\nsearchreps = " + numRuns); config.append("\n"); } }
/** The core method that initiates a job on CIPRes. */ public boolean postJob( HttpClient httpclient, MultipartEntityBuilder builder, MesquiteString jobURL) { if (builder == null) return false; String URL = baseURL + "/job/" + username; HttpPost httppost = new HttpPost(URL); httppost.addHeader("cipres-appkey", CIPRESkey); // some of this from // http://stackoverflow.com/questions/18964288/upload-a-file-through-an-http-form-via-multipartentitybuilder-with-a-progress HttpEntity cipresEntity = builder.build(); httppost.setEntity(cipresEntity); try { HttpResponse response = httpclient.execute(httppost); HttpEntity responseEntity = response.getEntity(); InputStream instream = responseEntity.getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(instream)); StringBuffer sb = new StringBuffer(); String line = ""; while ((line = br.readLine()) != null) { sb.append(line + StringUtil.lineEnding()); } Document cipresResponseDoc = loadXMLFile("jobstatus", sb.toString()); // let's see how it went boolean success = false; if (cipresResponseDoc != null) { processJobSubmissionResponse(cipresResponseDoc, jobURL); if (verbose) ownerModule.logln(sb.toString()); if (jobURL != null) success = StringUtil.notEmpty(jobURL.getValue()); else success = true; } else { cipresResponseDoc = loadXMLFile(sb.toString()); reportError(cipresResponseDoc, "Error with CIPRes run", false); } EntityUtils.consume(response.getEntity()); return success; } catch (IOException e) { Debugg.printStackTrace(e); } return false; }
/*.................................................................................................................*/ public String preparePreferencesForXML() { StringBuffer buffer = new StringBuffer(200); StringUtil.appendXMLTag(buffer, 2, "availMemory", availMemory); buffer.append(super.preparePreferencesForXML()); return buffer.toString(); }
/*.................................................................................................................*/ void addArgument(MultipartEntityBuilder builder, StringBuffer sb, String param, String value) { if (builder != null) builder.addTextBody(param, value); if (sb != null) sb.append("\n " + param + " = " + value); }