use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class ResolverTestTriggerTest method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) {
try {
Class<?> clazz = Class.forName("com.predic8.membrane.core.resolver.ResolverTest");
clazz.getField("deployment").set(null, "J2EE");
Object value = router.getResolverMap().getFileSchemaResolver();
Object resolverMap = clazz.getField("resolverMap").get(null);
resolverMap.getClass().getMethod("addSchemaResolver", SchemaResolver.class).invoke(resolverMap, value);
Parameterized p = new Parameterized(clazz);
JUnitCore c = new JUnitCore();
Result run = c.run(Request.runner(p));
StringBuilder sb = new StringBuilder();
sb.append(MAGIC);
for (Failure f : run.getFailures()) {
sb.append(f.toString());
StringWriter stringWriter = new StringWriter();
f.getException().printStackTrace(new PrintWriter(stringWriter));
sb.append(stringWriter.toString());
sb.append("\n");
sb.append("\n");
}
exc.setResponse(Response.ok().header(Header.CONTENT_TYPE, MimeType.TEXT_PLAIN_UTF8).body(sb.toString()).build());
} catch (Throwable t) {
LOG.error(t.getMessage(), t);
}
return Outcome.RETURN;
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class ExceptionHandlingTest method setUp.
@Before
public void setUp() throws Exception {
router = new HttpRouter();
router.getTransport().setPrintStackTrace(printStackTrace);
ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", getPort()), "", -1);
sp2.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
throw new Exception("secret");
}
});
router.getRuleManager().addProxyAndOpenPortIfNew(sp2);
router.init();
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class BoundConnectionTest method setUp.
@Before
public void setUp() throws Exception {
router = new HttpRouter();
ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3021), "localhost", 3022);
router.getRuleManager().addProxyAndOpenPortIfNew(sp1);
ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3022), "", -1);
sp2.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
exc.getRequest().readBody();
exc.setResponse(Response.ok("OK.").build());
connectionHash = ((HttpServerHandler) exc.getHandler()).getSrcOut().hashCode();
return Outcome.RETURN;
}
});
router.getRuleManager().addProxyAndOpenPortIfNew(sp2);
router.init();
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class HttpKeepAliveTest method testConnectionClose.
@Test
public void testConnectionClose() throws Exception {
HttpClient client = createHttpClient(500);
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;
}
});
// opens connection 1
assertEquals(200, issueRequest(client));
assertEquals(1, set.size());
assertEquals(1, client.getConnectionManager().getNumberInPool());
// connection closer did not yet run
Thread.sleep(600);
// connection 1 is now dead, but still in pool
assertEquals(1, client.getConnectionManager().getNumberInPool());
// opens connection 2
assertEquals(200, issueRequest(client));
assertEquals(2, set.size());
// connection closer runs and closes both
Thread.sleep(600);
assertEquals(0, client.getConnectionManager().getNumberInPool());
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class HttpKeepAliveTest method testTimeoutDefault.
@Test
public void testTimeoutDefault() throws Exception {
HttpClient client = createHttpClient(1000);
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(1, set.size());
Thread.sleep(1500);
assertEquals(200, issueRequest(client));
assertEquals(2, set.size());
}
Aggregations