use of org.h2.tools.Server in project h2database by h2database.
the class TestFtp method test.
private void test(String dir) throws Exception {
Server server = FtpServer.createFtpServer("-ftpDir", dir, "-ftpPort", "8121").start();
FtpServer ftp = (FtpServer) server.getService();
ftp.setEventListener(this);
FtpClient client = FtpClient.open("localhost:8121");
client.login("sa", "sa");
client.makeDirectory("ftp");
client.changeWorkingDirectory("ftp");
assertEquals("CWD", lastEvent.getCommand());
client.makeDirectory("hello");
client.changeWorkingDirectory("hello");
client.changeDirectoryUp();
assertEquals("CDUP", lastEvent.getCommand());
client.nameList("hello");
client.removeDirectory("hello");
client.close();
server.stop();
}
use of org.h2.tools.Server in project h2database by h2database.
the class TestAutoReconnect method testWrongUrl.
private void testWrongUrl() throws Exception {
deleteDb(getTestName());
Server tcp = Server.createTcpServer().start();
try {
conn = getConnection("jdbc:h2:" + getBaseDir() + "/" + getTestName() + ";AUTO_SERVER=TRUE");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).getConnection("jdbc:h2:" + getBaseDir() + "/" + getTestName() + ";OPEN_NEW=TRUE");
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).getConnection("jdbc:h2:" + getBaseDir() + "/" + getTestName() + ";OPEN_NEW=TRUE");
conn.close();
conn = getConnection("jdbc:h2:tcp://localhost/" + getBaseDir() + "/" + getTestName());
assertThrows(ErrorCode.DATABASE_ALREADY_OPEN_1, this).getConnection("jdbc:h2:" + getBaseDir() + "/" + getTestName() + ";AUTO_SERVER=TRUE;OPEN_NEW=TRUE");
conn.close();
} finally {
tcp.stop();
}
}
use of org.h2.tools.Server in project traccar by traccar.
the class ConsoleServlet method init.
@Override
public void init() {
super.init();
try {
Field field = WebServlet.class.getDeclaredField("server");
field.setAccessible(true);
org.h2.server.web.WebServer server = (org.h2.server.web.WebServer) field.get(this);
ConnectionInfo connectionInfo = new ConnectionInfo("Traccar|" + Context.getConfig().getString("database.driver") + "|" + Context.getConfig().getString("database.url") + "|" + Context.getConfig().getString("database.user"));
Method method;
method = org.h2.server.web.WebServer.class.getDeclaredMethod("updateSetting", ConnectionInfo.class);
method.setAccessible(true);
method.invoke(server, connectionInfo);
method = org.h2.server.web.WebServer.class.getDeclaredMethod("setAllowOthers", boolean.class);
method.setAccessible(true);
method.invoke(server, true);
} catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
Log.warning(e);
}
}
use of org.h2.tools.Server in project h2database by h2database.
the class MixedMode method main.
/**
* This method is called when executing this sample application from the
* command line.
*
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
// start the server, allows to access the database remotely
Server server = Server.createTcpServer("-tcpPort", "9081");
server.start();
System.out.println("You can access the database remotely now, using the URL:");
System.out.println("jdbc:h2:tcp://localhost:9081/~/test (user: sa, password: sa)");
// now use the database in your application in embedded mode
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "sa");
// some simple 'business usage'
Statement stat = conn.createStatement();
stat.execute("DROP TABLE TIMER IF EXISTS");
stat.execute("CREATE TABLE TIMER(ID INT PRIMARY KEY, TIME VARCHAR)");
System.out.println("Execute this a few times: " + "SELECT TIME FROM TIMER");
System.out.println("To stop this application " + "(and the server), run: DROP TABLE TIMER");
try {
while (true) {
// runs forever, except if you drop the table remotely
stat.execute("MERGE INTO TIMER VALUES(1, NOW())");
Thread.sleep(1000);
}
} catch (SQLException e) {
System.out.println("Error: " + e.toString());
}
conn.close();
// stop the server
server.stop();
}
use of org.h2.tools.Server in project h2database by h2database.
the class TestTools method testSSL.
private void testSSL() throws SQLException {
String result;
Connection conn;
try {
result = runServer(0, new String[] { "-tcp", "-tcpAllowOthers", "-tcpPort", "9001", "-tcpPassword", "abcdef", "-tcpSSL" });
assertContains(result, "ssl://");
assertContains(result, ":9001");
assertContains(result, "others can");
assertTrue(result.indexOf("Starts the H2 Console") < 0);
conn = getConnection("jdbc:h2:ssl://localhost:9001/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[] { "-tcpShutdown", "ssl://localhost:9001", "-tcpPassword", "abcdef" });
assertContains(result, "Shutting down");
assertThrows(ErrorCode.CONNECTION_BROKEN_1, this).getConnection("jdbc:h2:ssl://localhost:9001/mem:", "sa", "sa");
result = runServer(0, new String[] { "-web", "-webPort", "9002", "-webAllowOthers", "-webSSL", "-pg", "-pgAllowOthers", "-pgPort", "9003", "-tcp", "-tcpAllowOthers", "-tcpPort", "9006", "-tcpPassword", "abc" });
Server stop = server;
assertContains(result, "https://");
assertContains(result, ":9002");
assertContains(result, "pg://");
assertContains(result, ":9003");
assertContains(result, "others can");
assertTrue(result.indexOf("only local") < 0);
assertContains(result, "tcp://");
assertContains(result, ":9006");
conn = getConnection("jdbc:h2:tcp://localhost:9006/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[] { "-tcpShutdown", "tcp://localhost:9006", "-tcpPassword", "abc", "-tcpShutdownForce" });
assertContains(result, "Shutting down");
stop.shutdown();
assertThrows(ErrorCode.CONNECTION_BROKEN_1, this).getConnection("jdbc:h2:tcp://localhost:9006/mem:", "sa", "sa");
} finally {
shutdownServers();
}
}
Aggregations