use of io.undertow.Undertow in project indy by Commonjava.
the class IndyDeployer method deploy.
@Override
public void deploy(BootOptions bootOptions) throws DeployException {
final DeploymentInfo di = indyDeployment.getDeployment(bootOptions.getContextPath()).setContextPath("/");
final DeploymentManager dm = Servlets.defaultContainer().addDeployment(di);
Collection<String> list = Servlets.defaultContainer().listDeployments();
logger.info("List deployments: {}", list);
dm.deploy();
try {
Integer port = bootOptions.getPort();
if (port < 1) {
logger.info("Looking for open Undertow port...");
final AtomicReference<Exception> errorHolder = new AtomicReference<>();
final AtomicReference<Integer> usingPort = new AtomicReference<>();
server = PortFinder.findPortFor(16, (foundPort) -> {
usingPort.set(foundPort);
try {
return buildAndStartUndertow(dm, foundPort, bootOptions.getBind(), restConfig);
} catch (Exception e) {
errorHolder.set(e);
}
return null;
});
Exception e = errorHolder.get();
if (e != null) {
throw e;
}
bootOptions.setPort(usingPort.get());
} else {
logger.info("Start Undertow server, bind: {}, port: {}", bootOptions.getBind(), port);
server = buildAndStartUndertow(dm, port, bootOptions.getBind(), restConfig);
}
logger.info("Indy listening on {}:{}\n\n", bootOptions.getBind(), bootOptions.getPort());
} catch (Exception e) {
logger.error("Deploy failed", e);
throw new DeployException("Deploy failed", e);
}
}
use of io.undertow.Undertow in project undertow by undertow-io.
the class AjpClientTestCase method beforeClass.
@BeforeClass
public static void beforeClass() throws IOException {
// Create xnio worker
worker = Xnio.getInstance().createWorker(null, DEFAULT_OPTIONS);
undertow = Undertow.builder().addListener(new Undertow.ListenerBuilder().setType(Undertow.ListenerType.AJP).setPort(AJP_PORT)).setHandler(new PathHandler().addExactPath(MESSAGE, AjpClientTestCase::sendMessage).addExactPath(POST, exchange -> exchange.getRequestReceiver().receiveFullString((exchange1, message) -> exchange1.getResponseSender().send(message)))).build();
undertow.start();
}
use of io.undertow.Undertow in project undertow by undertow-io.
the class StopTestCase method testStopUndertowAfterExceptionDuringStart.
@Test
public void testStopUndertowAfterExceptionDuringStart() {
// Making the NioXnioWorker constructor throw an exception, resulting in the Undertow.worker field not getting set.
Undertow undertow = Undertow.builder().setWorkerOption(Options.WORKER_IO_THREADS, -1).build();
try {
undertow.start();
} catch (RuntimeException ignore) {
}
undertow.stop();
}
use of io.undertow.Undertow in project undertow by undertow-io.
the class WebSocketServer method main.
public static void main(final String[] args) {
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) {
WebSockets.sendText(message.getData(), channel, null);
}
});
channel.resumeReceives();
}
})).addPrefixPath("/", resource(new ClassPathResourceManager(WebSocketServer.class.getClassLoader(), WebSocketServer.class.getPackage())).addWelcomeFiles("index.html"))).build();
server.start();
}
use of io.undertow.Undertow in project undertow by undertow-io.
the class ReverseProxyServer method main.
public static void main(final String[] args) {
try {
final Undertow server1 = Undertow.builder().addHttpListener(8081, "localhost").setHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Server1");
}
}).build();
server1.start();
final Undertow server2 = Undertow.builder().addHttpListener(8082, "localhost").setHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Server2");
}
}).build();
server2.start();
final Undertow server3 = Undertow.builder().addHttpListener(8083, "localhost").setHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Server3");
}
}).build();
server3.start();
LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient().addHost(new URI("http://localhost:8081")).addHost(new URI("http://localhost:8082")).addHost(new URI("http://localhost:8083")).setConnectionsPerThread(20);
Undertow reverseProxy = Undertow.builder().addHttpListener(8080, "localhost").setIoThreads(4).setHandler(ProxyHandler.builder().setProxyClient(loadBalancer).setMaxRequestTime(30000).build()).build();
reverseProxy.start();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
Aggregations