Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a2f179e4
提交
a2f179e4
authored
12月 02, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Server.openBrowser no longer writes to System.out directly if opening the URL failed.
上级
56fb3686
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
244 行增加
和
127 行删除
+244
-127
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+10
-5
Console.java
h2/src/main/org/h2/tools/Console.java
+10
-2
Server.java
h2/src/main/org/h2/tools/Server.java
+29
-20
TestWeb.java
h2/src/test/org/h2/test/server/TestWeb.java
+181
-97
WebClient.java
h2/src/test/org/h2/test/server/WebClient.java
+13
-2
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+1
-1
没有找到文件。
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
a2f179e4
...
...
@@ -253,7 +253,7 @@ public class WebServer implements Service {
public
void
init
(
String
...
args
)
{
// set the serverPropertiesDir, because it's used in loadProperties()
for
(
int
i
=
0
;
args
!=
null
&&
i
<
args
.
length
;
i
++)
{
if
(
args
[
i
].
equals
(
"-properties"
))
{
if
(
"-properties"
.
equals
(
args
[
i
]
))
{
serverPropertiesDir
=
args
[++
i
];
}
}
...
...
@@ -276,7 +276,7 @@ public class WebServer implements Service {
SysProperties
.
setBaseDir
(
baseDir
);
}
else
if
(
"-ifExists"
.
equals
(
a
))
{
ifExists
=
true
;
}
else
if
(
args
[
i
].
equals
(
"-properties"
))
{
}
else
if
(
"-properties"
.
equals
(
args
[
i
]
))
{
// already set
i
++;
}
else
if
(
"-trace"
.
equals
(
a
))
{
...
...
@@ -519,6 +519,9 @@ public class WebServer implements Service {
private
Properties
loadProperties
()
{
try
{
if
(
"null"
.
equals
(
serverPropertiesDir
))
{
return
new
Properties
();
}
return
SortedProperties
.
loadProperties
(
serverPropertiesDir
+
"/"
+
Constants
.
SERVER_PROPERTIES_NAME
);
}
catch
(
Exception
e
)
{
TraceSystem
.
traceThrowable
(
e
);
...
...
@@ -595,9 +598,11 @@ public class WebServer implements Service {
prop
.
setProperty
(
String
.
valueOf
(
len
-
i
-
1
),
info
.
getString
());
}
}
OutputStream
out
=
IOUtils
.
openFileOutputStream
(
serverPropertiesDir
+
"/"
+
Constants
.
SERVER_PROPERTIES_NAME
,
false
);
prop
.
store
(
out
,
"H2 Server Properties"
);
out
.
close
();
if
(!
"null"
.
equals
(
serverPropertiesDir
))
{
OutputStream
out
=
IOUtils
.
openFileOutputStream
(
serverPropertiesDir
+
"/"
+
Constants
.
SERVER_PROPERTIES_NAME
,
false
);
prop
.
store
(
out
,
"H2 Server Properties"
);
out
.
close
();
}
}
catch
(
Exception
e
)
{
TraceSystem
.
traceThrowable
(
e
);
}
...
...
h2/src/main/org/h2/tools/Console.java
浏览文件 @
a2f179e4
...
...
@@ -170,7 +170,7 @@ ShutdownHandler {
// because some people don't look at the output,
// but are wondering why nothing happens
if
(
browserStart
)
{
Server
.
openBrowser
(
web
.
getURL
());
openBrowser
(
web
.
getURL
());
}
if
(
tcpStart
)
{
...
...
@@ -421,12 +421,20 @@ ShutdownHandler {
long
now
=
System
.
currentTimeMillis
();
if
(
lastOpen
==
0
||
lastOpen
+
100
<
now
)
{
lastOpen
=
now
;
Server
.
openBrowser
(
url
);
openBrowser
(
url
);
}
}
}
//## AWT end ##
private
void
openBrowser
(
String
url
)
{
try
{
Server
.
openBrowser
(
url
);
}
catch
(
Exception
e
)
{
out
.
println
(
e
.
getMessage
());
}
}
/**
* INTERNAL
*/
...
...
h2/src/main/org/h2/tools/Server.java
浏览文件 @
a2f179e4
...
...
@@ -6,7 +6,6 @@
*/
package
org
.
h2
.
tools
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
...
...
@@ -21,6 +20,7 @@ import org.h2.server.pg.PgServer;
import
org.h2.server.web.WebServer
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Tool
;
import
org.h2.util.Utils
;
/**
* Starts the H2 Console (web-) server, TCP, and PG server.
...
...
@@ -31,6 +31,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
private
Service
service
;
private
Server
web
,
tcp
,
pg
;
private
ShutdownHandler
shutdownHandler
;
private
boolean
started
;
public
Server
()
{
// nothing to do
...
...
@@ -95,7 +96,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* <tr><td>[-pgPort <port>]</td>
* <td>The port (default: 5435)</td></tr>
* <tr><td>[-properties "<dir>"]</td>
* <td>
The server properties directory (default: ~
)</td></tr>
* <td>
Server properties (default: ~, disable: null
)</td></tr>
* <tr><td>[-baseDir <dir>]</td>
* <td>The base directory for H2 databases (all servers)</td></tr>
* <tr><td>[-ifExists]</td>
...
...
@@ -140,8 +141,6 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
// no parameters
}
else
if
(
"-webPort"
.
equals
(
arg
))
{
i
++;
}
else
if
(
"-webScript"
.
equals
(
arg
))
{
i
++;
}
else
{
throwUnsupportedOption
(
arg
);
}
...
...
@@ -221,7 +220,11 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
// because some people don't look at the output,
// but are wondering why nothing happens
if
(
browserStart
)
{
Server
.
openBrowser
(
web
.
getURL
());
try
{
openBrowser
(
web
.
getURL
());
}
catch
(
Exception
e
)
{
out
.
println
(
e
.
getMessage
());
}
}
if
(
result
!=
null
)
{
throw
result
;
...
...
@@ -269,7 +272,9 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
*/
public
String
getStatus
()
{
StringBuilder
buff
=
new
StringBuilder
();
if
(
isRunning
(
false
))
{
if
(!
started
)
{
buff
.
append
(
"Not started"
);
}
else
if
(
isRunning
(
false
))
{
buff
.
append
(
service
.
getType
()).
append
(
" server running on "
).
append
(
service
.
getURL
()).
...
...
@@ -344,6 +349,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
*/
public
Server
start
()
throws
SQLException
{
try
{
started
=
true
;
service
.
start
();
Thread
t
=
new
Thread
(
this
);
t
.
setDaemon
(
service
.
isDaemon
());
...
...
@@ -404,6 +410,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
* Stops the server.
*/
public
void
stop
()
{
started
=
false
;
service
.
stop
();
}
...
...
@@ -468,13 +475,16 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
*
* @param url the URL to open
*/
public
static
void
openBrowser
(
String
url
)
{
String
osName
=
SysProperties
.
getStringSetting
(
"os.name"
,
"linux"
).
toLowerCase
();
Runtime
rt
=
Runtime
.
getRuntime
();
public
static
void
openBrowser
(
String
url
)
throws
Exception
{
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
.
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
);
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
args
[
i
]
=
StringUtils
.
replaceAll
(
args
[
i
],
"%url"
,
url
);
...
...
@@ -525,12 +535,11 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
}
if
(!
ok
)
{
// 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
)
{
System
.
out
.
println
(
"Failed to start a browser to open the URL "
+
url
);
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"Failed to start a browser to open the URL "
+
url
+
": "
+
e
.
getMessage
());
}
}
...
...
@@ -550,13 +559,13 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
server
.
web
=
web
;
webServer
.
setShutdownHandler
(
server
);
String
url
=
webServer
.
addSession
(
conn
);
Server
.
openBrowser
(
url
);
while
(!
webServer
.
isStopped
())
{
try
{
try
{
Server
.
openBrowser
(
url
);
while
(!
webServer
.
isStopped
())
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
// ignore
}
}
catch
(
Exception
e
)
{
// ignore
}
}
...
...
h2/src/test/org/h2/test/server/TestWeb.java
浏览文件 @
a2f179e4
差异被折叠。
点击展开。
h2/src/test/org/h2/test/server/WebClient.java
浏览文件 @
a2f179e4
...
...
@@ -46,11 +46,12 @@ public class WebClient {
* Read the session ID from a URL.
*
* @param url the URL
* @return the session id
*/
void
readSessionId
(
String
url
)
{
String
readSessionId
(
String
url
)
{
int
idx
=
url
.
indexOf
(
"jsessionid="
);
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
);
if
(!
Character
.
isLetterOrDigit
(
ch
))
{
id
=
id
.
substring
(
0
,
i
);
...
...
@@ -58,6 +59,7 @@ public class WebClient {
}
}
this
.
sessionId
=
id
;
return
id
;
}
/**
...
...
@@ -83,4 +85,13 @@ public class WebClient {
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
;
}
}
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
a2f179e4
...
...
@@ -40,9 +40,9 @@ import org.h2.tools.RunScript;
import
org.h2.tools.Script
;
import
org.h2.tools.Server
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.Task
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.Task
;
/**
* Tests the database tools.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论