@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) {
val = (String) Tools.extractXPath(namespaceContext, expression, body, XPathConstants.STRING, charset);
}
if (val != null) {
val = val.trim();
}
return val;
}
}