Search in sources :

Example 11 with Rule

use of com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule in project service-proxy by membrane.

the class RuleManager method getMatchingRule.

public Rule getMatchingRule(String hostHeader, String method, String uri, String version, int port, String localIP) {
    for (Rule rule : rules) {
        RuleKey key = rule.getKey();
        log.debug("Host from rule: " + key.getHost() + ";   Host from parameter rule key: " + hostHeader);
        if (!rule.isActive())
            continue;
        if (!key.matchesVersion(version))
            continue;
        if (key.getIp() != null && !key.getIp().equals(localIP))
            continue;
        if (!key.matchesHostHeader(hostHeader))
            continue;
        if (key.getPort() != -1 && port != -1 && key.getPort() != port)
            continue;
        if (!key.getMethod().equals(method) && !key.isMethodWildcard())
            continue;
        if (key.isUsePathPattern() && !key.matchesPath(uri))
            continue;
        if (!key.complexMatch(hostHeader, method, uri, version, port, localIP))
            continue;
        return rule;
    }
    return null;
}
Also used : RuleKey(com.predic8.membrane.core.rules.RuleKey) Rule(com.predic8.membrane.core.rules.Rule)

Example 12 with Rule

use of com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule in project service-proxy by membrane.

the class RuleManager method openPorts.

public synchronized void openPorts() throws IOException {
    HashMap<IpPort, SSLProvider> sslProviders;
    try {
        HashMap<IpPort, SSLContextCollection.Builder> sslContexts = new HashMap<IpPort, SSLContextCollection.Builder>();
        for (Rule rule : rules) {
            SSLContext sslContext = rule.getSslInboundContext();
            if (sslContext != null) {
                IpPort ipPort = new IpPort(rule.getKey().getIp(), rule.getKey().getPort());
                SSLContextCollection.Builder builder = sslContexts.get(ipPort);
                if (builder == null) {
                    builder = new SSLContextCollection.Builder();
                    sslContexts.put(ipPort, builder);
                }
                builder.add(sslContext);
            }
        }
        sslProviders = new HashMap<IpPort, SSLProvider>();
        for (Map.Entry<IpPort, SSLContextCollection.Builder> entry : sslContexts.entrySet()) sslProviders.put(entry.getKey(), entry.getValue().build());
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
    for (Rule rule : rules) {
        IpPort ipPort = new IpPort(rule.getKey().getIp(), rule.getKey().getPort());
        router.getTransport().openPort(rule.getKey().getIp(), rule.getKey().getPort(), sslProviders.get(ipPort));
    }
}
Also used : SSLContextCollection(com.predic8.membrane.core.transport.ssl.SSLContextCollection) HashMap(java.util.HashMap) IpPort(com.predic8.membrane.core.transport.http.IpPort) SSLContext(com.predic8.membrane.core.transport.ssl.SSLContext) IOException(java.io.IOException) ConfigurationException(com.predic8.membrane.core.config.ConfigurationException) SSLProvider(com.predic8.membrane.core.transport.ssl.SSLProvider) Rule(com.predic8.membrane.core.rules.Rule) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with Rule

use of com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleServiceProxyShowRequest.

@Mapping("/admin/service-proxy/show/?(\\?.*)?")
public Response handleServiceProxyShowRequest(final Map<String, String> params, final String relativeRootPath) throws Exception {
    final StringWriter writer = new StringWriter();
    final AbstractServiceProxy rule = (AbstractServiceProxy) RuleUtil.findRuleByIdentifier(router, params.get("name"));
    return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {

        @Override
        protected int getSelectedTab() {
            return TAB_ID_SERVICE_PROXIES;
        }

        @Override
        protected String getTitle() {
            return super.getTitle() + " " + rule.toString() + " ServiceProxy";
        }

        @Override
        protected void createTabContent() throws Exception {
            h1().text(rule.toString() + " ServiceProxy").end();
            script().raw("$(function() {\r\n" + "					$( \"#subtab\" ).tabs();\r\n" + "				});").end();
            div().id("subtab");
            ul();
            li().a().href("#tab1").text("Visualization").end(2);
            li().a().href("#tab2").text("Statistics").end(2);
            // li().a().href("#tab3").text("XML Configuration").end(2);
            end();
            div().id("tab1");
            createServiceProxyVisualization(rule, relativeRootPath);
            end();
            div().id("tab2");
            createStatusCodesTable(rule.getStatisticsByStatusCodes());
            br();
            createButton("View Messages", "calls", null, createQueryString("proxy", rule.toString()));
            end();
            end();
        }
    }.createPage());
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) StringWriter(java.io.StringWriter)

Example 14 with Rule

use of com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule in project service-proxy by membrane.

the class EtcdRegistryApiConfig method findAdminConsole.

private EtcdNodeInformation findAdminConsole() {
    Object routerObj = context.getBean(Router.class);
    if (routerObj == null)
        throw new RuntimeException("Router not found, cannot publish admin console");
    Router router = (Router) routerObj;
    for (Rule r : router.getRuleManager().getRules()) {
        if (!(r instanceof AbstractServiceProxy))
            continue;
        for (Interceptor i : r.getInterceptors()) {
            if (i instanceof AdminConsoleInterceptor) {
                String name = r.getName();
                String host = ((ServiceProxy) r).getExternalHostname();
                if (host == null)
                    host = getLocalHostname();
                String port = Integer.toString(((AbstractServiceProxy) r).getPort());
                EtcdNodeInformation node = new EtcdNodeInformation(null, null, host, port, name);
                return node;
            }
        }
    }
    throw new RuntimeException("Admin console not found but is needed. Add a service proxy with an admin console.");
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) AdminConsoleInterceptor(com.predic8.membrane.core.interceptor.administration.AdminConsoleInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) EtcdNodeInformation(com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation) Router(com.predic8.membrane.core.Router) Rule(com.predic8.membrane.core.rules.Rule) Interceptor(com.predic8.membrane.core.interceptor.Interceptor) AdminConsoleInterceptor(com.predic8.membrane.core.interceptor.administration.AdminConsoleInterceptor)

Example 15 with Rule

use of com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule in project service-proxy by membrane.

the class RESTBLZServiceIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3005), "thomas-bayer.com", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    HTTP2XMLInterceptor http2xml = new HTTP2XMLInterceptor();
    router.getTransport().getInterceptors().add(http2xml);
    RewriteInterceptor urlRewriter = new RewriteInterceptor();
    List<Mapping> mappings = new ArrayList<Mapping>();
    mappings.add(new Mapping("/bank/.*", "/axis2/services/BLZService", null));
    urlRewriter.setMappings(mappings);
    router.getTransport().getInterceptors().add(urlRewriter);
    XSLTInterceptor xslt = new XSLTInterceptor();
    xslt.setXslt("classpath:/blz-httpget2soap-request.xsl");
    xslt.setFlow(Flow.Set.REQUEST);
    xslt.setXslt("classpath:/strip-soap-envelope.xsl");
    xslt.setFlow(Flow.Set.RESPONSE);
    router.getTransport().getInterceptors().add(xslt);
}
Also used : Mapping(com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) XSLTInterceptor(com.predic8.membrane.core.interceptor.xslt.XSLTInterceptor)

Aggregations

Rule (com.predic8.membrane.core.rules.Rule)29 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)15 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)13 HttpRouter (com.predic8.membrane.core.HttpRouter)11 Before (org.junit.Before)8 IRuleChangeListener (com.predic8.membrane.core.model.IRuleChangeListener)6 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)6 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)5 Exchange (com.predic8.membrane.core.exchange.Exchange)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)2 HeaderField (com.predic8.membrane.core.http.HeaderField)2 MockInterceptor (com.predic8.membrane.core.interceptor.MockInterceptor)2 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)2 IExchangesStoreListener (com.predic8.membrane.core.model.IExchangesStoreListener)2 NullRule (com.predic8.membrane.core.rules.NullRule)2 SOAPProxy (com.predic8.membrane.core.rules.SOAPProxy)2 StringWriter (java.io.StringWriter)2 CacheBuilder (com.google.common.cache.CacheBuilder)1