Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
working on new server style
Browse files Browse the repository at this point in the history
  • Loading branch information
fulton committed Jan 2, 2020
1 parent 574006a commit 0c421d1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mainClassName = 'com.andromeda.araserver.Run'

group 'ara-server'
version '1.0-SNAPSHOT'

ext.ktor_version = '1.2.6'
sourceCompatibility = 1.8

repositories {
Expand Down Expand Up @@ -62,6 +62,9 @@ dependencies {
// https://mvnrepository.com/artifact/postgresql/postgresql
compile group: 'postgresql', name: 'postgresql', version: '9.1-901-1.jdbc4'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile "io.ktor:ktor-server-netty:$ktor_version"
compile "io.ktor:ktor-websockets:$ktor_version"
testCompile "io.ktor:ktor-server-test-host:$ktor_version"
implementation("com.squareup.okhttp3:okhttp:4.3.0")
compile "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.+"

Expand Down
52 changes: 46 additions & 6 deletions src/main/java/com/andromeda/araserver/Run.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ import com.rometools.rome.feed.synd.SyndFeed
import com.rometools.rome.io.FeedException
import com.rometools.rome.io.SyndFeedOutput
import fi.iki.elonen.NanoHTTPD
import io.ktor.application.Application
import io.ktor.application.ApplicationCallPipeline
import io.ktor.application.call
import io.ktor.request.queryString
import io.ktor.request.uri
import io.ktor.response.respondText
import io.ktor.routing.get
import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import opennlp.tools.parser.Parser
import opennlp.tools.parser.ParserFactory
import opennlp.tools.parser.ParserModel
Expand All @@ -21,12 +31,12 @@ import java.net.URL
import java.sql.SQLException
import java.util.*

object Run : NanoHTTPD(80) {
object Run {
private var keyWord: KeyWord? = null
private var model: ParserModel? = null
private var parser: Parser? = null
//If connected to
override fun serve(session: IHTTPSession): Response {
fun serve(session: NanoHTTPD.IHTTPSession) {
val tag: Int
//URI passed from client
val sessionUri = session.uri
Expand Down Expand Up @@ -97,12 +107,42 @@ object Run : NanoHTTPD(80) {
}
println(sessionUri)
//Output response
return newFixedLengthResponse(main2)

}
fun serverCode(a:Application) {
a.routing {
println("")
get("/api/{param?}") {
call.respondText{ApiStart().apiMain(call.request.uri.replace("%20", " "), keyWord, parser)}
}
get("/hi/{param?}"){
call.respondText{Hello().hello()}
}
get("/searcht/{param?}"){
call.respondText{GetInfo().main(call.request.uri.replace("%20", " "))}
}
get("/store/{param?}"){
call.respondText{com.andromeda.araserver.store.Main().GetStoreContent()}
}
get("/devices/{param?}"){
call.respondText{Main().main(call.request.uri.replace("%20", " "))}
}
get("/skillsdata/{param?}"){
call.respondText{GetSkillData().main(call.request.uri.replace("%20", " "))!!}
}
get("/newdevice/{param?}"){
NewDevice().main(call.request.uri)
}
get("/weath/{param?}"){call.respondText(Weather().mainPart(call.request.uri.replace("%20", " "), keyWord!!, parser!!)!!)}
get("/yelpclient/{param?}"){call.respondText(Locdec().main(call.request.uri.replace("%20", " "), keyWord, parser))}
}
}
// Static function, to be run on start.
@JvmStatic
fun main(args: Array<String>) { // If this is in a heroku environment, get the port number
start(SOCKET_READ_TIMEOUT, false)
fun main(args: Array<String>) {
val server = embeddedServer(Netty, 8080){
serverCode(this)
}
println(" Ara server is running and is available on your domain, IP, or http://localhost:8080/")
println(
"This program is free software: you can redistribute it and/or modify\n" +
Expand All @@ -118,7 +158,6 @@ object Run : NanoHTTPD(80) {
" You should have received a copy of the GNU General Public License\n" +
" along with this program. If not, see <https://www.gnu.org/licenses/>."
)
//new MsSql().getSkills();
val classloader = javaClass.classLoader
var `is` = classloader.getResourceAsStream("resources/parse.bin")
println("test")
Expand All @@ -131,6 +170,7 @@ object Run : NanoHTTPD(80) {
parser = ParserFactory.create(model)
keyWord = KeyWord(`is`!!)
println("Press any key to exit...")
server.start(wait = false)


}
Expand Down

0 comments on commit 0c421d1

Please sign in to comment.