Search in sources :

Example 1 with ServiceProxyKey

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

the class IndexInterceptor method getServiceInfo.

private ServiceInfo getServiceInfo(Exchange exc, AbstractServiceProxy sp) {
    if (sp.getInterceptors().size() == 1 && sp.getInterceptors().get(0) instanceof IndexInterceptor)
        return null;
    ServiceProxyKey k = (ServiceProxyKey) sp.getKey();
    ServiceInfo ri = new ServiceInfo();
    ri.method = k.getMethod();
    // NOTE: when running as servlet, we have no idea what the protocol was
    ri.ssl = sp.getSslInboundContext() != null;
    String protocol = ri.ssl ? "https" : "http";
    String host = k.isHostWildcard() ? new HostColonPort(ri.ssl, exc.getRequest().getHeader().getHost()).host : fullfillRegexp(ServiceProxyKey.createHostPattern(k.getHost()));
    if (host == null || host.length() == 0)
        host = exc.getHandler().getLocalAddress().getHostAddress().toString();
    int port = k.getPort();
    if (port == -1 || !exc.getHandler().isMatchLocalPort())
        port = exc.getHandler().getLocalPort();
    String path;
    if (!k.isUsePathPattern()) {
        path = "/";
    } else if (k.isPathRegExp()) {
        path = fullfillRegexp(k.getPath());
    } else {
        path = "/" + StringUtils.removeStart(k.getPath(), "/");
    }
    if (!"".equals(exc.getHandler().getContextPath(exc))) {
        path = StringUtils.removeEnd(exc.getHandler().getContextPath(exc), "/") + "/" + StringUtils.removeStart(path, "/");
    }
    ri.name = sp.getName();
    if (path != null)
        ri.url = protocol + "://" + host + ":" + port + path;
    ri.host = k.isHostWildcard() ? "" : StringEscapeUtils.escapeHtml(k.getHost());
    ri.port = k.getPort() == -1 ? "" : "" + k.getPort();
    ri.path = k.isUsePathPattern() ? "<tt>" + StringEscapeUtils.escapeHtml(k.getPath()) + "</tt>" + (k.isPathRegExp() ? " (regex)" : "") : "";
    return ri;
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) HostColonPort(com.predic8.membrane.core.transport.http.HostColonPort)

Example 2 with ServiceProxyKey

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

the class LargeBodyTest method setup.

public void setup() throws Exception {
    // streaming only works for maxRetries = 1
    hcc = new HttpClientConfiguration();
    hcc.setMaxRetries(1);
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3040), "thomas-bayer.com", 80);
    rule.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleRequest(Exchange exc) throws Exception {
            exc.setResponse(Response.ok().body("").build());
            return Outcome.RETURN;
        }
    });
    router = new HttpRouter();
    ((HTTPClientInterceptor) router.getTransport().getInterceptors().get(3)).setHttpClientConfig(hcc);
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    router.init();
    Rule rule1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3041), "localhost", 3040);
    router2 = new HttpRouter();
    ((HTTPClientInterceptor) router2.getTransport().getInterceptors().get(3)).setHttpClientConfig(hcc);
    router2.getRuleManager().addProxyAndOpenPortIfNew(rule1);
    router2.init();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) HTTPClientInterceptor(com.predic8.membrane.core.interceptor.HTTPClientInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) HttpClientConfiguration(com.predic8.membrane.core.transport.http.client.HttpClientConfiguration) IOException(java.io.IOException)

Example 3 with ServiceProxyKey

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

the class Http10Test method setUp.

@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "thomas-bayer.com", 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 4 with ServiceProxyKey

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

the class LoadBalancingInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    service1 = new HttpRouter();
    mockInterceptor1 = new DummyWebServiceInterceptor();
    ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2000), "thomas-bayer.com", 80);
    sp1.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleResponse(Exchange exc) throws Exception {
            exc.getResponse().getHeader().add("Connection", "close");
            return Outcome.CONTINUE;
        }
    });
    sp1.getInterceptors().add(mockInterceptor1);
    service1.getRuleManager().addProxyAndOpenPortIfNew(sp1);
    service1.init();
    service2 = new HttpRouter();
    mockInterceptor2 = new DummyWebServiceInterceptor();
    ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "thomas-bayer.com", 80);
    sp2.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleResponse(Exchange exc) throws Exception {
            exc.getResponse().getHeader().add("Connection", "close");
            return Outcome.CONTINUE;
        }
    });
    sp2.getInterceptors().add(mockInterceptor2);
    service2.getRuleManager().addProxyAndOpenPortIfNew(sp2);
    service2.init();
    balancer = new HttpRouter();
    ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 7000), "thomas-bayer.com", 80);
    balancingInterceptor = new LoadBalancingInterceptor();
    balancingInterceptor.setName("Default");
    sp3.getInterceptors().add(balancingInterceptor);
    balancer.getRuleManager().addProxyAndOpenPortIfNew(sp3);
    enableFailOverOn5XX(balancer);
    balancer.init();
    BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 2000);
    BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 3000);
    roundRobinStrategy = new RoundRobinStrategy();
    byThreadStrategy = new ByThreadStrategy();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) LoadBalancingInterceptor(com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) ByThreadStrategy(com.predic8.membrane.core.interceptor.balancer.ByThreadStrategy) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter) RoundRobinStrategy(com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) DummyWebServiceInterceptor(com.predic8.membrane.core.services.DummyWebServiceInterceptor) Before(org.junit.Before)

Example 5 with ServiceProxyKey

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

the class HttpKeepAliveTest method setUp.

@Before
public void setUp() throws Exception {
    set = new HashSet<Integer>();
    service1 = new HttpRouter();
    sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2003), "thomas-bayer.com", 80);
    sp1.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleRequest(Exchange exc) throws Exception {
            exc.getRequest().readBody();
            exc.setResponse(Response.ok("OK.").build());
            set.add(((HttpServerHandler) exc.getHandler()).getSrcOut().hashCode());
            return Outcome.RETURN;
        }
    });
    service1.getRuleManager().addProxyAndOpenPortIfNew(sp1);
    service1.init();
}
Also used : 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) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

Aggregations

ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)35 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)34 HttpRouter (com.predic8.membrane.core.HttpRouter)24 Before (org.junit.Before)18 Rule (com.predic8.membrane.core.rules.Rule)14 Exchange (com.predic8.membrane.core.exchange.Exchange)12 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)11 Outcome (com.predic8.membrane.core.interceptor.Outcome)11 IOException (java.io.IOException)8 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)3 SSLParser (com.predic8.membrane.core.config.security.SSLParser)2 MockInterceptor (com.predic8.membrane.core.interceptor.MockInterceptor)2 WebServerInterceptor (com.predic8.membrane.core.interceptor.server.WebServerInterceptor)2 ProxyRuleKey (com.predic8.membrane.core.rules.ProxyRuleKey)2 DummyWebServiceInterceptor (com.predic8.membrane.core.services.DummyWebServiceInterceptor)2 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)2 ProxyConfiguration (com.predic8.membrane.core.transport.http.client.ProxyConfiguration)2 MalformedURLException (java.net.MalformedURLException)2