Handler & Crawler : Add traits.
This commit is contained in:
parent
359d4af5ca
commit
290ae030fa
6
src/main/scala/model/crawler/Crawler.scala
Normal file
6
src/main/scala/model/crawler/Crawler.scala
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package com.voronind.doublegis.test
|
||||||
|
package model.crawler
|
||||||
|
|
||||||
|
trait Crawler {
|
||||||
|
|
||||||
|
}
|
6
src/main/scala/model/crawler/TitleCrawler.scala
Normal file
6
src/main/scala/model/crawler/TitleCrawler.scala
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package com.voronind.doublegis.test
|
||||||
|
package model.crawler
|
||||||
|
|
||||||
|
class TitleCrawler extends Crawler {
|
||||||
|
|
||||||
|
}
|
8
src/main/scala/model/handler/Handler.scala
Normal file
8
src/main/scala/model/handler/Handler.scala
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package com.voronind.doublegis.test
|
||||||
|
package model.handler
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange
|
||||||
|
|
||||||
|
trait Handler {
|
||||||
|
def handle(exchange: HttpExchange): Unit
|
||||||
|
}
|
|
@ -5,10 +5,10 @@ import model.lib.StreamUtil
|
||||||
import com.sun.net.httpserver.{HttpExchange, HttpHandler}
|
import com.sun.net.httpserver.{HttpExchange, HttpHandler}
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
class TitleCrawlerHandler extends HttpHandler {
|
class TitleCrawlerHandler extends HttpHandler, Handler {
|
||||||
def handle(t: HttpExchange): Unit = {
|
override def handle(exchange: HttpExchange): Unit = {
|
||||||
log(t.getRequestBody)
|
log(exchange.getRequestBody)
|
||||||
sendResponse(t)
|
sendResponse(exchange)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def log(body: InputStream): Unit = {
|
private def log(body: InputStream): Unit = {
|
||||||
|
@ -17,12 +17,12 @@ class TitleCrawlerHandler extends HttpHandler {
|
||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
|
|
||||||
private def sendResponse(t: HttpExchange): Unit = {
|
private def sendResponse(exchange: HttpExchange): Unit = {
|
||||||
val response = "Ack!"
|
val response = "Ack!"
|
||||||
t.sendResponseHeaders(200, response.length())
|
exchange.sendResponseHeaders(200, response.length())
|
||||||
val os = t.getResponseBody
|
val out = exchange.getResponseBody
|
||||||
os.write(response.getBytes)
|
out.write(response.getBytes)
|
||||||
os.close()
|
out.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue