How to use GroovyService class of org.cerberus.service.groovy.impl package

Best Cerberus-source code snippet using org.cerberus.service.groovy.impl.GroovyService

Source:GroovyService.java Github

copy

Full Screen

...25import java.util.concurrent.Executors;26import java.util.concurrent.Future;27import javax.annotation.PostConstruct;28import javax.annotation.PreDestroy;29import org.cerberus.service.groovy.IGroovyService;30import org.codehaus.groovy.control.CompilerConfiguration;31import org.kohsuke.groovy.sandbox.SandboxTransformer;32import org.springframework.stereotype.Service;33/**34 * {@link IGroovyService} default implementation35 *36 * @author Aurelien Bourdon37 */38@Service39public class GroovyService implements IGroovyService {40 /**41 * Groovy specific compilation customizer in order to avoid code injection42 */43 private static final CompilerConfiguration GROOVY_COMPILER_CONFIGURATION = new CompilerConfiguration().addCompilationCustomizers(new SandboxTransformer());44 /**45 * Each Groovy execution is ran inside a dedicated {@link Thread},46 * especially to register our Groovy interceptor47 */48 private ExecutorService executorService;49 @PostConstruct50 private void init() {51 executorService = Executors.newCachedThreadPool();52 }53 @PreDestroy54 private void shutdown() {55 if (executorService != null && !executorService.isShutdown()) {56 executorService.shutdownNow();57 }58 }59 @Override60 public String eval(final String script) throws IGroovyServiceException {61 try {62 Future<String> expression = executorService.submit(() -> {63 RestrictiveGroovyInterceptor interceptor = new RestrictiveGroovyInterceptor(64 Collections.<Class<?>>emptySet(),65 Collections.<Class<?>>emptySet(),66 Collections.<RestrictiveGroovyInterceptor.AllowedPrefix>emptyList()67 );68 try {69 interceptor.register();70 GroovyShell shell = new GroovyShell(GROOVY_COMPILER_CONFIGURATION);71 return shell.evaluate(script).toString();72 } finally {73 interceptor.unregister();74 }75 });76 String eval = expression.get();77 if (eval == null) {78 throw new IGroovyServiceException("Groovy evaluation returns null result");79 }80 return eval;81 } catch (Exception e) {82 throw new IGroovyServiceException(e);83 }84 }85}...

Full Screen

Full Screen

GroovyService

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.groovy.impl.GroovyService2import org.cerberus.service.groovy.impl.GroovyService3import org.cerberus.service.groovy.impl.GroovyService4import org.cerberus.service.groovy.impl.GroovyService5import org.cerberus.service.groovy.impl.GroovyService6import org.cerberus.service.groovy.impl.GroovyService7import org.cerberus.service.groovy.impl.GroovyService8import org.cerberus.service.groovy.impl.GroovyService9import org.cerberus.service.groovy.impl.GroovyService10import org.cerberus.service.groovy.impl.GroovyService11import org.cerberus.service.groovy.impl.GroovyService12import org.cerberus.service.groovy.impl.GroovyService13import org.cerberus.service.groovy.impl.GroovyService14import org.cerberus.service.groovy.impl.GroovyService

Full Screen

Full Screen

GroovyService

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.groovy.impl.GroovyService2import org.cerberus.service.groovy.impl.*3import org.cerberus.service.groovy.impl.GroovyService4import org.cerberus.service.groovy.impl.*5def groovyService = new GroovyService()6import org.cerberus.service.groovy.impl.*7GroovyService groovyService = new GroovyService();

Full Screen

Full Screen

GroovyService

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.groovy.impl.GroovyService;2import org.cerberus.service.groovy.impl.GroovyServiceFactory;3GroovyService groovyService = GroovyServiceFactory.createGroovyService();4groovyService.executeScript("return 1+1");5groovyService.executeScript("return param1+param2", ["param1":1, "param2":2]);6groovyService.executeScript("return param1+param2", ["param1":1, "param2":2], ["import java.util.Date"]);7groovyService.executeScript("return param1+param2", ["param1":1, "param2":2], ["import java.util.Date"]);8groovyService.executeScript("return param1+param2", ["param1":1, "param2":2], ["import java.util.Date"], ["binding1":"value1", "binding2":"value2"]);9groovyService.executeScript("return param1+param2", ["param1":1, "param2":2], ["import java.util.Date"], ["binding1":"value1", "binding2":"value2"], Thread.currentThread().getContextClassLoader());10groovyService.executeScript("return param1+param2", ["param1":1, "param2":2], ["import java.util.Date"], ["binding1":"value1", "binding2":"value2"], Thread.currentThread().getContextClassLoader(), System.getSecurityManager());11groovyService.executeScript("return param1+param2", ["param1":1, "param2":2], ["import java.util.Date"], ["binding1":"value1", "binding2":"value2"], Thread.currentThread().getContextClassLoader(), System.getSecurityManager(), GroovyService.class);

Full Screen

Full Screen

GroovyService

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.groovy.impl.GroovyService2def groovyService = new GroovyService()3def result = groovyService.executeGroovyFromScriptName("test")4public Object executeGroovyFromScriptName(String scriptName) {5 Object result = null;6 try {7 Script script = scriptService.findScriptByKey(scriptName);8 result = executeGroovyScript(script);9 } catch (Exception ex) {10 LOG.error(ex.toString(), ex);11 }12 return result;13 }14public Object executeGroovyScript(Script script) {15 Object result = null;16 try {17 String scriptContent = script.getScript();18 GroovyShell shell = new GroovyShell();19 result = shell.evaluate(scriptContent);20 } catch (Exception ex) {21 LOG.error(ex.toString(), ex);22 }23 return result;24 }25public interface ScriptService {26 public Script findScriptByKey(String script);27 public void updateScript(Script script);28 public void createScript(Script script);29 public void deleteScript(Script script);30 public List<Script> findAllScript();31 public List<Script> findScriptByCriteria(int start, int amount, String column, String dir, String searchTerm, String individualSearch);32}33public class Script {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in GroovyService

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful