Search in sources :

Example 1 with Rule

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

the class AbstractExchangeStore method notifyListenersOnExchangeAdd.

public void notifyListenersOnExchangeAdd(Rule rule, AbstractExchange exchange) {
    for (IExchangesStoreListener listener : exchangesStoreListeners) {
        exchange.addExchangeStoreListener(listener);
        listener.addExchange(rule, exchange);
    }
}
Also used : IExchangesStoreListener(com.predic8.membrane.core.model.IExchangesStoreListener)

Example 2 with Rule

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

the class ElasticSearchExchangeStore method removeAllExchanges.

@Override
public void removeAllExchanges(Rule rule) {
    String name = rule.toString();
    try {
        Exchange exc = new Request.Builder().post(getElasticSearchExchangesPath() + "_delete_by_query").body("{\n" + "  \"query\": {\n" + "    \"bool\": {\n" + "      \"must\": [\n" + "        {\n" + "          \"wildcard\": {\n" + "            \"issuer\": \"" + documentPrefix + "\"\n" + "          }\n" + "        },\n" + "        {\n" + "          \"match\": {\n" + "            \"rule.name\": \"" + name + "\"\n" + "          }\n" + "        }\n" + "      ]\n" + "    }\n" + "  }\n" + "}").header("Content-Type", "application/json").buildExchange();
        client.call(exc);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) Exchange(com.predic8.membrane.core.exchange.Exchange) CacheBuilder(com.google.common.cache.CacheBuilder) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 3 with Rule

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

the class UserFeatureInterceptor method handleRequest.

@Override
public Outcome handleRequest(Exchange exc) throws Exception {
    Rule predecessorRule = exc.getRule();
    Outcome outcome = flowController.invokeRequestHandlers(exc, predecessorRule.getInterceptors());
    while (isTargetInternalAndContinue(exc, outcome)) {
        log.debug("routing to serviceProxy with name: " + getServiceProxyName(exc));
        // rule matching
        String destination = exc.getDestinations().get(0);
        Rule newRule = getRuleByDest(destination);
        if (newRule == null)
            throw new Exception("No proxy found for destination " + destination);
        exc.setRule(newRule);
        // dispatching
        exc.getDestinations().clear();
        exc.getDestinations().add(DispatchingInterceptor.getForwardingDestination(exc));
        // user feature
        outcome = flowController.invokeRequestHandlers(exc, newRule.getInterceptors());
    }
    exc.setRule(predecessorRule);
    return outcome;
}
Also used : Rule(com.predic8.membrane.core.rules.Rule)

Example 4 with Rule

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

the class ValidatorInterceptor method init.

@Override
public void init() throws Exception {
    validator = null;
    String baseLocation = router == null ? null : router.getBaseLocation();
    if (wsdl != null) {
        name = "SOAP Validator";
        setValidator(new WSDLValidator(resourceResolver, ResolverMap.combine(baseLocation, wsdl), createFailureHandler(), skipFaults));
    }
    if (schema != null) {
        name = "XML Schema Validator";
        setValidator(new XMLSchemaValidator(resourceResolver, ResolverMap.combine(baseLocation, schema), createFailureHandler()));
    }
    if (jsonSchema != null) {
        name = "JSON Schema Validator";
        setValidator(new JSONValidator(resourceResolver, ResolverMap.combine(baseLocation, jsonSchema), createFailureHandler()));
    }
    if (schematron != null) {
        name = "Schematron Validator";
        setValidator(new SchematronValidator(resourceResolver, ResolverMap.combine(baseLocation, schematron), createFailureHandler(), router, applicationContext));
    }
    if (validator == null) {
        Rule parent = router.getParentProxy(this);
        if (parent instanceof SOAPProxy) {
            wsdl = ((SOAPProxy) parent).getWsdl();
            name = "SOAP Validator";
            setValidator(new WSDLValidator(resourceResolver, ResolverMap.combine(baseLocation, wsdl), createFailureHandler(), skipFaults));
        }
        if (validator == null)
            throw new Exception("<validator> must have an attribute specifying the validator.");
    }
    if (skipFaults && wsdl == null)
        throw new Exception("validator/@skipFaults only makes sense with validator/@wsdl");
}
Also used : SOAPProxy(com.predic8.membrane.core.rules.SOAPProxy) Rule(com.predic8.membrane.core.rules.Rule) BeansException(org.springframework.beans.BeansException)

Example 5 with Rule

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

the class WSDLPublisherInterceptor method init.

@Override
public void init() throws Exception {
    // inherit wsdl="..." from SoapProxy
    if (wsdl == null) {
        Rule parent = router.getParentProxy(this);
        if (parent instanceof SOAPProxy) {
            wsdl = ((SOAPProxy) parent).getWsdl();
            setWsdl(wsdl);
        }
    }
}
Also used : SOAPProxy(com.predic8.membrane.core.rules.SOAPProxy) Rule(com.predic8.membrane.core.rules.Rule)

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