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

Server.openBrowser no longer writes to System.out directly if opening the URL failed.

上级 56fb3686
...@@ -253,7 +253,7 @@ public class WebServer implements Service { ...@@ -253,7 +253,7 @@ public class WebServer implements Service {
public void init(String... args) { public void init(String... args) {
// set the serverPropertiesDir, because it's used in loadProperties() // set the serverPropertiesDir, because it's used in loadProperties()
for (int i = 0; args != null && i < args.length; i++) { for (int i = 0; args != null && i < args.length; i++) {
if (args[i].equals("-properties")) { if ("-properties".equals(args[i])) {
serverPropertiesDir = args[++i]; serverPropertiesDir = args[++i];
} }
} }
...@@ -276,7 +276,7 @@ public class WebServer implements Service { ...@@ -276,7 +276,7 @@ public class WebServer implements Service {
SysProperties.setBaseDir(baseDir); SysProperties.setBaseDir(baseDir);
} else if ("-ifExists".equals(a)) { } else if ("-ifExists".equals(a)) {
ifExists = true; ifExists = true;
} else if (args[i].equals("-properties")) { } else if ("-properties".equals(args[i])) {
// already set // already set
i++; i++;
} else if ("-trace".equals(a)) { } else if ("-trace".equals(a)) {
...@@ -519,6 +519,9 @@ public class WebServer implements Service { ...@@ -519,6 +519,9 @@ public class WebServer implements Service {
private Properties loadProperties() { private Properties loadProperties() {
try { try {
if ("null".equals(serverPropertiesDir)) {
return new Properties();
}
return SortedProperties.loadProperties(serverPropertiesDir + "/" + Constants.SERVER_PROPERTIES_NAME); return SortedProperties.loadProperties(serverPropertiesDir + "/" + Constants.SERVER_PROPERTIES_NAME);
} catch (Exception e) { } catch (Exception e) {
TraceSystem.traceThrowable(e); TraceSystem.traceThrowable(e);
...@@ -595,9 +598,11 @@ public class WebServer implements Service { ...@@ -595,9 +598,11 @@ public class WebServer implements Service {
prop.setProperty(String.valueOf(len - i - 1), info.getString()); prop.setProperty(String.valueOf(len - i - 1), info.getString());
} }
} }
OutputStream out = IOUtils.openFileOutputStream(serverPropertiesDir + "/" + Constants.SERVER_PROPERTIES_NAME, false); if (!"null".equals(serverPropertiesDir)) {
prop.store(out, "H2 Server Properties"); OutputStream out = IOUtils.openFileOutputStream(serverPropertiesDir + "/" + Constants.SERVER_PROPERTIES_NAME, false);
out.close(); prop.store(out, "H2 Server Properties");
out.close();
}
} catch (Exception e) { } catch (Exception e) {
TraceSystem.traceThrowable(e); TraceSystem.traceThrowable(e);
} }
......
...@@ -170,7 +170,7 @@ ShutdownHandler { ...@@ -170,7 +170,7 @@ ShutdownHandler {
// because some people don't look at the output, // because some people don't look at the output,
// but are wondering why nothing happens // but are wondering why nothing happens
if (browserStart) { if (browserStart) {
Server.openBrowser(web.getURL()); openBrowser(web.getURL());
} }
if (tcpStart) { if (tcpStart) {
...@@ -421,12 +421,20 @@ ShutdownHandler { ...@@ -421,12 +421,20 @@ ShutdownHandler {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (lastOpen == 0 || lastOpen + 100 < now) { if (lastOpen == 0 || lastOpen + 100 < now) {
lastOpen = now; lastOpen = now;
Server.openBrowser(url); openBrowser(url);
} }
} }
} }
//## AWT end ## //## AWT end ##
private void openBrowser(String url) {
try {
Server.openBrowser(url);
} catch (Exception e) {
out.println(e.getMessage());
}
}
/** /**
* INTERNAL * INTERNAL
*/ */
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
*/ */
package org.h2.tools; package org.h2.tools;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -21,6 +20,7 @@ import org.h2.server.pg.PgServer; ...@@ -21,6 +20,7 @@ import org.h2.server.pg.PgServer;
import org.h2.server.web.WebServer; import org.h2.server.web.WebServer;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.util.Tool; import org.h2.util.Tool;
import org.h2.util.Utils;
/** /**
* Starts the H2 Console (web-) server, TCP, and PG server. * Starts the H2 Console (web-) server, TCP, and PG server.
...@@ -31,6 +31,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -31,6 +31,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
private Service service; private Service service;
private Server web, tcp, pg; private Server web, tcp, pg;
private ShutdownHandler shutdownHandler; private ShutdownHandler shutdownHandler;
private boolean started;
public Server() { public Server() {
// nothing to do // nothing to do
...@@ -95,7 +96,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -95,7 +96,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* <tr><td>[-pgPort &lt;port&gt;]</td> * <tr><td>[-pgPort &lt;port&gt;]</td>
* <td>The port (default: 5435)</td></tr> * <td>The port (default: 5435)</td></tr>
* <tr><td>[-properties "&lt;dir&gt;"]</td> * <tr><td>[-properties "&lt;dir&gt;"]</td>
* <td>The server properties directory (default: ~)</td></tr> * <td>Server properties (default: ~, disable: null)</td></tr>
* <tr><td>[-baseDir &lt;dir&gt;]</td> * <tr><td>[-baseDir &lt;dir&gt;]</td>
* <td>The base directory for H2 databases (all servers)</td></tr> * <td>The base directory for H2 databases (all servers)</td></tr>
* <tr><td>[-ifExists]</td> * <tr><td>[-ifExists]</td>
...@@ -140,8 +141,6 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -140,8 +141,6 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
// no parameters // no parameters
} else if ("-webPort".equals(arg)) { } else if ("-webPort".equals(arg)) {
i++; i++;
} else if ("-webScript".equals(arg)) {
i++;
} else { } else {
throwUnsupportedOption(arg); throwUnsupportedOption(arg);
} }
...@@ -221,7 +220,11 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -221,7 +220,11 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
// because some people don't look at the output, // because some people don't look at the output,
// but are wondering why nothing happens // but are wondering why nothing happens
if (browserStart) { if (browserStart) {
Server.openBrowser(web.getURL()); try {
openBrowser(web.getURL());
} catch (Exception e) {
out.println(e.getMessage());
}
} }
if (result != null) { if (result != null) {
throw result; throw result;
...@@ -269,7 +272,9 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -269,7 +272,9 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
*/ */
public String getStatus() { public String getStatus() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
if (isRunning(false)) { if (!started) {
buff.append("Not started");
} else if (isRunning(false)) {
buff.append(service.getType()). buff.append(service.getType()).
append(" server running on "). append(" server running on ").
append(service.getURL()). append(service.getURL()).
...@@ -344,6 +349,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -344,6 +349,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
*/ */
public Server start() throws SQLException { public Server start() throws SQLException {
try { try {
started = true;
service.start(); service.start();
Thread t = new Thread(this); Thread t = new Thread(this);
t.setDaemon(service.isDaemon()); t.setDaemon(service.isDaemon());
...@@ -404,6 +410,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -404,6 +410,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* Stops the server. * Stops the server.
*/ */
public void stop() { public void stop() {
started = false;
service.stop(); service.stop();
} }
...@@ -468,13 +475,16 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -468,13 +475,16 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* *
* @param url the URL to open * @param url the URL to open
*/ */
public static void openBrowser(String url) { public static void openBrowser(String url) throws Exception {
String osName = SysProperties.getStringSetting("os.name", "linux").toLowerCase();
Runtime rt = Runtime.getRuntime();
try { try {
String browser = SysProperties.BROWSER; String osName = SysProperties.getStringSetting("os.name", "linux").toLowerCase();
Runtime rt = Runtime.getRuntime();
String browser = System.getProperty(SysProperties.H2_BROWSER);
if (browser != null) { if (browser != null) {
if (browser.indexOf("%url") >= 0) { if (browser.startsWith("call:")) {
browser = browser.substring("call:".length());
Utils.callStaticMethod(browser, url);
} else if (browser.indexOf("%url") >= 0) {
String[] args = StringUtils.arraySplit(browser, ',', false); String[] args = StringUtils.arraySplit(browser, ',', false);
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
args[i] = StringUtils.replaceAll(args[i], "%url", url); args[i] = StringUtils.replaceAll(args[i], "%url", url);
...@@ -525,12 +535,11 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -525,12 +535,11 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
} }
if (!ok) { if (!ok) {
// No success in detection. // No success in detection.
System.out.println("Please open a browser and go to " + url); throw new Exception("Browser detection failed and system property " + SysProperties.H2_BROWSER + " not set");
} }
} }
} catch (IOException e) { } catch (Exception e) {
System.out.println("Failed to start a browser to open the URL " + url); throw new Exception("Failed to start a browser to open the URL " + url + ": " + e.getMessage());
e.printStackTrace();
} }
} }
...@@ -550,13 +559,13 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -550,13 +559,13 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
server.web = web; server.web = web;
webServer.setShutdownHandler(server); webServer.setShutdownHandler(server);
String url = webServer.addSession(conn); String url = webServer.addSession(conn);
Server.openBrowser(url); try {
while (!webServer.isStopped()) { Server.openBrowser(url);
try { while (!webServer.isStopped()) {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
} }
} catch (Exception e) {
// ignore
} }
} }
......
...@@ -6,14 +6,22 @@ ...@@ -6,14 +6,22 @@
*/ */
package org.h2.test.server; package org.h2.test.server;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.sql.Connection;
import org.h2.constant.SysProperties;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.Server; import org.h2.tools.Server;
import org.h2.util.Task;
/** /**
* Tests the H2 Console application. * Tests the H2 Console application.
*/ */
public class TestWeb extends TestBase { public class TestWeb extends TestBase {
private static volatile String lastUrl;
/** /**
* Run just this test. * Run just this test.
* *
...@@ -24,108 +32,184 @@ public class TestWeb extends TestBase { ...@@ -24,108 +32,184 @@ public class TestWeb extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
Server server = Server.createWebServer("-webPort", "8182", "-properties", getBaseDir()); testAlreadyRunning();
testStartWebServerWithConnection();
testAutoComplete();
}
private void testAlreadyRunning() throws Exception {
Server server = Server.createWebServer("-webPort", "8182", "-properties", "null");
server.start();
assertTrue(server.getStatus().indexOf("server running") >= 0);
Server server2 = Server.createWebServer("-webPort", "8182", "-properties", "null");
assertEquals("Not started", server2.getStatus());
try {
server2.start();
fail();
} catch (Exception e) {
assertTrue(e.toString().indexOf("port may be in use") >= 0);
assertTrue(server2.getStatus().indexOf("could not be started") >= 0);
}
server.stop();
}
private void testAutoComplete() throws Exception {
Server server = new Server();
server.setOut(new PrintStream(new ByteArrayOutputStream()));
server.runTool("-web", "-webPort", "8182", "-properties", "null", "-tcp", "-tcpPort", "9001");
String url = "http://localhost:8182";
WebClient client = new WebClient();
String result = client.get(url);
client.readSessionId(result);
client.get(url, "login.jsp");
client.get(url, "stylesheet.css");
client.get(url, "adminSave.do");
result = client.get(url, "index.do?language=de");
result = client.get(url, "login.jsp");
assertContains(result, "Einstellung");
result = client.get(url, "index.do?language=en");
result = client.get(url, "login.jsp");
assertTrue(result.indexOf("Einstellung") < 0);
result = client.get(url, "test.do?driver=abc&url=jdbc:abc:mem:web&user=sa&password=sa&name=_test_");
assertContains(result, "Exception");
result = client.get(url, "test.do?driver=org.h2.Driver&url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_");
assertTrue(result.indexOf("Exception") < 0);
result = client.get(url, "login.do?driver=org.h2.Driver&url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_");
result = client.get(url, "header.jsp");
result = client.get(url, "tables.do");
result = client.get(url, "query.jsp");
result = client.get(url, "query.do?sql=select * from test");
result = client.get(url, "query.do?sql=drop table test if exists");
result = client.get(url, "query.do?sql=create table test(id int primary key, name varchar);insert into test values(1, 'Hello')");
result = client.get(url, "query.do?sql=select * from test");
assertContains(result, "Hello");
result = client.get(url, "query.do?sql=@META select * from test");
assertContains(result, "typeName");
result = client.get(url, "query.do?sql=delete from test");
result = client.get(url, "query.do?sql=@LOOP 1000 insert into test values(?, 'Hello ' || ?/*RND*/)");
assertContains(result, "1000 * (Prepared)");
result = client.get(url, "query.do?sql=select * from test");
result = client.get(url, "query.do?sql=@HISTORY");
result = client.get(url, "getHistory.do?id=4");
assertContains(result, "select * from test");
result = client.get(url, "autoCompleteList.do?query=select 'abc");
// expected: '
assertContains(result, "%27");
result = client.get(url, "autoCompleteList.do?query=se");
// long time = System.currentTimeMillis();
// for (int i=0; i<1000; i++) {
// if(System.currentTimeMillis()-time > 15000) {
// break;
// }
// result = client.get(url, "autoCompleteList.do?query=select * from ");
assertContains(result, "select");
assertContains(result, "set");
result = client.get(url, "tables.do");
assertContains(result, "TEST");
result = client.get(url, "autoCompleteList.do?query=select * from ");
assertContains(result, "test");
result = client.get(url, "autoCompleteList.do?query=select * from test t where t.");
assertContains(result, "id");
result = client.get(url, "autoCompleteList.do?query=select id x from test te where t");
assertContains(result, "te");
result = client.get(url, "autoCompleteList.do?query=select * from test where name = '");
assertContains(result, "%27");
result = client.get(url, "query.do?sql=delete from test");
result = client.get(url, "query.do?sql=@LOOP 10 @STATEMENT insert into test values(?, 'Hello')");
result = client.get(url, "query.do?sql=select * from test");
assertContains(result, "8");
result = client.get(url, "query.do?sql=@EDIT select * from test");
assertContains(result, "editRow");
result = client.get(url, "query.do?sql=@AUTOCOMMIT TRUE");
result = client.get(url, "query.do?sql=@AUTOCOMMIT FALSE");
result = client.get(url, "query.do?sql=@TRANSACTION_ISOLATION");
result = client.get(url, "query.do?sql=@SET MAXROWS 1");
result = client.get(url, "query.do?sql=select * from test order by id");
result = client.get(url, "query.do?sql=@SET MAXROWS 1000");
result = client.get(url, "query.do?sql=@TABLES");
assertContains(result, "TEST");
result = client.get(url, "query.do?sql=@COLUMNS null null TEST");
assertContains(result, "ID");
result = client.get(url, "query.do?sql=@INDEX_INFO null null TEST");
assertContains(result, "PRIMARY");
result = client.get(url, "query.do?sql=@CATALOG");
assertContains(result, "PUBLIC");
result = client.get(url, "query.do?sql=@MEMORY");
assertContains(result, "Used");
result = client.get(url, "query.do?sql=@UDTS");
result = client.get(url, "query.do?sql=@INFO");
assertContains(result, "getCatalog");
result = client.get(url, "logout.do");
result = client.get(url, "settingRemove.do?name=_test_");
client.get(url, "admin.do");
try {
client.get(url, "adminShutdown.do");
} catch (IOException e) {
// expected
Thread.sleep(100);
}
server.shutdown();
// it should be stopped now
server = Server.createTcpServer("-tcpPort", "9001");
server.start(); server.start();
server.stop();
}
private void testStartWebServerWithConnection() throws Exception {
String old = System.getProperty(SysProperties.H2_BROWSER);
try { try {
String url = server.getURL(); System.setProperty(SysProperties.H2_BROWSER, "call:" + TestWeb.class.getName() + ".openBrowser");
Server.openBrowser("testUrl");
assertEquals("testUrl", lastUrl);
String oldUrl = lastUrl;
final Connection conn = getConnection("testWeb");
Task t = new Task() {
public void call() throws Exception {
Server.startWebServer(conn);
}
};
t.execute();
for (int i = 0; lastUrl == oldUrl; i++) {
if (i > 100) {
throw new Exception("Browser not started");
}
Thread.sleep(100);
}
String url = lastUrl;
WebClient client = new WebClient(); WebClient client = new WebClient();
String result = client.get(url); client.readSessionId(url);
client.readSessionId(result); url = client.getBaseUrl(url);
client.get(url, "login.jsp"); try {
client.get(url, "stylesheet.css"); client.get(url, "logout.do");
client.get(url, "adminSave.do"); } catch (Exception e) {
result = client.get(url, "index.do?language=de"); // the server stopps on logout
result = client.get(url, "login.jsp"); }
assertContains(result, "Einstellung"); t.get();
result = client.get(url, "index.do?language=en");
result = client.get(url, "login.jsp");
assertTrue(result.indexOf("Einstellung") < 0);
result = client.get(url, "test.do?driver=abc&url=jdbc:abc:mem:web&user=sa&password=sa&name=_test_");
assertContains(result, "Exception");
result = client.get(url, "test.do?driver=org.h2.Driver&url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_");
assertTrue(result.indexOf("Exception") < 0);
result = client.get(url, "login.do?driver=org.h2.Driver&url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_");
result = client.get(url, "header.jsp");
result = client.get(url, "tables.do");
result = client.get(url, "query.jsp");
result = client.get(url, "query.do?sql=select * from test");
result = client.get(url, "query.do?sql=drop table test if exists");
result = client.get(url, "query.do?sql=create table test(id int primary key, name varchar);insert into test values(1, 'Hello')");
result = client.get(url, "query.do?sql=select * from test");
assertContains(result, "Hello");
result = client.get(url, "query.do?sql=@META select * from test");
assertContains(result, "typeName");
result = client.get(url, "query.do?sql=delete from test");
result = client.get(url, "query.do?sql=@LOOP 1000 insert into test values(?, 'Hello ' || ?/*RND*/)");
assertContains(result, "1000 * (Prepared)");
result = client.get(url, "query.do?sql=select * from test");
result = client.get(url, "query.do?sql=@HISTORY");
result = client.get(url, "getHistory.do?id=4");
assertContains(result, "select * from test");
result = client.get(url, "autoCompleteList.do?query=select 'abc");
// expected: '
assertContains(result, "%27");
result = client.get(url, "autoCompleteList.do?query=se");
// long time = System.currentTimeMillis();
// for (int i=0; i<1000; i++) {
// if(System.currentTimeMillis()-time > 15000) {
// break;
// }
// result = client.get(url, "autoCompleteList.do?query=select * from ");
assertContains(result, "select");
assertContains(result, "set");
result = client.get(url, "tables.do");
assertContains(result, "TEST");
result = client.get(url, "autoCompleteList.do?query=select * from ");
assertContains(result, "test");
result = client.get(url, "autoCompleteList.do?query=select * from test t where t.");
assertContains(result, "id");
result = client.get(url, "autoCompleteList.do?query=select id x from test te where t");
assertContains(result, "te");
result = client.get(url, "autoCompleteList.do?query=select * from test where name = '");
assertContains(result, "%27");
result = client.get(url, "query.do?sql=delete from test");
result = client.get(url, "query.do?sql=@LOOP 10 @STATEMENT insert into test values(?, 'Hello')");
result = client.get(url, "query.do?sql=select * from test");
assertContains(result, "8");
result = client.get(url, "query.do?sql=@EDIT select * from test");
assertContains(result, "editRow");
result = client.get(url, "query.do?sql=@AUTOCOMMIT TRUE");
result = client.get(url, "query.do?sql=@AUTOCOMMIT FALSE");
result = client.get(url, "query.do?sql=@TRANSACTION_ISOLATION");
result = client.get(url, "query.do?sql=@SET MAXROWS 1");
result = client.get(url, "query.do?sql=select * from test order by id");
result = client.get(url, "query.do?sql=@SET MAXROWS 1000");
result = client.get(url, "query.do?sql=@TABLES");
assertContains(result, "TEST");
result = client.get(url, "query.do?sql=@COLUMNS null null TEST");
assertContains(result, "ID");
result = client.get(url, "query.do?sql=@INDEX_INFO null null TEST");
assertContains(result, "PRIMARY");
result = client.get(url, "query.do?sql=@CATALOG");
assertContains(result, "PUBLIC");
result = client.get(url, "query.do?sql=@MEMORY");
assertContains(result, "Used");
result = client.get(url, "query.do?sql=@UDTS");
result = client.get(url, "query.do?sql=@INFO");
assertContains(result, "getCatalog");
result = client.get(url, "logout.do");
result = client.get(url, "settingRemove.do?name=_test_");
client.get(url, "admin.do");
// this would also stop the server
// client.get(url, "adminShutdown.do");
} finally { } finally {
server.stop(); if (old != null) {
System.setProperty(SysProperties.H2_BROWSER, old);
} else {
System.clearProperty(SysProperties.H2_BROWSER);
}
} }
} }
/**
* This method is called via reflection.
*
* @param url the browser url
*/
public static void openBrowser(String url) {
lastUrl = url;
}
} }
...@@ -46,11 +46,12 @@ public class WebClient { ...@@ -46,11 +46,12 @@ public class WebClient {
* Read the session ID from a URL. * Read the session ID from a URL.
* *
* @param url the URL * @param url the URL
* @return the session id
*/ */
void readSessionId(String url) { String readSessionId(String url) {
int idx = url.indexOf("jsessionid="); int idx = url.indexOf("jsessionid=");
String id = url.substring(idx + "jsessionid=".length()); String id = url.substring(idx + "jsessionid=".length());
for (int i = 0; i < url.length(); i++) { for (int i = 0; i < id.length(); i++) {
char ch = id.charAt(i); char ch = id.charAt(i);
if (!Character.isLetterOrDigit(ch)) { if (!Character.isLetterOrDigit(ch)) {
id = id.substring(0, i); id = id.substring(0, i);
...@@ -58,6 +59,7 @@ public class WebClient { ...@@ -58,6 +59,7 @@ public class WebClient {
} }
} }
this.sessionId = id; this.sessionId = id;
return id;
} }
/** /**
...@@ -83,4 +85,13 @@ public class WebClient { ...@@ -83,4 +85,13 @@ public class WebClient {
return get(url); return get(url);
} }
String getBaseUrl(String url) {
int idx = url.indexOf("//");
idx = url.indexOf("/", idx + 2);
if (idx >= 0) {
return url.substring(0, idx);
}
return url;
}
} }
...@@ -40,9 +40,9 @@ import org.h2.tools.RunScript; ...@@ -40,9 +40,9 @@ import org.h2.tools.RunScript;
import org.h2.tools.Script; import org.h2.tools.Script;
import org.h2.tools.Server; import org.h2.tools.Server;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
import org.h2.util.Task;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.Task;
/** /**
* Tests the database tools. * Tests the database tools.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论