@BeforeClass
public static void setup() throws URISyntaxException {
final SessionCookieConfig sessionConfig = new SessionCookieConfig();
int port = DefaultServer.getHostPort("default");
final JvmRouteHandler handler1 = jvmRoute("JSESSIONID", "s1", path()
.addPrefixPath("/session", new SessionAttachmentHandler(new SessionTestHandler(sessionConfig), new InMemorySessionManager(""), sessionConfig))
.addPrefixPath("/name", new StringSendHandler("server1")));
server1 = Undertow.builder()
.addHttpsListener(port + 1, DefaultServer.getHostAddress("default"), DefaultServer.getServerSslContext())
.setServerOption(UndertowOptions.ENABLE_HTTP2, true)
.setSocketOption(Options.REUSE_ADDRESSES, true)
.setHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
if (!(exchange.getConnection() instanceof Http2ServerConnection)) {
throw new RuntimeException("Not HTTP2");
}
exchange.getResponseHeaders().add(new HttpString("X-Custom-Header"), "foo");
System.out.println(exchange.getRequestHeaders());
handler1.handleRequest(exchange);
}
})
.build();
final JvmRouteHandler handler2 = jvmRoute("JSESSIONID", "s2", path()
.addPrefixPath("/session", new SessionAttachmentHandler(new SessionTestHandler(sessionConfig), new InMemorySessionManager(""), sessionConfig))
.addPrefixPath("/name", new StringSendHandler("server2")));
server2 = Undertow.builder()
.addHttpsListener(port + 2, DefaultServer.getHostAddress("default"), DefaultServer.getServerSslContext())
.setServerOption(UndertowOptions.ENABLE_HTTP2, true)
.setSocketOption(Options.REUSE_ADDRESSES, true)
.setHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
if (!(exchange.getConnection() instanceof Http2ServerConnection)) {
throw new RuntimeException("Not HTTP2");
}
exchange.getResponseHeaders().add(new HttpString("X-Custom-Header"), "foo");
System.out.println(exchange.getRequestHeaders());
handler2.handleRequest(exchange);
}
})
.build();
server1.start();
server2.start();