Search in sources :

Example 1 with Console

use of org.h2.tools.Console in project felix by apache.

the class H2Activator method start.

@Override
public void start(BundleContext context) throws Exception {
    ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put("dataSourceName", "test");
    context.registerService(DataSource.class.getName(), ds, props);
    loadData(ds);
    // Register the H2 console servlet
    Dictionary<String, String> servletProps = new Hashtable<String, String>();
    servletProps.put("alias", "/h2");
    servletProps.put("init.webAllowOthers", "true");
    context.registerService(Servlet.class.getName(), new WebServlet(), servletProps);
}
Also used : WebServlet(org.h2.server.web.WebServlet) Hashtable(java.util.Hashtable) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Servlet(javax.servlet.Servlet) WebServlet(org.h2.server.web.WebServlet) DataSource(javax.sql.DataSource) JdbcDataSource(org.h2.jdbcx.JdbcDataSource)

Example 2 with Console

use of org.h2.tools.Console 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();
    }
}
Also used : Server(org.h2.tools.Server) Connection(java.sql.Connection)

Example 3 with Console

use of org.h2.tools.Console in project h2database by h2database.

the class TestTools method testConsole.

private void testConsole() throws Exception {
    String old = System.getProperty(SysProperties.H2_BROWSER);
    Console c = new Console();
    c.setOut(new PrintStream(new ByteArrayOutputStream()));
    try {
        // start including browser
        lastUrl = "-";
        System.setProperty(SysProperties.H2_BROWSER, "call:" + TestTools.class.getName() + ".openBrowser");
        c.runTool("-web", "-webPort", "9002", "-tool", "-browser", "-tcp", "-tcpPort", "9003", "-pg", "-pgPort", "9004");
        assertContains(lastUrl, ":9002");
        shutdownConsole(c);
        // check if starting the browser works
        c.runTool("-web", "-webPort", "9002", "-tool");
        lastUrl = "-";
        c.actionPerformed(new ActionEvent(this, 0, "console"));
        assertContains(lastUrl, ":9002");
        lastUrl = "-";
        // double-click prevention is 100 ms
        Thread.sleep(200);
        try {
            MouseEvent me = new MouseEvent(new Button(), 0, 0, 0, 0, 0, 0, false, MouseEvent.BUTTON1);
            c.mouseClicked(me);
            assertContains(lastUrl, ":9002");
            lastUrl = "-";
            // no delay - ignore because it looks like a double click
            c.mouseClicked(me);
            assertEquals("-", lastUrl);
            // open the window
            c.actionPerformed(new ActionEvent(this, 0, "status"));
            c.actionPerformed(new ActionEvent(this, 0, "exit"));
            // check if the service was stopped
            c.runTool("-webPort", "9002");
        } catch (HeadlessException e) {
        // ignore
        }
        shutdownConsole(c);
        // trying to use the same port for two services should fail,
        // but also stop the first service
        createClassProxy(c.getClass());
        assertThrows(ErrorCode.EXCEPTION_OPENING_PORT_2, c).runTool("-web", "-webPort", "9002", "-tcp", "-tcpPort", "9002");
        c.runTool("-web", "-webPort", "9002");
    } finally {
        if (old != null) {
            System.setProperty(SysProperties.H2_BROWSER, old);
        } else {
            System.clearProperty(SysProperties.H2_BROWSER);
        }
        shutdownConsole(c);
    }
}
Also used : PrintStream(java.io.PrintStream) MouseEvent(java.awt.event.MouseEvent) HeadlessException(java.awt.HeadlessException) Button(java.awt.Button) ActionEvent(java.awt.event.ActionEvent) Console(org.h2.tools.Console) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

Button (java.awt.Button)1 HeadlessException (java.awt.HeadlessException)1 ActionEvent (java.awt.event.ActionEvent)1 MouseEvent (java.awt.event.MouseEvent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Connection (java.sql.Connection)1 Hashtable (java.util.Hashtable)1 Servlet (javax.servlet.Servlet)1 DataSource (javax.sql.DataSource)1 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)1 WebServlet (org.h2.server.web.WebServlet)1 Console (org.h2.tools.Console)1 Server (org.h2.tools.Server)1