@Override public String handle(RunnerVariablesProvider variablesProvider, Config config, RestResponse response, Object expressionContext, String expression) { return response.getBody(); }
@Override public String handle(RunnerVariablesProvider variablesProvider, Config config, RestResponse response, Object expressionContext, String expression) { @SuppressWarnings("unchecked") Map<String, String> namespaceContext = (Map<String, String>) expressionContext; NodeList list = Tools.extractXPath(namespaceContext, expression, response.getBody()); String val = Tools.xPathResultToXmlString(list); int pos = val.indexOf("?>"); if (pos >= 0) { val = val.substring(pos + 2); } return val; }
@Override public String handle(RunnerVariablesProvider variablesProvider, Config config, RestResponse response, Object expressionContext, String expression) { @SuppressWarnings("unchecked") Map<String, String> namespaceContext = (Map<String, String>) expressionContext; String contentTypeString = response.getContentType(); String charset = response.getCharset(); ContentType contentType = ContentType.parse(contentTypeString); BodyTypeAdapter bodyTypeAdapter = new BodyTypeAdapterFactory(variablesProvider, config) .getBodyTypeAdapter(contentType, charset); String body = bodyTypeAdapter.toXmlString(response.getBody()); if (body == null) { return null; } String val = null; try { NodeList list = Tools.extractXPath(namespaceContext, expression, body); Node item = list.item(0); if (item != null) { val = item.getTextContent(); } } catch (IllegalArgumentException e) { // ignore - may be that it's evaluating to a string val = (String) Tools.extractXPath(namespaceContext, expression, body, XPathConstants.STRING, charset); } if (val != null) { val = val.trim(); } return val; } }
public Object evaluateExpression(RestResponse response, String expression, Map<String, String> imports) { if (expression == null) { return null; } Context context = Context.enter(); final String body = response == null ? null : response.getBody(); removeOptimisationForLargeExpressions(body, expression, context); ScriptableObject scope = context.initStandardObjects(); injectImports(context, scope, imports); injectFitNesseSymbolMap(scope); injectResponse(context, scope, response); Object result = evaluateExpression(context, scope, expression); return result; }
response = cx.newObject(scope, "JsResponse", arg); scope.put(RESPONSE_OBJ_NAME, scope, response); putPropertyOnJsObject(response, "body", r.getBody()); putPropertyOnJsObject(response, JSON_OBJ_NAME, null); boolean isJson = isJsonResponse(r); if (isJson) { evaluateExpression(cx, scope, RESPONSE_OBJ_NAME + "." + JSON_OBJ_NAME + "=" + r.getBody());
@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); }