use of runwar.options.ServerOptions 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 runwar.options.ServerOptions in project runwar by cfmlprojects.
the class StartStopTest method testAliasMapProcessed.
@Test
public void testAliasMapProcessed() {
ServerOptions serverOptions = new ServerOptionsImpl();
serverOptions.setWarFile(new File(DefaultServer.SIMPLEWARPATH)).setDebug(true).setBackground(false).setTrayEnabled(false);
Server server = new Server();
try {
server.startServer(serverOptions);
} catch (Exception e) {
e.printStackTrace();
}
try {
Stop.stopServer(serverOptions, false);
} catch (Exception e) {
e.printStackTrace();
}
}
use of runwar.options.ServerOptions in project runwar by cfmlprojects.
the class Tray method hookTray.
public static void hookTray(final Server server) {
if (trayIsHooked) {
return;
}
SystemTray.AUTO_SIZE = true;
SystemTray.FORCE_GTK2 = true;
System.setProperty("SWT_GTK3", "0");
// SystemTray.FORCE_TRAY_TYPE = TrayType.;
if (GraphicsEnvironment.isHeadless()) {
RunwarLogger.LOG.debug("Server is in headless mode, System Tray is not supported");
return;
}
try {
RunwarLogger.LOG.trace("Initializing tray");
systemTray = SystemTray.get();
RunwarLogger.LOG.trace("Initialized");
} catch (java.lang.ExceptionInInitializerError e) {
RunwarLogger.LOG.debugf("Error initializing tray: %s", e.getMessage());
}
if (systemTray == null) {
RunwarLogger.LOG.warn("System Tray is not supported");
return;
}
ServerOptions serverOptions = Server.getServerOptions();
String iconImage = serverOptions.getIconImage();
String host = serverOptions.getHost();
int portNumber = serverOptions.getPortNumber();
final int stopSocket = serverOptions.getSocketNumber();
String processName = serverOptions.getProcessName();
String PID = server.getPID();
String warpath = serverOptions.getWarPath();
final String statusText = processName + " server on " + host + ":" + portNumber + " PID:" + PID;
variableMap = new HashMap<String, String>();
variableMap.put("defaultTitle", statusText);
variableMap.put("webroot", warpath);
variableMap.put("runwar.port", Integer.toString(portNumber));
variableMap.put("runwar.processName", processName);
variableMap.put("runwar.PID", PID);
variableMap.put("runwar.host", host);
variableMap.put("runwar.stopsocket", Integer.toString(stopSocket));
String trayConfigJSON;
if (serverOptions.getTrayConfig() != null) {
trayConfigJSON = readFile(serverOptions.getTrayConfig());
} else {
trayConfigJSON = getResourceAsString("runwar/taskbar.json");
}
instantiateMenu(trayConfigJSON, statusText, iconImage, variableMap, server);
trayIsHooked = true;
}
Aggregations