Commit bd99bb38 authored by Yoshiharu Hirose's avatar Yoshiharu Hirose

デバッグ動作設定を追加

parent acbd0c67
# 応答ファイルのベースパス
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
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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment