use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class ComplexSSLTestCase method testSslLotsOfData.
@Test
public void testSslLotsOfData() throws IOException, GeneralSecurityException, URISyntaxException {
DefaultServer.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
if (exchange.isInIoThread()) {
exchange.dispatch(this);
return;
}
exchange.startBlocking();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[100];
int res = 0;
while ((res = exchange.getInputStream().read(buf)) > 0) {
out.write(buf, 0, res);
}
System.out.println("WRITE " + out.size());
exchange.getOutputStream().write(out.toByteArray());
System.out.println("DONE " + out.size());
}
});
DefaultServer.startSSLServer();
TestHttpClient client = new TestHttpClient();
client.setSSLContext(DefaultServer.getClientSSLContext());
try {
generateMessage(1000000);
HttpPost post = new HttpPost(DefaultServer.getDefaultServerSSLAddress());
post.setEntity(new StringEntity(message));
HttpResponse resultList = client.execute(post);
Assert.assertEquals(StatusCodes.OK, resultList.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(resultList);
Assert.assertEquals(message.length(), response.length());
Assert.assertEquals(message, response);
generateMessage(100000);
post = new HttpPost(DefaultServer.getDefaultServerSSLAddress());
post.setEntity(new StringEntity(message));
resultList = client.execute(post);
Assert.assertEquals(StatusCodes.OK, resultList.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(resultList);
Assert.assertEquals(message.length(), response.length());
Assert.assertEquals(message, response);
} finally {
client.getConnectionManager().shutdown();
DefaultServer.stopSSLServer();
}
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class SimpleSSLTestCase method testNonPersistentConnections.
@Test
public void testNonPersistentConnections() throws IOException, GeneralSecurityException {
DefaultServer.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(HttpString.tryFromString("scheme"), exchange.getRequestScheme());
exchange.getResponseHeaders().put(Headers.CONNECTION, "close");
exchange.endExchange();
}
});
DefaultServer.startSSLServer();
TestHttpClient client = new TestHttpClient();
client.setSSLContext(DefaultServer.getClientSSLContext());
try {
for (int i = 0; i < 5; ++i) {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerSSLAddress());
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Header[] header = result.getHeaders("scheme");
Assert.assertEquals("https", header[0].getValue());
HttpClientUtils.readResponse(result);
}
} finally {
client.getConnectionManager().shutdown();
DefaultServer.stopSSLServer();
}
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class SimpleSSLTestCase method simpleSSLTestCase.
@Test
public void simpleSSLTestCase() throws IOException, GeneralSecurityException {
DefaultServer.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(HttpString.tryFromString("scheme"), exchange.getRequestScheme());
exchange.endExchange();
}
});
DefaultServer.startSSLServer();
TestHttpClient client = new TestHttpClient();
client.setSSLContext(DefaultServer.getClientSSLContext());
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerSSLAddress());
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Header[] header = result.getHeaders("scheme");
Assert.assertEquals("https", header[0].getValue());
} finally {
client.getConnectionManager().shutdown();
DefaultServer.stopSSLServer();
}
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class HTTP2ViaUpgradeTestCase method setup.
@BeforeClass
public static void setup() throws URISyntaxException {
final SessionCookieConfig sessionConfig = new SessionCookieConfig();
int port = DefaultServer.getHostPort("default");
server = Undertow.builder().addHttpListener(port + 1, DefaultServer.getHostAddress("default")).setServerOption(UndertowOptions.ENABLE_HTTP2, true).setSocketOption(Options.REUSE_ADDRESSES, true).setHandler(Handlers.header(new Http2UpgradeHandler(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");
exchange.getResponseSender().send(message);
}
}, "h2c", "h2c-17"), Headers.SEC_WEB_SOCKET_ACCEPT_STRING, //work around Netty bug, it assumes that every upgrade request that does not have this header is an old style websocket upgrade
"fake")).build();
server.start();
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class AuthenticationTestBase method setAuthenticationChain.
@Before
public void setAuthenticationChain() {
List<AuthenticationMechanism> testMechanisms = getTestMechanisms();
if (testMechanisms == null) {
return;
}
HttpHandler current = new ResponseHandler();
current = new AuthenticationCallHandler(current);
current = new AuthenticationConstraintHandler(current);
current = new AuthenticationMechanismsHandler(current, testMechanisms);
// Ensure empty on initialisation.
auditReceiver.takeNotifications();
current = new NotificationReceiverHandler(current, Collections.<NotificationReceiver>singleton(auditReceiver));
if (cachingRequired()) {
current = new CachedAuthenticatedSessionHandler(current);
}
current = new SecurityInitialHandler(AuthenticationMode.PRO_ACTIVE, identityManager, current);
setRootHandler(current);
}
Aggregations