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 java.io.InputStream
|
||||
|
||||
class TitleCrawlerHandler extends HttpHandler {
|
||||
def handle(t: HttpExchange): Unit = {
|
||||
log(t.getRequestBody)
|
||||
sendResponse(t)
|
||||
class TitleCrawlerHandler extends HttpHandler, Handler {
|
||||
override def handle(exchange: HttpExchange): Unit = {
|
||||
log(exchange.getRequestBody)
|
||||
sendResponse(exchange)
|
||||
}
|
||||
|
||||
private def log(body: InputStream): Unit = {
|
||||
|
@ -17,12 +17,12 @@ class TitleCrawlerHandler extends HttpHandler {
|
|||
println()
|
||||
}
|
||||
|
||||
private def sendResponse(t: HttpExchange): Unit = {
|
||||
private def sendResponse(exchange: HttpExchange): Unit = {
|
||||
val response = "Ack!"
|
||||
t.sendResponseHeaders(200, response.length())
|
||||
val os = t.getResponseBody
|
||||
os.write(response.getBytes)
|
||||
os.close()
|
||||
exchange.sendResponseHeaders(200, response.length())
|
||||
val out = exchange.getResponseBody
|
||||
out.write(response.getBytes)
|
||||
out.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue