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
d05ddbd4
Commit
d05ddbd4
authored
Mar 25, 2016
by
Yoshiharu Hirose
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ベースディレクトリを引数で指定
parent
c1a8aa7e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
+19
-6
README.TXT
README.TXT
+9
-0
DummyHttpServer.scala
src/main/scala/DummyHttpServer.scala
+10
-6
No files found.
README.TXT
0 → 100644
View file @
d05ddbd4
iaas-sdk ユニットテスト用ダミーHTTPサーバ
実行
> activator "run (ベースディレクトリ)"
※HTTPサーバから返却するxmlが格納されたディレクトリを指定する。
例
> activator "run D:\project\nifty\clisdk\dev\iaas-sdk\src\test\resources"
src/main/scala/DummyHttpServer.scala
View file @
d05ddbd4
...
@@ -6,27 +6,30 @@ import com.sun.net.httpserver.{HttpExchange, HttpHandler, HttpServer}
...
@@ -6,27 +6,30 @@ import com.sun.net.httpserver.{HttpExchange, HttpHandler, HttpServer}
import
scala.collection.JavaConversions._
import
scala.collection.JavaConversions._
object
DummyHttpServer
{
object
DummyHttpServer
{
val
BASEDIR
=
"""D:\project\nifty\clisdk\dev\iaas-sdk\src\test\resources"""
val
PORTS
=
Array
(
80
,
8080
,
38080
)
val
PORTS
=
Array
(
80
,
8080
,
38080
)
def
main
(
args
:
Array
[
String
])
{
def
main
(
args
:
Array
[
String
])
{
PORTS
.
foreach
(
startServer
)
if
(
args
.
length
>
0
)
{
printf
(
"Starting server.\nbasedir = %s\n"
,
args
(
0
))
PORTS
.
foreach
{
port
=>
startServer
(
args
(
0
),
port
)
}
}
}
}
/**
/**
* サーバ起動
* サーバ起動
*
* @param port 待ち受けポート番号
* @param port 待ち受けポート番号
*/
*/
def
startServer
(
port
:
Int
)
{
def
startServer
(
basedir
:
String
,
port
:
Int
)
{
val
server
=
HttpServer
.
create
(
new
InetSocketAddress
(
port
),
10
)
val
server
=
HttpServer
.
create
(
new
InetSocketAddress
(
port
),
10
)
server
.
createContext
(
"/"
,
new
DummyHttpServer
.
MyHandler
)
server
.
createContext
(
"/"
,
new
DummyHttpServer
.
MyHandler
(
basedir
)
)
server
.
start
()
server
.
start
()
}
}
/**
/**
* ハンドラ
* ハンドラ
*/
*/
class
MyHandler
extends
HttpHandler
{
class
MyHandler
(
basedir
:
String
)
extends
HttpHandler
{
def
handle
(
t
:
HttpExchange
)
:
Unit
=
{
def
handle
(
t
:
HttpExchange
)
:
Unit
=
{
println
(
"------------------------------------------------------------"
)
println
(
"------------------------------------------------------------"
)
printf
(
"%s %s\n"
,
t
.
getRequestMethod
,
t
.
getRequestURI
)
printf
(
"%s %s\n"
,
t
.
getRequestMethod
,
t
.
getRequestURI
)
...
@@ -35,7 +38,7 @@ object DummyHttpServer {
...
@@ -35,7 +38,7 @@ object DummyHttpServer {
printf
(
"%s: %s\n"
,
ent
.
getKey
,
v
)
printf
(
"%s: %s\n"
,
ent
.
getKey
,
v
)
}
}
}
}
findFile
(
new
File
(
t
.
getRequestURI
.
getPath
).
getName
,
new
File
(
BASEDIR
))
match
{
findFile
(
new
File
(
t
.
getRequestURI
.
getPath
).
getName
,
new
File
(
basedir
))
match
{
case
Some
(
file
)
=>
case
Some
(
file
)
=>
t
.
sendResponseHeaders
(
200
,
file
.
length
)
t
.
sendResponseHeaders
(
200
,
file
.
length
)
val
is
=
new
BufferedInputStream
(
new
FileInputStream
(
file
))
val
is
=
new
BufferedInputStream
(
new
FileInputStream
(
file
))
...
@@ -55,6 +58,7 @@ object DummyHttpServer {
...
@@ -55,6 +58,7 @@ object DummyHttpServer {
/**
/**
* ファイル検索
* ファイル検索
*
* @param filename ファイル名
* @param filename ファイル名
* @param dir 検索対象ディレクトリ
* @param dir 検索対象ディレクトリ
* @return ファイル
* @return ファイル
...
...
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