Search in sources :

Example 6 with Rule

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

the class SwaggerRewriterInterceptor method init.

@Override
public void init() throws Exception {
    // inherit wsdl="..." from SoapProxy
    if (this.swagger == null) {
        Rule parent = router.getParentProxy(this);
        if (parent instanceof SwaggerProxy) {
            setSwagger(((SwaggerProxy) parent).getSwagger());
        }
    }
    // use default if no SwaggerProxy is found
    if (this.swagger == null) {
        String swaggerSource = IOUtils.toString(this.getRouter().getResolverMap().resolve(this.swaggerJson));
        this.swagger = new SwaggerParser().parse(swaggerSource);
        this.swaggerUrl = this.swaggerJson;
    }
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) SwaggerProxy(com.predic8.membrane.core.rules.SwaggerProxy) Rule(com.predic8.membrane.core.rules.Rule)

Example 7 with Rule

use of com.predic8.membrane.core.rules.Rule 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 8 with Rule

use of com.predic8.membrane.core.rules.Rule 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 9 with Rule

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

the class RuleManager method addProxyAndOpenPortIfNew.

public synchronized void addProxyAndOpenPortIfNew(Rule rule, RuleDefinitionSource source) throws IOException {
    if (exists(rule.getKey()))
        return;
    router.getTransport().openPort(rule.getKey().getIp(), rule.getKey().getPort(), rule.getSslInboundContext());
    rules.add(rule);
    ruleSources.add(source);
    for (IRuleChangeListener listener : listeners) {
        listener.ruleAdded(rule);
    }
}
Also used : IRuleChangeListener(com.predic8.membrane.core.model.IRuleChangeListener)

Example 10 with Rule

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

the class RuleManager method removeRule.

public synchronized void removeRule(Rule rule) {
    getExchangeStore().removeAllExchanges(rule);
    int i = rules.indexOf(rule);
    rules.remove(i);
    ruleSources.remove(i);
    for (IRuleChangeListener listener : listeners) {
        listener.ruleRemoved(rule, rules.size());
    }
}
Also used : IRuleChangeListener(com.predic8.membrane.core.model.IRuleChangeListener)

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