Search in sources :

Example 41 with Router

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

the class SOAPRESTHelper method getTransformer.

protected XSLTTransformer getTransformer(String ss) throws Exception {
    String key = ss == null ? "null" : ss;
    XSLTTransformer t = xsltTransformers.get(key);
    if (t == null) {
        int concurrency = 2 * Runtime.getRuntime().availableProcessors();
        t = new XSLTTransformer(ss, router, concurrency);
        XSLTTransformer t2 = xsltTransformers.putIfAbsent(key, t);
        if (t2 != null)
            return t2;
    }
    return t;
}
Also used : XSLTTransformer(com.predic8.membrane.core.interceptor.xslt.XSLTTransformer)

Example 42 with Router

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

the class MembraneAuthorizationService method init.

@Override
public void init() throws Exception {
    if (src == null)
        throw new Exception("No wellknown file source configured. - Cannot work without one");
    if (dynamicRegistration != null) {
        dynamicRegistration.init(router);
        supportsDynamicRegistration = true;
    }
    try {
        String[] urls = src.split(Pattern.quote(" "));
        if (urls.length == 1) {
            String url = urls[0] + "/.well-known/openid-configuration";
            parseSrc(dynamicRegistration != null ? dynamicRegistration.retrieveOpenIDConfiguration(url) : router.getResolverMap().resolve(url));
        } else if (urls.length == 2) {
            String internalUrl = urls[1] + "/.well-known/openid-configuration";
            parseSrc(dynamicRegistration != null ? dynamicRegistration.retrieveOpenIDConfiguration(internalUrl) : router.getResolverMap().resolve(internalUrl));
            publicAuthorizationEndpoint = urls[0] + new URI(authorizationEndpoint).getPath();
        } else if (urls.length > 2)
            throw new RuntimeException("src property is not set correctly: " + src);
    } catch (ResourceRetrievalException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    adjustScope();
    prepareClaimsForLoginUrl();
}
Also used : IOException(java.io.IOException) URI(java.net.URI) IOException(java.io.IOException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ResourceRetrievalException(com.predic8.membrane.core.resolver.ResourceRetrievalException)

Example 43 with Router

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

the class AdminPageBuilder method createClustersTable.

protected void createClustersTable(String balancerName) throws UnsupportedEncodingException {
    table().attr("cellpadding", "0", "cellspacing", "0", "border", "0", "class", "display clustersTable");
    thead();
    tr();
    createThs("Name", "#Nodes", "Health");
    end();
    end();
    tbody();
    for (Cluster c : BalancerUtil.lookupBalancer(router, balancerName).getClusters()) {
        tr();
        td();
        createLink(!c.getName().isEmpty() ? c.getName() : "<unnamed>", "clusters", "show", createQueryString("balancer", balancerName, "cluster", c.getName()));
        end();
        createTds(String.valueOf(BalancerUtil.lookupBalancer(router, balancerName).getAllNodesByCluster(c.getName()).size()), getFormatedHealth(balancerName, c.getName()));
        end();
    }
    end();
    end();
}
Also used : Cluster(com.predic8.membrane.core.interceptor.balancer.Cluster)

Example 44 with Router

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

the class AdminPageBuilder method getFormatedHealth.

private String getFormatedHealth(String balancerName) {
    Balancer balancer = BalancerUtil.lookupBalancer(router, balancerName);
    int available = 0, all = 0;
    for (Cluster c : balancer.getClusters()) {
        all += balancer.getAllNodesByCluster(c.getName()).size();
        available += balancer.getAvailableNodesByCluster(c.getName()).size();
    }
    return String.format("%d up/ %d down", available, all - available);
}
Also used : Balancer(com.predic8.membrane.core.interceptor.balancer.Balancer) Cluster(com.predic8.membrane.core.interceptor.balancer.Cluster)

Example 45 with Router

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

the class ClusterNotificationInterceptorTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3002), "thomas-bayer.com", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    interceptor = new ClusterNotificationInterceptor();
    router.addUserFeatureInterceptor(interceptor);
    lbi = new LoadBalancingInterceptor();
    lbi.setName("Default");
    Rule rule2 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3003), "thomas-bayer.com", 80);
    router.getRuleManager().addProxyAndOpenPortIfNew(rule2);
    rule2.getInterceptors().add(lbi);
    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)

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