Search in sources :

Example 31 with Rule

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

the class MemoryExchangeStore method removeAllExchanges.

public void removeAllExchanges(Rule rule) {
    AbstractExchange[] exchanges = getExchanges(rule.getKey());
    exchangesMap.remove(rule.getKey());
    totals.removeAll(Arrays.asList(exchanges));
    for (IExchangesStoreListener listener : exchangesStoreListeners) {
        listener.removeExchanges(rule, exchanges);
    }
}
Also used : IExchangesStoreListener(com.predic8.membrane.core.model.IExchangesStoreListener) AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange)

Example 32 with Rule

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

the class RuleMatchingInterceptor method getRule.

private Rule getRule(Exchange exc) {
    Request request = exc.getRequest();
    AbstractHttpHandler handler = exc.getHandler();
    // retrieve value to match
    String hostHeader = request.getHeader().getHost();
    String method = request.getMethod();
    String uri = request.getUri();
    String version = request.getVersion();
    int port = handler.isMatchLocalPort() ? handler.getLocalPort() : -1;
    String localIP = handler.getLocalAddress().getHostAddress();
    // match it
    Rule rule = router.getRuleManager().getMatchingRule(hostHeader, method, uri, version, port, localIP);
    if (rule != null) {
        if (log.isDebugEnabled())
            log.debug("Matching Rule found for RuleKey " + hostHeader + " " + method + " " + uri + " " + port + " " + localIP);
        return rule;
    }
    return findProxyRule(exc);
}
Also used : Request(com.predic8.membrane.core.http.Request) Rule(com.predic8.membrane.core.rules.Rule) NullRule(com.predic8.membrane.core.rules.NullRule) ProxyRule(com.predic8.membrane.core.rules.ProxyRule) AbstractHttpHandler(com.predic8.membrane.core.transport.http.AbstractHttpHandler)

Example 33 with Rule

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

the class RuleMatchingInterceptor method handleRequest.

@Override
public Outcome handleRequest(Exchange exc) throws Exception {
    if (exc.getRule() != null)
        return Outcome.CONTINUE;
    Rule rule = getRule(exc);
    exc.setRule(rule);
    if (exc.getRule().getSslOutboundContext() != null) {
        exc.setProperty(Exchange.SSL_CONTEXT, exc.getRule().getSslOutboundContext());
    }
    if (rule instanceof NullRule) {
        handleNoRuleFound(exc);
        return Outcome.ABORT;
    }
    if (xForwardedForEnabled && (rule instanceof AbstractServiceProxy))
        insertXForwardedFor(exc);
    return Outcome.CONTINUE;
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) NullRule(com.predic8.membrane.core.rules.NullRule) Rule(com.predic8.membrane.core.rules.Rule) NullRule(com.predic8.membrane.core.rules.NullRule) ProxyRule(com.predic8.membrane.core.rules.ProxyRule)

Example 34 with Rule

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

the class BasicAuthenticationInterceptorIntegrationTest method setup.

@Before
public void setup() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3001), "thomas-bayer.com", 80);
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    BasicAuthenticationInterceptor interceptor = new BasicAuthenticationInterceptor();
    List<User> users = new ArrayList<User>();
    users.add(new User("admin", "admin"));
    interceptor.setUsers(users);
    router.addUserFeatureInterceptor(interceptor);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) User(com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) ArrayList(java.util.ArrayList) Rule(com.predic8.membrane.core.rules.Rule) Before(org.junit.Before)

Example 35 with Rule

use of com.predic8.membrane.core.interceptor.HeaderFilterInterceptor.Rule 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

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