use of com.predic8.membrane.core.interceptor.groovy.GroovyInterceptor in project service-proxy by membrane.
the class GenericJsonParserTest method testMultipleChildElements.
@Test
public void testMultipleChildElements() {
JSONObject spec = new JSONObject(new HashMap<String, Object>() {
{
put("interceptors", Arrays.asList(new HashMap<String, Object>() {
{
put("groovy", new HashMap<String, Object>() {
{
put("src", "println()");
}
});
}
}, new HashMap<String, Object>() {
{
put("target", new HashMap<String, Object>() {
{
put("host", "localhost");
put("port", 8080);
}
});
}
}));
}
});
ServiceProxy sp = GenericJsonParser.parse(ServiceProxy.class, spec);
assertEquals(2, sp.getInterceptors().size());
assertTrue(sp.getInterceptors().get(0) instanceof GroovyInterceptor);
assertEquals("println()", ((GroovyInterceptor) sp.getInterceptors().get(0)).getSrc());
assertTrue(sp.getInterceptors().get(1) instanceof AbstractServiceProxy.Target);
assertEquals("localhost", ((AbstractServiceProxy.Target) sp.getInterceptors().get(1)).getHost());
assertEquals(8080, ((AbstractServiceProxy.Target) sp.getInterceptors().get(1)).getPort());
}
use of com.predic8.membrane.core.interceptor.groovy.GroovyInterceptor in project service-proxy by membrane.
the class GenericJsonParserTest method testChildElements.
@Test
public void testChildElements() {
JSONObject spec = new JSONObject(new HashMap<String, Object>() {
{
put("interceptors", Collections.singletonList(new HashMap<String, Object>() {
{
put("groovy", new HashMap<String, Object>() {
{
put("src", "println()");
}
});
}
}));
}
});
ServiceProxy sp = GenericJsonParser.parse(ServiceProxy.class, spec);
assertFalse(sp.getInterceptors().isEmpty());
assertEquals("println()", ((GroovyInterceptor) sp.getInterceptors().get(0)).getSrc());
}
use of com.predic8.membrane.core.interceptor.groovy.GroovyInterceptor in project service-proxy by membrane.
the class GenericJsonParserTest method testTextContent.
@Test
public void testTextContent() {
String want = "println(\"Hello, World!\")";
JSONObject spec = new JSONObject(new HashMap<String, Object>() {
{
put("src", want);
}
});
GroovyInterceptor gi = GenericJsonParser.parse(GroovyInterceptor.class, spec);
assertEquals(want, gi.getSrc());
}
use of com.predic8.membrane.core.interceptor.groovy.GroovyInterceptor in project service-proxy by membrane.
the class GenericJsonParserTest method testCombined.
@Test
public void testCombined() {
JSONObject spec = new JSONObject(new HashMap<String, Object>() {
{
put("port", 2020);
put("blockRequest", true);
put("path", new HashMap<String, Object>() {
{
put("isRegExp", true);
put("value", "/foo");
}
});
put("interceptors", Arrays.asList(new HashMap<String, Object>() {
{
put("groovy", new HashMap<String, Object>() {
{
put("src", "println()");
}
});
}
}, new HashMap<String, Object>() {
{
put("target", new HashMap<String, Object>() {
{
put("host", "localhost");
put("port", 8080);
}
});
}
}));
}
});
ServiceProxy sp = GenericJsonParser.parse(ServiceProxy.class, spec);
assertEquals(2020, sp.getPort());
assertTrue(sp.isBlockRequest());
assertTrue(sp.getPath().isRegExp());
assertEquals("/foo", sp.getPath().getValue());
assertEquals(2, sp.getInterceptors().size());
assertTrue(sp.getInterceptors().get(0) instanceof GroovyInterceptor);
assertEquals("println()", ((GroovyInterceptor) sp.getInterceptors().get(0)).getSrc());
assertTrue(sp.getInterceptors().get(1) instanceof AbstractServiceProxy.Target);
assertEquals("localhost", ((AbstractServiceProxy.Target) sp.getInterceptors().get(1)).getHost());
assertEquals(8080, ((AbstractServiceProxy.Target) sp.getInterceptors().get(1)).getPort());
}
use of com.predic8.membrane.core.interceptor.groovy.GroovyInterceptor in project service-proxy by membrane.
the class ConcurrentConnectionLimitTest method setup.
@Before
public void setup() throws Exception {
executor = Executors.newFixedThreadPool(concurrency);
router = new HttpRouter();
concurrentLimit = router.getTransport().getConcurrentConnectionLimitPerIp();
ServiceProxy sp = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", port), "", -1);
GroovyInterceptor gi = new GroovyInterceptor();
gi.setSrc("exc.setResponse(Response.ok(\"Response\").build())\nRETURN");
sp.getInterceptors().add(gi);
router.getRuleManager().addProxyAndOpenPortIfNew(sp);
router.init();
}
Aggregations