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);
}
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);
}
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;
}
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());
}
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();
}
Aggregations