use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class LoadBalancingProxyHTTP2TestCase method setup.
@BeforeClass
public static void setup() throws URISyntaxException {
int port = DefaultServer.getHostPort("default");
final HttpHandler handler1 = getRootHandler("s1", "server1");
server1 = Undertow.builder().addHttpsListener(port + 1, DefaultServer.getHostAddress("default"), DefaultServer.getServerSslContext()).setServerOption(UndertowOptions.ENABLE_HTTP2, true).setServerOption(UndertowOptions.NO_REQUEST_TIMEOUT, IDLE_TIMEOUT).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");
handler1.handleRequest(exchange);
}
}).build();
final HttpHandler handler2 = getRootHandler("s2", "server2");
server2 = Undertow.builder().addHttpsListener(port + 2, DefaultServer.getHostAddress("default"), DefaultServer.getServerSslContext()).setServerOption(UndertowOptions.ENABLE_HTTP2, true).setSocketOption(Options.REUSE_ADDRESSES, true).setServerOption(UndertowOptions.NO_REQUEST_TIMEOUT, IDLE_TIMEOUT).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");
handler2.handleRequest(exchange);
}
}).build();
server1.start();
server2.start();
UndertowXnioSsl ssl = new UndertowXnioSsl(DefaultServer.getWorker().getXnio(), OptionMap.EMPTY, DefaultServer.SSL_BUFFER_POOL, DefaultServer.createClientSslContext());
DefaultServer.setRootHandler(new ProxyHandler(new LoadBalancingProxyClient().setConnectionsPerThread(4).addHost(new URI("https", null, DefaultServer.getHostAddress("default"), port + 1, null, null, null), "s1", ssl, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).addHost(new URI("https", null, DefaultServer.getHostAddress("default"), port + 2, null, null, null), "s2", ssl, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)), 10000, ResponseCodeHandler.HANDLE_404, false, false, 2));
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class PredicatedHandlersParserTestCase method testParsedHandler1.
@Test
public void testParsedHandler1() {
String value = "dump-request";
List<PredicatedHandler> ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
Assert.assertEquals(1, ret.size());
HttpHandler handler = ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
Assert.assertTrue(handler instanceof RequestDumpingHandler);
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class PreChunkedResponseTransferCodingTestCase method setup.
@BeforeClass
public static void setup() {
final BlockingHandler blockingHandler = new BlockingHandler();
DefaultServer.setRootHandler(blockingHandler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
try {
if (connection == null) {
connection = exchange.getConnection();
} else if (!DefaultServer.isAjp() && !DefaultServer.isProxy() && connection != exchange.getConnection()) {
final OutputStream outputStream = exchange.getOutputStream();
outputStream.write("Connection not persistent".getBytes());
outputStream.close();
return;
}
exchange.getResponseHeaders().put(Headers.TRANSFER_ENCODING, Headers.CHUNKED.toString());
exchange.putAttachment(HttpAttachments.PRE_CHUNKED_RESPONSE, true);
new StringWriteChannelListener(chunkedMessage).setup(exchange.getResponseChannel());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class SimpleConfidentialRedirectTestCase method setup.
@BeforeClass
public static void setup() throws IOException {
DefaultServer.startSSLServer();
HttpHandler current = new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(HttpString.tryFromString("scheme"), exchange.getRequestScheme());
exchange.getResponseHeaders().put(HttpString.tryFromString("uri"), exchange.getRequestURI());
exchange.endExchange();
}
};
current = new SinglePortConfidentialityHandler(current, DefaultServer.getHostSSLPort("default"));
DefaultServer.setRootHandler(current);
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class SsoTestCase method setup.
@BeforeClass
public static void setup() {
final SingleSignOnAuthenticationMechanism sso = new SingleSignOnAuthenticationMechanism(new InMemorySingleSignOnManager());
final PathHandler path = new PathHandler();
HttpHandler current = new ResponseHandler();
current = new AuthenticationCallHandler(current);
current = new AuthenticationConstraintHandler(current);
List<AuthenticationMechanism> mechs = new ArrayList<>();
mechs.add(sso);
mechs.add(new BasicAuthenticationMechanism("Test Realm"));
current = new AuthenticationMechanismsHandler(current, mechs);
current = new NotificationReceiverHandler(current, Collections.<NotificationReceiver>singleton(auditReceiver));
current = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, identityManager, current);
path.addPrefixPath("/test1", current);
current = new ResponseHandler();
current = new AuthenticationCallHandler(current);
current = new AuthenticationConstraintHandler(current);
mechs = new ArrayList<>();
mechs.add(sso);
mechs.add(new FormAuthenticationMechanism("form", "/login", "/error"));
current = new AuthenticationMechanismsHandler(current, mechs);
current = new NotificationReceiverHandler(current, Collections.<NotificationReceiver>singleton(auditReceiver));
current = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, identityManager, current);
path.addPrefixPath("/test2", current);
path.addPrefixPath("/login", new ResponseCodeHandler(StatusCodes.UNAUTHORIZED));
DefaultServer.setRootHandler(new SessionAttachmentHandler(path, new InMemorySessionManager(""), new SessionCookieConfig()));
}
Aggregations