* configclients.jsp: Add start button for clients and webapps.

This commit is contained in:
zzz
2008-06-20 20:20:50 +00:00
parent f3d73a6c15
commit dc68ebbaeb
4 changed files with 74 additions and 16 deletions

View File

@ -1,5 +1,6 @@
package net.i2p.router.web;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -9,8 +10,12 @@ import java.util.Set;
import net.i2p.data.DataFormatException;
import net.i2p.router.startup.ClientAppConfig;
import net.i2p.router.startup.LoadClientAppsJob;
import net.i2p.util.Log;
import org.mortbay.http.HttpListener;
import org.mortbay.jetty.Server;
/**
* Saves changes to clients.config or webapps.config
*/
@ -18,13 +23,25 @@ public class ConfigClientsHandler extends FormHandler {
private Log _log;
private Map _settings;
public ConfigClientsHandler() {}
public ConfigClientsHandler() {
_log = ContextHelper.getContext(null).logManager().getLog(ConfigClientsHandler.class);
}
protected void processForm() {
if (_action.startsWith("Save Client")) {
saveClientChanges();
} else if (_action.startsWith("Save WebApp")) {
saveWebAppChanges();
} else if (_action.startsWith("Start ")) {
String app = _action.substring(6);
int appnum = -1;
try {
appnum = Integer.parseInt(app);
} catch (NumberFormatException nfe) {}
if (appnum >= 0)
startClient(appnum);
else
startWebApp(app);
} else {
addFormError("Unsupported " + _action);
}
@ -44,6 +61,17 @@ public class ConfigClientsHandler extends FormHandler {
addFormNotice("Client configuration saved successfully - restart required to take effect");
}
private void startClient(int i) {
List clients = ClientAppConfig.getClientApps(_context);
if (i >= clients.size()) {
addFormError("Bad client index");
return;
}
ClientAppConfig ca = (ClientAppConfig) clients.get(i);
LoadClientAppsJob.runClient(ca.className, ca.clientName, LoadClientAppsJob.parseArgs(ca.args), _log);
addFormNotice("Client " + ca.clientName + " started");
}
private void saveWebAppChanges() {
Properties props = RouterConsoleRunner.webAppProperties();
Set keys = props.keySet();
@ -60,4 +88,28 @@ public class ConfigClientsHandler extends FormHandler {
RouterConsoleRunner.storeWebAppProperties(props);
addFormNotice("WebApp configuration saved successfully - restart required to take effect");
}
// Big hack for the moment, not using properties for directory and port
// Go through all the Jetty servers, find the one serving port 7657,
// requested and add the .war to that one
private void startWebApp(String app) {
Collection c = Server.getHttpServers();
for (int i = 0; i < c.size(); i++) {
Server s = (Server) c.toArray()[i];
HttpListener[] hl = s.getListeners();
for (int j = 0; j < hl.length; j++) {
if (hl[j].getPort() == 7657) {
try {
s.addWebApplication("/"+ app, "./webapps/" + app + ".war").start();
// no passwords... initialize(wac);
addFormNotice("WebApp " + app + " started");
} catch (Exception ioe) {
addFormError("Failed to start " + app + " " + ioe);
}
return;
}
}
}
addFormError("Failed to find server");
}
}

View File

@ -29,7 +29,7 @@ public class ConfigClientsHelper {
public String getForm1() {
StringBuffer buf = new StringBuffer(1024);
buf.append("<table border=\"1\">\n");
buf.append("<tr><td>Client</td><td>Enabled?</td><td>Class and arguments</td></tr>\n");
buf.append("<tr><td>Client</td><td>Run at Startup?</td><td>Start Now</td><td>Class and arguments</td></tr>\n");
List clients = ClientAppConfig.getClientApps(_context);
for (int cur = 0; cur < clients.size(); cur++) {
@ -44,7 +44,7 @@ public class ConfigClientsHelper {
public String getForm2() {
StringBuffer buf = new StringBuffer(1024);
buf.append("<table border=\"1\">\n");
buf.append("<tr><td>WebApp</td><td>Enabled?</td><td>Description</td></tr>\n");
buf.append("<tr><td>WebApp</td><td>Run at Startup?</td><td>Start Now</td><td>Description</td></tr>\n");
Properties props = RouterConsoleRunner.webAppProperties();
Set keys = new TreeSet(props.keySet());
for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
@ -75,6 +75,10 @@ public class ConfigClientsHelper {
if (ro)
buf.append("disabled=\"true\" ");
}
buf.append("/><td>").append(desc).append("</td></tr>\n");
buf.append("/></td><td>&nbsp");
if (!enabled) {
buf.append("<button type=\"submit\" name=\"action\" value=\"Start ").append(index).append("\" />Start</button>");
}
buf.append("&nbsp</td><td>").append(desc).append("</td></tr>\n");
}
}