Class<?> groovyClass = loader.parseClass(TemplateBasedScriptBuilder.fromTemplateResource(scriptTemplateResource)
.withCode(validationScript)
.build());
if (groovyClass == null) {
throw new CitrusRuntimeException("Failed to load groovy validation script resource");
}
GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
((GroovyScriptExecutor) groovyObject).validate(receivedMessage, context);
log.info("Groovy message validation finished successfully: All values OK");
}
} catch (CompilationFailedException e) {
throw new CitrusRuntimeException(e);
} catch (InstantiationException e) {
throw new CitrusRuntimeException(e);
} catch (IllegalAccessException e) {
throw new CitrusRuntimeException(e);
} catch (AssertionError e) {
throw new ValidationException("Groovy script validation failed with assertion error:\n" + e.getMessage(), e);
}
}