use of com.predic8.membrane.core.interceptor.AbstractInterceptor 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();
}
use of com.predic8.membrane.core.interceptor.AbstractInterceptor in project service-proxy by membrane.
the class LoadBalancingInterceptorTest method testFailOverOnStatus500.
@Test
public void testFailOverOnStatus500() throws Exception {
balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
HttpClient client = new HttpClient();
client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(0, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(1, mockInterceptor2.getCount());
((ServiceProxy) service1.getRuleManager().getRules().get(0)).getInterceptors().add(0, new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
exc.setResponse(Response.internalServerError().build());
return Outcome.ABORT;
}
});
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(2, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(3, mockInterceptor2.getCount());
}
use of com.predic8.membrane.core.interceptor.AbstractInterceptor in project service-proxy by membrane.
the class LoadBalancingInterceptorTest method setUp.
@Before
public void setUp() throws Exception {
service1 = new HttpRouter();
mockInterceptor1 = new DummyWebServiceInterceptor();
ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2000), "thomas-bayer.com", 80);
sp1.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add("Connection", "close");
return Outcome.CONTINUE;
}
});
sp1.getInterceptors().add(mockInterceptor1);
service1.getRuleManager().addProxyAndOpenPortIfNew(sp1);
service1.init();
service2 = new HttpRouter();
mockInterceptor2 = new DummyWebServiceInterceptor();
ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "thomas-bayer.com", 80);
sp2.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add("Connection", "close");
return Outcome.CONTINUE;
}
});
sp2.getInterceptors().add(mockInterceptor2);
service2.getRuleManager().addProxyAndOpenPortIfNew(sp2);
service2.init();
balancer = new HttpRouter();
ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 7000), "thomas-bayer.com", 80);
balancingInterceptor = new LoadBalancingInterceptor();
balancingInterceptor.setName("Default");
sp3.getInterceptors().add(balancingInterceptor);
balancer.getRuleManager().addProxyAndOpenPortIfNew(sp3);
enableFailOverOn5XX(balancer);
balancer.init();
BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 2000);
BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 3000);
roundRobinStrategy = new RoundRobinStrategy();
byThreadStrategy = new ByThreadStrategy();
}
use of com.predic8.membrane.core.interceptor.AbstractInterceptor 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.AbstractInterceptor 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