Search in sources :

Example 26 with Router

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

the class InterceptorInvocationTest method createRouter.

private HttpRouter createRouter() throws Exception {
    HttpRouter router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(createServiceProxy());
    addMockInterceptors(router, regularInterceptorNames);
    router.init();
    return router;
}
Also used : HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 27 with Router

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

the class ConnectionTest method setUp.

@Before
public void setUp() throws Exception {
    Rule rule2000 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 2000), "predic8.com", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule2000);
    conLocalhost = Connection.open("localhost", 2000, null, null, 30000);
    con127_0_0_1 = Connection.open("127.0.0.1", 2000, null, null, 30000);
}
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 28 with Router

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

the class EmbeddingJava method main.

public static void main(String[] args) throws Exception {
    String hostname = "*";
    String method = "GET";
    String path = ".*";
    int listenPort = 4000;
    ServiceProxyKey key = new ServiceProxyKey(hostname, method, path, listenPort);
    String targetHost = "predic8.com";
    int targetPort = 80;
    ServiceProxy sp = new ServiceProxy(key, targetHost, targetPort);
    sp.getInterceptors().add(new AddMyHeaderInterceptor());
    HttpRouter router = new HttpRouter();
    router.add(sp);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) HttpRouter(com.predic8.membrane.core.HttpRouter)

Example 29 with Router

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

the class EtcdBasedConfigurator method setUpModuleServiceProxy.

private ServiceProxy setUpModuleServiceProxy(String name, int port, String path) {
    log.info("Creating serviceProxy for module: " + path);
    ServiceProxyKey key = new ServiceProxyKey("*", "*", path, port);
    key.setUsePathPattern(true);
    key.setPathRegExp(false);
    ServiceProxy sp = new ServiceProxy(key, null, 0);
    sp.getInterceptors().add(new LoadBalancingInterceptor());
    try {
        sp.init(router);
        router.add(sp);
        runningServiceProxyForModule.put(path, sp);
    } catch (Exception ignored) {
    }
    return sp;
}
Also used : LoadBalancingInterceptor(com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) BeansException(org.springframework.beans.BeansException)

Example 30 with Router

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

the class ConfigSerializationTest method doit.

@Test
public void doit() throws Exception {
    try {
        String config = FileUtils.readFileToString(new File(configFile));
        Object o = MCUtil.fromXML(Router.class, config);
        String xml = MCUtil.toXML(o);
        // prettyPrint(xml);
        // System.out.println(xml);
        AssertUtils.assertContainsNot("incomplete serialization", xml);
        Router r2 = MCUtil.fromXML(Router.class, xml);
        String xml2 = MCUtil.toXML(r2);
        XMLAssert.assertXMLEqual(xml2, xml);
    } catch (Exception e) {
        throw new Exception("in test " + configFile, e);
    }
}
Also used : Router(com.predic8.membrane.core.Router) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

HttpRouter (com.predic8.membrane.core.HttpRouter)24 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)21 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)19 Before (org.junit.Before)18 Rule (com.predic8.membrane.core.rules.Rule)16 IOException (java.io.IOException)9 Router (com.predic8.membrane.core.Router)8 Exchange (com.predic8.membrane.core.exchange.Exchange)6 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)5 Outcome (com.predic8.membrane.core.interceptor.Outcome)5 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)5 StringWriter (java.io.StringWriter)5 Test (org.junit.Test)5 Interceptor (com.predic8.membrane.core.interceptor.Interceptor)3 Node (com.predic8.membrane.core.interceptor.balancer.Node)3 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)3 ProxyRuleKey (com.predic8.membrane.core.rules.ProxyRuleKey)3 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)3 File (java.io.File)3