use of io.undertow.Undertow in project indy by Commonjava.
the class JaxRsBooter method deploy.
@Override
public boolean deploy() {
boolean started;
final IndyDeployment indyDeployment = container.instance().select(IndyDeployment.class).get();
final DeploymentInfo di = indyDeployment.getDeployment(bootOptions.getContextPath()).setContextPath("/");
final DeploymentManager dm = Servlets.defaultContainer().addDeployment(di);
dm.deploy();
status = new BootStatus();
try {
Integer port = bootOptions.getPort();
if (port < 1) {
System.out.println("Looking for open port...");
final ThreadLocal<ServletException> errorHolder = new ThreadLocal<>();
ThreadLocal<Integer> usingPort = new ThreadLocal<>();
server = PortFinder.findPortFor(16, (foundPort) -> {
Undertow undertow = null;
try {
undertow = Undertow.builder().setHandler(dm.start()).addHttpListener(foundPort, bootOptions.getBind()).build();
undertow.start();
usingPort.set(foundPort);
} catch (ServletException e) {
errorHolder.set(e);
}
return undertow;
});
ServletException e = errorHolder.get();
if (e != null) {
throw e;
}
bootOptions.setPort(usingPort.get());
} else {
server = Undertow.builder().setHandler(dm.start()).addHttpListener(port, bootOptions.getBind()).build();
server.start();
}
System.out.println("Using: " + bootOptions.getPort());
status.markSuccess();
started = true;
System.out.printf("Indy listening on %s:%s\n\n", bootOptions.getBind(), bootOptions.getPort());
} catch (ServletException | RuntimeException e) {
status.markFailed(ERR_CANT_LISTEN, e);
started = false;
}
return started;
}
use of io.undertow.Undertow in project cxf by apache.
the class UndertowHTTPServerEngine method createServer.
private Undertow createServer(URL url, UndertowHTTPHandler undertowHTTPHandler) throws Exception {
Undertow.Builder result = Undertow.builder();
result.setServerOption(UndertowOptions.IDLE_TIMEOUT, getMaxIdleTime());
if (tlsServerParameters != null) {
if (this.sslContext == null) {
this.sslContext = createSSLContext();
}
result = result.addHttpsListener(getPort(), getHost(), this.sslContext);
} else {
result = result.addHttpListener(getPort(), getHost());
}
path = Handlers.path(new NotFoundHandler());
if (url.getPath().length() == 0) {
result = result.setHandler(Handlers.trace(undertowHTTPHandler));
} else {
if (undertowHTTPHandler.isContextMatchExact()) {
path.addExactPath(url.getPath(), undertowHTTPHandler);
} else {
path.addPrefixPath(url.getPath(), undertowHTTPHandler);
}
result = result.setHandler(wrapHandler(path));
}
result = decorateUndertowSocketConnection(result);
result = disableSSLv3(result);
result = configureThreads(result);
return result.build();
}
use of io.undertow.Undertow in project mxgwd by kamax-io.
the class UndertowApp method main.
public static void main(String[] args) throws IOException {
String cfgFile = StringUtils.defaultIfBlank(System.getenv("MXGWD_CONFIG_FILE"), "mxgwd.yaml");
Config cfg = Value.get(YamlConfigLoader.loadFromFile(cfgFile), Config::new);
Gateway gw = new Gateway(cfg);
CatchAllHandler allHandler = new CatchAllHandler(gw);
ActivePoliciesListingHandler activePolicies = new ActivePoliciesListingHandler(gw);
Undertow server = Undertow.builder().addHttpListener(cfg.getServer().getPort(), "0.0.0.0").setHandler(Handlers.path().addExactPath("/_matrix/client/r0/policy/policies", activePolicies).addPrefixPath("/", allHandler)).build();
server.start();
}
use of io.undertow.Undertow in project runwar by cfmlprojects.
the class Start method main.
public static void main(String[] args) throws Exception {
System.setProperty("log4j.configuration", "log4j.filelog.xml");
ServerOptions serverOptions = CommandLineHandler.parseLogArguments(args);
LoggerFactory.init(serverOptions);
if (args.length == 0) {
if (new File("server.json").exists()) {
serverOptions = new ConfigParser(new File("server.json")).getServerOptions();
} else {
// print usage
serverOptions = CommandLineHandler.parseArguments(args);
}
} else {
serverOptions = CommandLineHandler.parseArguments(args);
}
if (serverOptions.getLoadBalance() != null && serverOptions.getLoadBalance().length > 0) {
final List<String> balanceHosts = new ArrayList<String>();
RunwarLogger.LOG.info("Initializing...");
final LoadBalancingProxyClient loadBalancer = new LoadBalancingProxyClient();
for (String balanceHost : serverOptions.getLoadBalance()) {
if (serverOptions.getWarFile() != null) {
RunwarLogger.LOG.info("Starting instance of " + serverOptions.getWarFile().getParent() + "...");
launchServer(balanceHost, serverOptions);
}
loadBalancer.addHost(new URI(balanceHost));
balanceHosts.add(balanceHost);
RunwarLogger.LOG.info("Added balanced host: " + balanceHost);
Thread.sleep(3000);
}
int port = serverOptions.getPortNumber();
loadBalancer.setConnectionsPerThread(20);
RunwarLogger.LOG.info("Hosts loaded");
RunwarLogger.LOG.info("Starting load balancer on 127.0.0.1 port " + port + "...");
ProxyHandler proxyHandler = ProxyHandler.builder().setProxyClient(loadBalancer).setMaxRequestTime(30000).setNext(ResponseCodeHandler.HANDLE_404).build();
Undertow reverseProxy = Undertow.builder().addHttpListener(port, "localhost").setIoThreads(4).setHandler(proxyHandler).build();
reverseProxy.start();
RunwarLogger.LOG.info("View balancer admin on http://127.0.0.1:9080");
Undertow adminServer = Undertow.builder().addHttpListener(9080, "localhost").setHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html");
if (exchange.getQueryParameters().get("addHost") != null) {
String balanceHost = URLDecoder.decode(exchange.getQueryParameters().get("addHost").toString(), "UTF-8");
balanceHost = balanceHost.replaceAll("]|\\[", "");
loadBalancer.addHost(new URI(balanceHost));
balanceHosts.add(balanceHost);
}
if (exchange.getQueryParameters().get("removeHost") != null) {
String balanceHost = URLDecoder.decode(exchange.getQueryParameters().get("removeHost").toString(), "UTF-8");
balanceHost = balanceHost.replaceAll("]|\\[", "");
loadBalancer.removeHost(new URI(balanceHost));
balanceHosts.remove(balanceHost);
}
String response = "";
// response += URLDecoder.decode(exchange.getQueryString(),"UTF-8");
for (String balanceHost : balanceHosts) {
String[] schemeHostAndPort = balanceHost.split(":");
String host = schemeHostAndPort[1].replaceAll("^//", "");
int port = schemeHostAndPort.length > 2 ? Integer.parseInt(schemeHostAndPort[2]) : 80;
response += balanceHost + " <a href='?removeHost=" + balanceHost + "'>remove</a> Listening: " + serverListening(host, port) + "<br/>";
}
exchange.getResponseSender().send("<h3>Balanced Hosts</h3><form action='?'> Add Host:<input type='text' name='addHost' placeholder='http://127.0.0.1:7070'><input type='submit'></form>" + response);
}
}).build();
adminServer.start();
RunwarLogger.LOG.info("Started load balancer.");
} else {
Server server = new Server();
try {
server.startServer(serverOptions);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
use of io.undertow.Undertow in project tutorials by eugenp.
the class FileServer method main.
public static void main(String[] args) {
Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(resource(new PathResourceManager(Paths.get(System.getProperty("user.home")), 100)).setDirectoryListingEnabled(true)).build();
server.start();
}
Aggregations