@Override public String handle(RunnerVariablesProvider variablesProvider, Config config, RestResponse response, Object expressionContext, String expression) { List<String> content = new ArrayList<String>(); if (response != null) { for (Header e : response.getHeaders()) { String string = Tools.convertEntryToString(e.getName(), e.getValue(), ":"); content.add(string); } } String value = null; if (content.size() > 0) { Pattern p = Pattern.compile(expression); for (String c : content) { Matcher m = p.matcher(c); if (m.find()) { int cc = m.groupCount(); value = m.group(cc); break; } } } return value; }
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void completeHttpMethodExecution() { String uri = getLastResponse().getResource(); String query = getLastRequest().getQuery(); if (query != null && !"".equals(query.trim())) { uri = uri + "?" + query; } String clientBaseUri = restClient.getBaseUrl(); String u = clientBaseUri + uri; CellWrapper uriCell = row.getCell(1); getFormatter().asLink(uriCell, GLOBALS.substitute(uriCell.body()), u, uri); CellWrapper cellStatusCode = row.getCell(2); if (cellStatusCode == null) { throw new IllegalStateException( "You must specify a status code cell"); } Integer lastStatusCode = getLastResponse().getStatusCode(); process(cellStatusCode, lastStatusCode.toString(), new StatusCodeTypeAdapter()); List<Header> lastHeaders = getLastResponse().getHeaders(); process(row.getCell(3), lastHeaders, new HeadersTypeAdapter()); CellWrapper bodyCell = row.getCell(4); if (bodyCell == null) { throw new IllegalStateException("You must specify a body cell"); } bodyCell.body(GLOBALS.substitute(bodyCell.body())); BodyTypeAdapter bodyTypeAdapter = createBodyTypeAdapter(); process(bodyCell, getLastResponse().getBody(), bodyTypeAdapter); }
putPropertyOnJsObject(response, "statusCode", r.getStatusCode()); putPropertyOnJsObject(response, "transactionId", r.getTransactionId()); for (Header h : r.getHeaders()) { callMethodOnJsObject(response, "addHeader", h.getName(), h.getValue());