Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dummyhttpserver
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yoshiharu Hirose
dummyhttpserver
Commits
bd99bb38
Commit
bd99bb38
authored
May 13, 2016
by
Yoshiharu Hirose
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
デバッグ動作設定を追加
parent
acbd0c67
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
2 deletions
+43
-2
dummyhttpserver.properties.sample
dummyhttpserver.properties.sample
+13
-0
DummyHttpServer.scala
src/main/scala/DummyHttpServer.scala
+30
-2
No files found.
dummyhttpserver.properties.sample
View file @
bd99bb38
# 応答ファイルのベースパス
basedir=D:\\project\\nifty\\clisdk\\dev\\iaas-sdk\\src\\test\\resources
basedir=D:\\project\\nifty\\clisdk\\dev\\iaas-sdk\\src\\test\\resources
# 待ち受けポート番号
#ports=80,8080,38080
#ports=80,8080,38080
### デバッグ設定
# 応答を返す前にスリープ(ms)
#sleep=1000
# 応答を返さずコネクションを切断する
#force_close=true
# 必ずエラー応答する (ステータスコード)
#force_error=503
src/main/scala/DummyHttpServer.scala
View file @
bd99bb38
import
java.io._
import
java.io._
import
java.net.InetSocketAddress
import
java.net.InetSocketAddress
import
java.util.
Properties
import
java.util.
{
Calendar
,
Properties
}
import
com.sun.net.httpserver.
{
HttpExchange
,
HttpHandler
,
HttpServer
}
import
com.sun.net.httpserver.
{
HttpExchange
,
HttpHandler
,
HttpServer
}
...
@@ -10,9 +10,10 @@ object DummyHttpServer {
...
@@ -10,9 +10,10 @@ object DummyHttpServer {
val
PROPERTIES_FILE
=
"dummyhttpserver.properties"
val
PROPERTIES_FILE
=
"dummyhttpserver.properties"
val
DEFAULT_PORTS
=
Array
(
80
,
8080
,
38080
)
val
DEFAULT_PORTS
=
Array
(
80
,
8080
,
38080
)
val
properties
=
new
Properties
()
def
main
(
args
:
Array
[
String
])
{
def
main
(
args
:
Array
[
String
])
{
// Load properties
// Load properties
val
properties
=
new
Properties
()
try
{
try
{
val
is
=
new
FileInputStream
(
new
File
(
PROPERTIES_FILE
))
val
is
=
new
FileInputStream
(
new
File
(
PROPERTIES_FILE
))
properties
.
load
(
is
)
properties
.
load
(
is
)
...
@@ -52,7 +53,9 @@ object DummyHttpServer {
...
@@ -52,7 +53,9 @@ object DummyHttpServer {
*/
*/
class
MyHandler
(
basedir
:
String
)
extends
HttpHandler
{
class
MyHandler
(
basedir
:
String
)
extends
HttpHandler
{
def
handle
(
t
:
HttpExchange
)
:
Unit
=
{
def
handle
(
t
:
HttpExchange
)
:
Unit
=
{
println
()
println
(
"------------------------------------------------------------"
)
println
(
"------------------------------------------------------------"
)
println
(
Calendar
.
getInstance
.
getTime
.
toString
)
printf
(
"%s %s\n"
,
t
.
getRequestMethod
,
t
.
getRequestURI
)
printf
(
"%s %s\n"
,
t
.
getRequestMethod
,
t
.
getRequestURI
)
try
{
try
{
t
.
getRequestHeaders
.
entrySet
().
foreach
{
ent
=>
t
.
getRequestHeaders
.
entrySet
().
foreach
{
ent
=>
...
@@ -91,6 +94,31 @@ object DummyHttpServer {
...
@@ -91,6 +94,31 @@ object DummyHttpServer {
}
}
}
}
// Sleep before respond
Option
(
properties
.
getProperty
(
"sleep"
))
match
{
case
Some
(
ms
)
=>
Thread
.
sleep
(
ms
.
toLong
)
println
(
Calendar
.
getInstance
.
getTime
.
toString
)
case
_
=>
}
// Force close connection
Option
(
properties
.
getProperty
(
"force_close"
))
match
{
case
Some
(
"true"
)
=>
t
.
close
()
return
case
_
=>
}
// Force close connection
Option
(
properties
.
getProperty
(
"force_error"
))
match
{
case
Some
(
str
:
String
)
=>
t
.
sendResponseHeaders
(
str
.
toInt
,
0
)
t
.
close
()
return
case
_
=>
}
findFile
(
new
File
(
t
.
getRequestURI
.
getPath
).
getName
,
new
File
(
basedir
)).
orElse
{
findFile
(
new
File
(
t
.
getRequestURI
.
getPath
).
getName
,
new
File
(
basedir
)).
orElse
{
actionOps
.
flatMap
{
action
=>
findFile
(
action
+
".xml"
,
new
File
(
basedir
))
}
actionOps
.
flatMap
{
action
=>
findFile
(
action
+
".xml"
,
new
File
(
basedir
))
}
}
match
{
}
match
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment