Search in sources :

Example 26 with Interceptor

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

the class SpringReferencesTest method doit.

@Test
public void doit() {
    ServiceProxy p = (ServiceProxy) r.getRules().iterator().next();
    List<Interceptor> is = p.getInterceptors();
    Assert.assertEquals(LogInterceptor.class, is.get(0).getClass());
    Assert.assertEquals(LogInterceptor.class, is.get(1).getClass());
    Assert.assertEquals(LogInterceptor.class, is.get(2).getClass());
    Assert.assertEquals(SpringInterceptor.class, is.get(3).getClass());
    Assert.assertEquals(LogInterceptor.class, is.get(4).getClass());
    SpringInterceptor si = (SpringInterceptor) is.get(3);
    Assert.assertSame(is.get(1), is.get(2));
    Assert.assertSame(is.get(1), si.getInner());
}
Also used : ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) SpringInterceptor(com.predic8.membrane.core.interceptor.SpringInterceptor) Interceptor(com.predic8.membrane.core.interceptor.Interceptor) LogInterceptor(com.predic8.membrane.core.interceptor.LogInterceptor) SpringInterceptor(com.predic8.membrane.core.interceptor.SpringInterceptor) Test(org.junit.Test)

Example 27 with Interceptor

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

the class ConditionalInterceptor method getShortDescription.

@Override
public String getShortDescription() {
    String ret = "if (" + test + ") {";
    for (Interceptor i : getInterceptors()) {
        ret += "<br/>&nbsp;&nbsp;&nbsp;&nbsp;" + i.getDisplayName();
    }
    ret += "<br/>}";
    return ret;
}
Also used : Interceptor(com.predic8.membrane.core.interceptor.Interceptor)

Example 28 with Interceptor

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

the class RequestInterceptor method handleRequest.

@Override
public Outcome handleRequest(Exchange exc) throws Exception {
    boolean logDebug = log.isDebugEnabled();
    for (Interceptor i : getInterceptors()) {
        EnumSet<Flow> f = i.getFlow();
        if (!f.contains(Flow.REQUEST))
            continue;
        if (logDebug)
            log.debug("Invoking request handler: " + i.getDisplayName() + " on exchange: " + exc);
        Outcome o = i.handleRequest(exc);
        if (o != Outcome.CONTINUE)
            return o;
    }
    return Outcome.CONTINUE;
}
Also used : Outcome(com.predic8.membrane.core.interceptor.Outcome) Interceptor(com.predic8.membrane.core.interceptor.Interceptor)

Example 29 with Interceptor

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

the class AbstractProxy method init.

/**
 * Called after parsing is complete and this has been added to the object tree (whose root is Router).
 */
public final void init(Router router) throws Exception {
    this.router = router;
    try {
        init();
        for (Interceptor i : interceptors) i.init(router);
        active = true;
    } catch (Exception e) {
        if (!router.isRetryInit())
            throw e;
        log.error("", e);
        active = false;
        error = e.getMessage();
    }
}
Also used : Interceptor(com.predic8.membrane.core.interceptor.Interceptor)

Example 30 with Interceptor

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

the class SwaggerProxy method init.

@Override
public void init() throws Exception {
    super.init();
    // download swaggerUrl
    HttpClient hc = new HttpClient(router.getHttpClientConfig());
    Exchange ex = hc.call(new Request.Builder().get(swaggerUrl).buildExchange());
    if (ex.getResponse().getStatusCode() != 200) {
        log.error("Couldn't fetch Swagger URL!");
        throw new Exception("Couldn't fetch Swagger URL!");
    }
    // parse swaggerUrl
    swagger = new SwaggerParser().parse(ex.getResponse().getBodyAsStringDecoded());
    // pass swagger specification to Swagger Key
    ((SwaggerProxyKey) key).setSwagger(swagger);
    ((SwaggerProxyKey) key).setAllowUI(allowUI);
    // add interceptor to position 0.
    SwaggerRewriterInterceptor sri = new SwaggerRewriterInterceptor(swagger, swaggerUrl);
    interceptors.add(0, sri);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) SwaggerParser(io.swagger.parser.SwaggerParser) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Request(com.predic8.membrane.core.http.Request) SwaggerRewriterInterceptor(com.predic8.membrane.core.interceptor.swagger.SwaggerRewriterInterceptor)

Aggregations

Interceptor (com.predic8.membrane.core.interceptor.Interceptor)11 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)6 Test (org.junit.Test)6 HttpRouter (com.predic8.membrane.core.HttpRouter)5 Rule (com.predic8.membrane.core.rules.Rule)5 Before (org.junit.Before)5 Exchange (com.predic8.membrane.core.exchange.Exchange)4 ArrayList (java.util.ArrayList)4 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 ResolverMap (com.predic8.membrane.core.resolver.ResolverMap)3 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)3 Response (com.predic8.membrane.core.http.Response)2 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)2 DispatchingInterceptor (com.predic8.membrane.core.interceptor.DispatchingInterceptor)2 HTTPClientInterceptor (com.predic8.membrane.core.interceptor.HTTPClientInterceptor)2 RuleMatchingInterceptor (com.predic8.membrane.core.interceptor.RuleMatchingInterceptor)2 UserFeatureInterceptor (com.predic8.membrane.core.interceptor.UserFeatureInterceptor)2 AccessControlInterceptor (com.predic8.membrane.core.interceptor.acl.AccessControlInterceptor)2 User (com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User)2 RequestInterceptor (com.predic8.membrane.core.interceptor.flow.RequestInterceptor)2