/** * Processes an "update" (add, commit or optimize) and * returns the response as a String. * * @param xml The XML of the update * @return The XML response to the update */ @Override public String update(String xml) { try { return query("/update?stream.body=" + URLEncoder.encode(xml, "UTF-8")); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Validates an XML "query" response against an array of XPath test strings * * @param request the Query to process * @return null if all good, otherwise the first test that fails. * @exception Exception any exception in the response. * @exception java.io.IOException if there is a problem writing the XML */ public String validateQuery(String request, String... tests) throws Exception { String res = query(request); return validateXPath(res, tests); }
public String checkResponseStatus(String xml, String code) throws Exception { try { String response = query(xml); String valid = validateXPath(response, "//int[@name='status']="+code ); return (null == valid) ? null : response; } catch (XPathExpressionException e) { throw new RuntimeException("?!? static xpath has bug?", e); } }
/** * Makes a query request and returns the JSON string response * * @param request a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_" */ public static String JQ(String request) throws Exception { int queryStartPos = request.indexOf('?'); String query; String path; if (-1 == queryStartPos) { query = ""; path = request; } else { query = request.substring(queryStartPos + 1); path = request.substring(0, queryStartPos); } query = setParam(query, "wt", "json"); request = path + '?' + setParam(query, "indent", "on"); String response; boolean failed=true; try { response = restTestHarness.query(request); failed = false; } finally { if (failed) { log.error("REQUEST FAILED: " + request); } } return response; }
String response = restTestHarness.query(request);
boolean failed = true; try { response = restTestHarness.query(request); failed = false; } finally {