提交 cff7158b authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved error detection when starting a server with invalid arguments, such as…

Improved error detection when starting a server with invalid arguments, such as "-tcpPort=9091" or "-tcpPort 9091" (as one parameter) instead of "-tcpPort", "9091".
上级 703851a3
......@@ -30,6 +30,7 @@ import org.h2.util.JdbcUtils;
import org.h2.util.NetUtils;
import org.h2.util.New;
import org.h2.util.StringUtils;
import org.h2.util.Tool;
/**
* The TCP server implements the native H2 database server protocol.
......@@ -162,24 +163,24 @@ public class TcpServer implements Service {
port = Constants.DEFAULT_TCP_PORT;
for (int i = 0; args != null && i < args.length; i++) {
String a = args[i];
if ("-trace".equals(a)) {
if (Tool.isOption(a, "-trace")) {
trace = true;
} else if ("-tcpSSL".equals(a)) {
} else if (Tool.isOption(a, "-tcpSSL")) {
ssl = true;
} else if ("-tcpPort".equals(a)) {
} else if (Tool.isOption(a, "-tcpPort")) {
port = Integer.decode(args[++i]);
} else if ("-tcpPassword".equals(a)) {
} else if (Tool.isOption(a, "-tcpPassword")) {
managementPassword = args[++i];
} else if ("-baseDir".equals(a)) {
} else if (Tool.isOption(a, "-baseDir")) {
baseDir = args[++i];
} else if ("-key".equals(a)) {
} else if (Tool.isOption(a, "-key")) {
key = args[++i];
keyDatabase = args[++i];
} else if ("-tcpAllowOthers".equals(a)) {
} else if (Tool.isOption(a, "-tcpAllowOthers")) {
allowOthers = true;
} else if ("-tcpDaemon".equals(a)) {
} else if (Tool.isOption(a, "-tcpDaemon")) {
isDaemon = true;
} else if ("-ifExists".equals(a)) {
} else if (Tool.isOption(a, "-ifExists")) {
ifExists = true;
}
}
......
......@@ -23,6 +23,7 @@ import org.h2.engine.Constants;
import org.h2.server.Service;
import org.h2.util.NetUtils;
import org.h2.util.New;
import org.h2.util.Tool;
/**
* This class implements a subset of the PostgreSQL protocol as described here:
......@@ -84,17 +85,17 @@ public class PgServer implements Service {
port = DEFAULT_PORT;
for (int i = 0; args != null && i < args.length; i++) {
String a = args[i];
if ("-trace".equals(a)) {
if (Tool.isOption(a, "-trace")) {
trace = true;
} else if ("-pgPort".equals(a)) {
} else if (Tool.isOption(a, "-pgPort")) {
port = Integer.decode(args[++i]);
} else if ("-baseDir".equals(a)) {
} else if (Tool.isOption(a, "-baseDir")) {
baseDir = args[++i];
} else if ("-pgAllowOthers".equals(a)) {
} else if (Tool.isOption(a, "-pgAllowOthers")) {
allowOthers = true;
} else if ("-pgDaemon".equals(a)) {
} else if (Tool.isOption(a, "-pgDaemon")) {
isDaemon = true;
} else if ("-ifExists".equals(a)) {
} else if (Tool.isOption(a, "-ifExists")) {
ifExists = true;
}
}
......
......@@ -33,6 +33,7 @@ import org.h2.message.TraceSystem;
import org.h2.server.Service;
import org.h2.server.ShutdownHandler;
import org.h2.util.StringUtils;
import org.h2.util.Tool;
import org.h2.util.Utils;
import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils;
......@@ -272,23 +273,23 @@ public class WebServer implements Service {
allowOthers = SortedProperties.getBooleanProperty(prop, "webAllowOthers", false);
for (int i = 0; args != null && i < args.length; i++) {
String a = args[i];
if ("-webPort".equals(a)) {
if (Tool.isOption(a, "-webPort")) {
port = Integer.decode(args[++i]);
} else if ("-webSSL".equals(a)) {
} else if (Tool.isOption(a, "-webSSL")) {
ssl = true;
} else if ("-webAllowOthers".equals(a)) {
} else if (Tool.isOption(a, "-webAllowOthers")) {
allowOthers = true;
} else if ("-webDaemon".equals(a)) {
} else if (Tool.isOption(a, "-webDaemon")) {
isDaemon = true;
} else if ("-baseDir".equals(a)) {
} else if (Tool.isOption(a, "-baseDir")) {
String baseDir = args[++i];
SysProperties.setBaseDir(baseDir);
} else if ("-ifExists".equals(a)) {
} else if (Tool.isOption(a, "-ifExists")) {
ifExists = true;
} else if ("-properties".equals(args[i])) {
} else if (Tool.isOption(a, "-properties")) {
// already set
i++;
} else if ("-trace".equals(a)) {
} else if (Tool.isOption(a, "-trace")) {
trace = true;
}
}
......
......@@ -11,6 +11,7 @@ import java.io.IOException;
import java.io.PrintStream;
import java.sql.SQLException;
import java.util.Properties;
import org.h2.message.DbException;
import org.h2.store.FileLister;
/**
......@@ -99,4 +100,22 @@ public abstract class Tool {
out.println("See also http://h2database.com/javadoc/" + className.replace('.', '/') + ".html");
}
/**
* Check if the argument matches the option.
* If the argument starts with this option, but doesn't match,
* then an exception is thrown.
*
* @param arg the argument
* @param the option
* @return true if it matches
*/
public static boolean isOption(String arg, String option) {
if (arg.equals(option)) {
return true;
} else if (arg.startsWith(option)) {
throw DbException.getUnsupportedException("expected: " + option + " got: " + arg);
}
return false;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论