use of io.undertow.Undertow in project undertow by undertow-io.
the class TLS13HalfCloseHangTestCase method testHang.
@Test
public void testHang() throws IOException, GeneralSecurityException, InterruptedException {
SSLContext clientSslContext = null;
try {
clientSslContext = DefaultServer.createClientSslContext("TLSv1.3");
} catch (Throwable e) {
// Don't try to run test if TLS 1.3 is not supported
Assume.assumeNoException(e);
}
Undertow server = Undertow.builder().addHttpsListener(0, "localhost", DefaultServer.getServerSslContext()).setHandler((exchange) -> {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Hello World!\n");
}).setSocketOption(Options.SSL_ENABLED_PROTOCOLS, Sequence.of("TLSv1.3")).setIoThreads(1).setWorkerThreads(1).build();
server.start();
InetSocketAddress address = (InetSocketAddress) server.getListenerInfo().get(0).getAddress();
String uri = "https://localhost:" + address.getPort() + "/foo";
doRequest(clientSslContext, address);
doRequest(clientSslContext, address);
server.stop();
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {
}
}
use of io.undertow.Undertow in project undertow by undertow-io.
the class ChatServer method main.
public static void main(final String[] args) {
System.out.println("To see chat in action is to open two different browsers and point them at http://localhost:8080");
Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path().addPrefixPath("/myapp", websocket(new WebSocketConnectionCallback() {
@Override
public void onConnect(WebSocketHttpExchange exchange, WebSocketChannel channel) {
channel.getReceiveSetter().set(new AbstractReceiveListener() {
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) {
final String messageData = message.getData();
for (WebSocketChannel session : channel.getPeerConnections()) {
WebSockets.sendText(messageData, session, null);
}
}
});
channel.resumeReceives();
}
})).addPrefixPath("/", resource(new ClassPathResourceManager(ChatServer.class.getClassLoader(), ChatServer.class.getPackage())).addWelcomeFiles("index.html"))).build();
server.start();
}
use of io.undertow.Undertow in project indy by Commonjava.
the class IndyDeployer method buildAndStartUndertow.
private Undertow buildAndStartUndertow(DeploymentManager dm, Integer port, String bind, RestConfig restConfig) throws Exception {
Undertow.Builder builder = Undertow.builder().setServerOption(UndertowOptions.ENABLE_HTTP2, true).setHandler(getGzipEncodeHandler(dm)).addHttpListener(port, bind);
restConfig.configureBuilder(builder);
Undertow t = builder.build();
t.start();
return t;
}
use of io.undertow.Undertow in project indy by Commonjava.
the class IndyDeployer method getGzipEncodeHandler.
private EncodingHandler getGzipEncodeHandler(final DeploymentManager dm) throws ServletException {
// FROM: https://stackoverflow.com/questions/28295752/compressing-undertow-server-responses#28329810
final Predicate sizePredicate = Predicates.parse("max-content-size[" + Long.toString(5 * 1024) + "]");
// For firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=610679
final Predicate fileTypePredicate = v -> {
final String path = v.getRequestPath();
return !NO_NEED_GZIPPED_CONTENT.contains(mimeTyper.getContentType(path).toLowerCase());
};
final Predicate mixePredicate = v -> sizePredicate.resolve(v) && fileTypePredicate.resolve(v);
EncodingHandler eh = new EncodingHandler(new ContentEncodingRepository().addEncodingHandler("gzip", new GzipEncodingProvider(), 50, mixePredicate)).setNext(dm.start());
// sizePredicate ) ).setNext( dm.start() );
return eh;
}
use of io.undertow.Undertow in project spring-boot by spring-projects.
the class UndertowWebServer method start.
@Override
public void start() throws WebServerException {
synchronized (this.monitor) {
if (this.started) {
return;
}
try {
if (!this.autoStart) {
return;
}
if (this.undertow == null) {
this.undertow = createUndertowServer();
}
this.undertow.start();
this.started = true;
String message = getStartLogMessage();
logger.info(message);
} catch (Exception ex) {
try {
PortInUseException.ifPortBindingException(ex, (bindException) -> {
List<Port> failedPorts = getConfiguredPorts();
failedPorts.removeAll(getActualPorts());
if (failedPorts.size() == 1) {
throw new PortInUseException(failedPorts.get(0).getNumber());
}
});
throw new WebServerException("Unable to start embedded Undertow", ex);
} finally {
stopSilently();
}
}
}
}
Aggregations