Search in sources :

Example 21 with Outcome

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

the class LoginInterceptor method handleRequest.

@Override
public Outcome handleRequest(Exchange exc) throws Exception {
    if (loginDialog.isLoginRequest(exc)) {
        loginDialog.handleLoginRequest(exc);
        return Outcome.RETURN;
    }
    Session s = sessionManager.getSession(exc);
    if (s != null && s.isPreAuthorized()) {
        if (tokenProvider == null) {
            s.authorize();
        }
    } else if (s == null || !s.isAuthorized()) {
        return loginDialog.redirectToLogin(exc);
    }
    applyBackendAuthorization(exc, s);
    return super.handleRequest(exc);
}
Also used : Session(com.predic8.membrane.core.interceptor.authentication.session.SessionManager.Session)

Example 22 with Outcome

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

the class LoginInterceptor method handleResponse.

@Override
public Outcome handleResponse(Exchange exc) throws Exception {
    Header header = exc.getResponse().getHeader();
    header.setNoCacheResponseHeaders();
    return super.handleResponse(exc);
}
Also used : Header(com.predic8.membrane.core.http.Header)

Example 23 with Outcome

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

the class ClusterNotificationInterceptor method handleRequest.

@Override
public Outcome handleRequest(Exchange exc) throws Exception {
    log.debug(exc.getOriginalRequestUri());
    Matcher m = urlPattern.matcher(exc.getOriginalRequestUri());
    if (!m.matches())
        return Outcome.CONTINUE;
    log.debug("request received: " + m.group(1));
    if (validateSignature && !getParams(exc).containsKey("data")) {
        exc.setResponse(Response.forbidden().build());
        return Outcome.ABORT;
    }
    Map<String, String> params = validateSignature ? getDecryptedParams(getParams(exc).get("data")) : getParams(exc);
    if (isTimedout(params)) {
        exc.setResponse(Response.forbidden().build());
        return Outcome.ABORT;
    }
    updateClusterManager(m, params);
    exc.setResponse(Response.noContent().build());
    return Outcome.RETURN;
}
Also used : Matcher(java.util.regex.Matcher) URLParamUtil.parseQueryString(com.predic8.membrane.core.util.URLParamUtil.parseQueryString)

Example 24 with Outcome

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

the class HttpKeepAliveTest method testMaxParameter.

@Test
public void testMaxParameter() throws Exception {
    HttpClient client = new HttpClient();
    sp1.getInterceptors().add(0, new AbstractInterceptor() {

        @Override
        public Outcome handleResponse(Exchange exc) throws Exception {
            exc.getResponse().getHeader().add(Header.KEEP_ALIVE, "max=2");
            return Outcome.CONTINUE;
        }
    });
    assertEquals(200, issueRequest(client));
    assertEquals(200, issueRequest(client));
    assertEquals(1, set.size());
    assertEquals(200, issueRequest(client));
    assertEquals(2, set.size());
    assertEquals(200, issueRequest(client));
    assertEquals(2, set.size());
    assertEquals(200, issueRequest(client));
    assertEquals(3, set.size());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Test(org.junit.Test)

Example 25 with Outcome

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

the class HttpKeepAliveTest method setUp.

@Before
public void setUp() throws Exception {
    set = new HashSet<Integer>();
    service1 = new HttpRouter();
    sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2003), "thomas-bayer.com", 80);
    sp1.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleRequest(Exchange exc) throws Exception {
            exc.getRequest().readBody();
            exc.setResponse(Response.ok("OK.").build());
            set.add(((HttpServerHandler) exc.getHandler()).getSrcOut().hashCode());
            return Outcome.RETURN;
        }
    });
    service1.getRuleManager().addProxyAndOpenPortIfNew(sp1);
    service1.init();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

Aggregations

Outcome (com.predic8.membrane.core.interceptor.Outcome)25 Exchange (com.predic8.membrane.core.exchange.Exchange)19 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)16 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)14 IOException (java.io.IOException)14 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)10 Test (org.junit.Test)9 HttpRouter (com.predic8.membrane.core.HttpRouter)8 URISyntaxException (java.net.URISyntaxException)7 Before (org.junit.Before)6 ArrayList (java.util.ArrayList)4 Header (com.predic8.membrane.core.http.Header)3 Session (com.predic8.membrane.core.interceptor.authentication.session.SessionManager.Session)3 Rule (com.predic8.membrane.core.rules.Rule)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Body (com.predic8.membrane.core.http.Body)2 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)2 MalformedURLException (java.net.MalformedURLException)2 InvalidParameterException (java.security.InvalidParameterException)2