org.springframework.scripting.support.ResourceScriptSource Java Examples

The following examples show how to use org.springframework.scripting.support.ResourceScriptSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataRedisDistributedLock.java    From summerframework with Apache License 2.0 6 votes vote down vote up
private void initLuaScript() {
    // lock script
    lockScript = new DefaultRedisScript<Long>();
    lockScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("lock/lock.lua")));
    lockScript.setResultType(Long.class);
    LOGGER.debug("init lock lua script success:{}", lockScript.getScriptAsString());
    // unlock script
    unlockScript = new DefaultRedisScript<Long>();
    unlockScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("lock/unlock.lua")));
    unlockScript.setResultType(Long.class);
    LOGGER.debug("init release lua script success:{}", unlockScript.getScriptAsString());
    // renew script
    renewScript = new DefaultRedisScript<Long>();
    renewScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("lock/renew.lua")));
    renewScript.setResultType(Long.class);
    LOGGER.debug("init renew lua script success:{}", renewScript.getScriptAsString());
}
 
Example #2
Source File: GroovyAspectTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void manualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
	pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
	testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
 
Example #3
Source File: GroovyAspectTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void manualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
	pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
	testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
 
Example #4
Source File: GroovyAspectTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void manualGroovyBeanWithDynamicPointcut() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
	pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
	testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", false);
}
 
Example #5
Source File: GroovyAspectTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void manualGroovyBeanWithStaticPointcut() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
	pointcut.setExpression(String.format("execution(* %s.TestService+.*(..))", ClassUtils.getPackageName(getClass())));
	testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
 
Example #6
Source File: GroovyAspectTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void manualGroovyBeanWithUnconditionalPointcut() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	testAdvice(new DefaultPointcutAdvisor(logAdvice), logAdvice, target, "GroovyServiceImpl");
}
 
Example #7
Source File: RedisConfig.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Bean
@SuppressWarnings("unchecked")
public RedisScript<Long> limitRedisScript() {
    DefaultRedisScript redisScript = new DefaultRedisScript<>();
    redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("scripts/redis/limit.lua")));
    redisScript.setResultType(Long.class);
    return redisScript;
}
 
Example #8
Source File: RateLimterHandler.java    From shield-ratelimter with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    getRedisScript = new DefaultRedisScript<>();
    getRedisScript.setResultType(Long.class);
    getRedisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("rateLimter.lua")));
    LOGGER.info("RateLimterHandler[分布式限流处理器]脚本加载完成");
}
 
Example #9
Source File: RedisLuaRateLimiter.java    From api-boot with Apache License 2.0 5 votes vote down vote up
/**
 * get Redis Script
 *
 * @return RedisScript
 */
RedisScript<List<Long>> getRedisScript() {
    DefaultRedisScript redisScript = new DefaultRedisScript<>();
    redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource(QPS_LUA_PATH)));
    redisScript.setResultType(List.class);
    return redisScript;
}
 
Example #10
Source File: GroovyAspectTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void manualGroovyBeanWithDynamicPointcut() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
	pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
	testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", false);
}
 
Example #11
Source File: GroovyAspectTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void manualGroovyBeanWithStaticPointcut() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
	pointcut.setExpression(String.format("execution(* %s.TestService+.*(..))", ClassUtils.getPackageName(getClass())));
	testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
 
Example #12
Source File: GroovyAspectTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void manualGroovyBeanWithUnconditionalPointcut() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	testAdvice(new DefaultPointcutAdvisor(logAdvice), logAdvice, target, "GroovyServiceImpl");
}
 
Example #13
Source File: GatewayRedisAutoConfiguration.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Bean
@SuppressWarnings("unchecked")
public RedisScript redisRequestRateLimiterScript() {
	DefaultRedisScript redisScript = new DefaultRedisScript<>();
	redisScript.setScriptSource(new ResourceScriptSource(
			new ClassPathResource("META-INF/scripts/request_rate_limiter.lua")));
	redisScript.setResultType(List.class);
	return redisScript;
}
 
Example #14
Source File: commons.java    From SpringBootLearn with Apache License 2.0 5 votes vote down vote up
/**
 * 读取限流脚本
 *
 * @return
 */
@Bean
public DefaultRedisScript<Number> redisluaScript() {
    DefaultRedisScript<Number> redisScript = new DefaultRedisScript<>();
    redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("redisLimit.lua")));
    //返回类型
    redisScript.setResultType(Number.class);
    return redisScript;
}
 
Example #15
Source File: GroovyAspectTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void manualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
	pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
	testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
 
Example #16
Source File: GroovyAspectTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void manualGroovyBeanWithDynamicPointcut() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
	pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
	testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", false);
}
 
Example #17
Source File: GroovyAspectTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void manualGroovyBeanWithStaticPointcut() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
	pointcut.setExpression(String.format("execution(* %s.TestService+.*(..))", ClassUtils.getPackageName(getClass())));
	testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
 
Example #18
Source File: GroovyAspectTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void manualGroovyBeanWithUnconditionalPointcut() throws Exception {
	TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
			new ClassPathResource("GroovyServiceImpl.grv", getClass())));

	testAdvice(new DefaultPointcutAdvisor(logAdvice), logAdvice, target, "GroovyServiceImpl");
}
 
Example #19
Source File: RateLimiterAutoConfiguration.java    From mica with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private RedisScript<List<Long>> redisRateLimiterScript() {
	DefaultRedisScript redisScript = new DefaultRedisScript<>();
	redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("META-INF/scripts/mica_rate_limiter.lua")));
	redisScript.setResultType(List.class);
	return redisScript;
}
 
Example #20
Source File: GroovyTransformProcessorConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Bean
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public MessageProcessor<?> transformer() {
	return new GroovyScriptExecutingMessageProcessor(
			new ResourceScriptSource(properties.getScript()), scriptVariableGenerator);
}
 
Example #21
Source File: BshScriptEvaluatorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void testBshScriptFromFile() {
	ScriptEvaluator evaluator = new BshScriptEvaluator();
	Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.bsh", getClass())));
	assertEquals(6, result);
}
 
Example #22
Source File: GroovyScriptEvaluatorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void testGroovyScriptFromFileUsingJsr223() {
	ScriptEvaluator evaluator = new StandardScriptEvaluator();
	Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.groovy", getClass())));
	assertEquals(6, result);
}
 
Example #23
Source File: GroovyScriptEvaluatorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void testGroovyScriptFromFile() {
	ScriptEvaluator evaluator = new GroovyScriptEvaluator();
	Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.groovy", getClass())));
	assertEquals(6, result);
}
 
Example #24
Source File: GroovyFilterProcessorConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Bean
@Filter(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public MessageProcessor<?> filter() {
	return new GroovyScriptExecutingMessageProcessor(
			new ResourceScriptSource(this.properties.getScript()), this.scriptVariableGenerator);
}
 
Example #25
Source File: BshScriptEvaluatorTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testBshScriptFromFile() {
	ScriptEvaluator evaluator = new BshScriptEvaluator();
	Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.bsh", getClass())));
	assertEquals(6, result);
}
 
Example #26
Source File: GroovyScriptEvaluatorTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testGroovyScriptFromFileUsingJsr223() {
	ScriptEvaluator evaluator = new StandardScriptEvaluator();
	Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.groovy", getClass())));
	assertEquals(6, result);
}
 
Example #27
Source File: GroovyScriptEvaluatorTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testGroovyScriptFromFile() {
	ScriptEvaluator evaluator = new GroovyScriptEvaluator();
	Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.groovy", getClass())));
	assertEquals(6, result);
}
 
Example #28
Source File: BshScriptEvaluatorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testBshScriptFromFile() {
	ScriptEvaluator evaluator = new BshScriptEvaluator();
	Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.bsh", getClass())));
	assertEquals(6, result);
}
 
Example #29
Source File: GroovyScriptEvaluatorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testGroovyScriptFromFileUsingJsr223() {
	ScriptEvaluator evaluator = new StandardScriptEvaluator();
	Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.groovy", getClass())));
	assertEquals(6, result);
}
 
Example #30
Source File: GroovyScriptEvaluatorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testGroovyScriptFromFile() {
	ScriptEvaluator evaluator = new GroovyScriptEvaluator();
	Object result = evaluator.evaluate(new ResourceScriptSource(new ClassPathResource("simple.groovy", getClass())));
	assertEquals(6, result);
}