Search in sources :

Example 51 with ServiceProxy

use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.

the class AccessControlInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    router = new HttpRouter();
    interceptor = new AccessControlInterceptor();
    interceptor.setFile("classpath:/acl/acl.xml");
    Rule rule4000 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 4000), "oio.de", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule4000);
    router.addUserFeatureInterceptor(interceptor);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) Before(org.junit.Before)

Example 52 with ServiceProxy

use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.

the class LimitInterceptorTest method before.

@BeforeClass
public static void before() throws Exception {
    router = new HttpRouter();
    ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3026), "", -1);
    LimitInterceptor wi = new LimitInterceptor();
    wi.setMaxBodyLength(10);
    wi.setFlow(Flow.Set.REQUEST);
    sp2.getInterceptors().add(wi);
    WebServerInterceptor wi2 = new WebServerInterceptor();
    wi2.setDocBase("classpath:");
    wi2.init();
    sp2.getInterceptors().add(wi2);
    router.getRuleManager().addProxyAndOpenPortIfNew(sp2);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) WebServerInterceptor(com.predic8.membrane.core.interceptor.server.WebServerInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 53 with ServiceProxy

use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.

the class SpringReferencesTest method doit.

@Test
public void doit() {
    ServiceProxy p = (ServiceProxy) r.getRules().iterator().next();
    List<Interceptor> is = p.getInterceptors();
    Assert.assertEquals(LogInterceptor.class, is.get(0).getClass());
    Assert.assertEquals(LogInterceptor.class, is.get(1).getClass());
    Assert.assertEquals(LogInterceptor.class, is.get(2).getClass());
    Assert.assertEquals(SpringInterceptor.class, is.get(3).getClass());
    Assert.assertEquals(LogInterceptor.class, is.get(4).getClass());
    SpringInterceptor si = (SpringInterceptor) is.get(3);
    Assert.assertSame(is.get(1), is.get(2));
    Assert.assertSame(is.get(1), si.getInner());
}
Also used : ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) SpringInterceptor(com.predic8.membrane.core.interceptor.SpringInterceptor) Interceptor(com.predic8.membrane.core.interceptor.Interceptor) LogInterceptor(com.predic8.membrane.core.interceptor.LogInterceptor) SpringInterceptor(com.predic8.membrane.core.interceptor.SpringInterceptor) Test(org.junit.Test)

Example 54 with ServiceProxy

use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.

the class MethodTest method setUp.

@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 4000), "oio.de", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) Before(org.junit.Before)

Example 55 with ServiceProxy

use of com.predic8.membrane.core.rules.ServiceProxy in project service-proxy by membrane.

the class AbortExchangeTest method setup.

@Before
public void setup() throws Exception {
    router = new HttpRouter();
    LimitedMemoryExchangeStore es = new LimitedMemoryExchangeStore();
    router.setExchangeStore(es);
    router.getTransport().getInterceptors().add(2, new ExchangeStoreInterceptor(es));
    ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3031), "", -1);
    sp2.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleRequest(Exchange exc) throws Exception {
            exc.getRequest().readBody();
            exc.setResponse(Response.ok("").body(new InputStream() {

                int l = 0;

                @Override
                public int read() throws IOException {
                    if (l >= 2000000)
                        return -1;
                    return 0;
                }
            }, true).build());
            return Outcome.RETURN;
        }
    });
    router.getRuleManager().addProxyAndOpenPortIfNew(sp2);
    router.init();
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Outcome(com.predic8.membrane.core.interceptor.Outcome) InputStream(java.io.InputStream) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) ExchangeStoreInterceptor(com.predic8.membrane.core.interceptor.ExchangeStoreInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter) IOException(java.io.IOException) Before(org.junit.Before)

Aggregations

ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)47 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)34 HttpRouter (com.predic8.membrane.core.HttpRouter)25 Before (org.junit.Before)19 Rule (com.predic8.membrane.core.rules.Rule)17 Exchange (com.predic8.membrane.core.exchange.Exchange)16 Outcome (com.predic8.membrane.core.interceptor.Outcome)14 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)12 IOException (java.io.IOException)9 Test (org.junit.Test)9 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)5 ArrayList (java.util.ArrayList)4 Router (com.predic8.membrane.core.Router)3 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)3 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)3 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)3 URISyntaxException (java.net.URISyntaxException)3 Interceptor (com.predic8.membrane.core.interceptor.Interceptor)2 MockInterceptor (com.predic8.membrane.core.interceptor.MockInterceptor)2