use of io.gravitee.gateway.services.healthcheck.eval.EvaluationException in project gravitee-gateway by gravitee-io.
the class AssertionEvaluation method validate.
@Override
public boolean validate() throws EvaluationException {
try {
final ExpressionParser parser = new SpelExpressionParser();
final Expression expr = parser.parseExpression(assertion);
final StandardEvaluationContext context = new StandardEvaluationContext();
context.registerFunction("jsonPath", BeanUtils.resolveSignature("evaluate", JsonPathFunction.class));
context.setVariables(variables);
return expr.getValue(context, boolean.class);
} catch (SpelEvaluationException spelex) {
throw new EvaluationException("Assertion can not be verified : " + assertion, spelex);
}
}
use of io.gravitee.gateway.services.healthcheck.eval.EvaluationException in project gravitee-gateway by gravitee-io.
the class HttpEndpointRuleHandler method validateAssertions.
private EndpointStatus.StepBuilder validateAssertions(final io.gravitee.definition.model.services.healthcheck.Step step, final EvaluableHttpResponse response) {
EndpointStatus.StepBuilder stepBuilder = EndpointStatus.forStep(step.getName());
// Run assertions
if (step.getResponse().getAssertions() != null) {
Iterator<String> assertionIterator = step.getResponse().getAssertions().iterator();
boolean success = true;
while (success && assertionIterator.hasNext()) {
try {
// TODO: assertion must be compiled only one time to preserve CPU
AssertionEvaluation evaluation = new AssertionEvaluation(assertionIterator.next());
evaluation.setVariable("response", response);
// Run validation
success = evaluation.validate();
if (success) {
stepBuilder.success();
} else {
stepBuilder.fail("Assertion not validated: " + evaluation.getAssertion());
}
} catch (EvaluationException eex) {
success = false;
stepBuilder.fail(eex.getMessage());
}
}
}
return stepBuilder;
}
Aggregations