@@ -6,6 +6,7 @@ import io.ktor.client.request.*
66import io.ktor.client.statement.*
77import io.ktor.http.*
88import io.ktor.server.application.*
9+ import io.ktor.server.config.*
910import io.ktor.server.response.*
1011import io.ktor.util.pipeline.*
1112import org.apache.commons.io.IOUtils
@@ -108,12 +109,13 @@ fun PipelineContext<*, ApplicationCall>.sysmlv2ElementIri(uuid: UUID): String {
108109 return " <urn:sysmlv2:${uuid} >"
109110}
110111
111- class FlexoRequestBuilder {
112+ class FlexoRequestBuilder ( config : FlexoConfig ) {
112113 private var headers = mutableListOf<Pair <String , List <String >>>()
113114 private var path: String = " "
114115 private var queryParams = mutableMapOf<String , String >()
115116 private var body: String = " "
116-
117+ private var flexohost = config.host
118+ private var flexoport = config.port
117119 fun addHeaders (vararg headers : Pair <String , String >) {
118120 this .headers.addAll(headers.map { it.first to listOf (it.second) })
119121 }
@@ -148,8 +150,8 @@ class FlexoRequestBuilder {
148150 return request {
149151 url {
150152 protocol = URLProtocol .HTTP
151- host = " localhost "
152- port = 8080
153+ host = flexohost
154+ port = flexoport
153155 path(path)
154156
155157 queryParams.forEach {
@@ -229,17 +231,17 @@ class FlexoResponse(
229231
230232}
231233
232- suspend fun flexoRequest (method : HttpMethod , auth : String , setup : FlexoRequestBuilder .() -> Unit ): FlexoResponse {
234+ suspend fun PipelineContext < Unit , ApplicationCall >. flexoRequest (method : HttpMethod , setup : FlexoRequestBuilder .() -> Unit ): FlexoResponse {
233235 val client = HttpClient () {
234236 install(HttpTimeout )
235237 }
236-
237- val builder = FlexoRequestBuilder ()
238+ val flexoconfig = getFlexoConfigValues(call.application.environment.config)
239+ val builder = FlexoRequestBuilder (flexoconfig )
238240
239241 setup(builder)
240242
241243 val request = builder.build()
242- request.header(HttpHeaders .Authorization , auth )
244+ request.header(HttpHeaders .Authorization , call.request.headers[ " Authorization " ] !! )
243245 request.method = method
244246 request.timeout {
245247 requestTimeoutMillis = 600000
@@ -251,15 +253,15 @@ suspend fun flexoRequest(method: HttpMethod, auth: String, setup: FlexoRequestBu
251253}
252254
253255suspend fun PipelineContext <Unit , ApplicationCall >.flexoRequestGet (setup : FlexoRequestBuilder .() -> Unit ): FlexoResponse {
254- return flexoRequest(HttpMethod .Get , call.request.headers[ " Authorization " ] !! , setup)
256+ return flexoRequest(HttpMethod .Get , setup)
255257}
256258
257259suspend fun PipelineContext <Unit , ApplicationCall >.flexoRequestPut (setup : FlexoRequestBuilder .() -> Unit ): FlexoResponse {
258- return flexoRequest(HttpMethod .Put , call.request.headers[ " Authorization " ] !! , setup)
260+ return flexoRequest(HttpMethod .Put , setup)
259261}
260262
261263suspend fun PipelineContext <Unit , ApplicationCall >.flexoRequestPost (setup : FlexoRequestBuilder .() -> Unit ): FlexoResponse {
262- return flexoRequest(HttpMethod .Post , call.request.headers[ " Authorization " ] !! , setup)
264+ return flexoRequest(HttpMethod .Post , setup)
263265}
264266
265267open class FlexoModelHandler (val model : Model , val prefixes : PrefixMappingImpl ) {
@@ -310,3 +312,13 @@ suspend fun PipelineContext<*, ApplicationCall>.forward(flexoResponse: FlexoResp
310312 }.toTypedArray())
311313 }
312314}
315+
316+ data class FlexoConfig (
317+ val host : String ,
318+ val port : Int
319+ )
320+ fun getFlexoConfigValues (config : ApplicationConfig ): FlexoConfig {
321+ val host = config.propertyOrNull(" flexo.host" )?.getString() ? : " localhost"
322+ val port = config.propertyOrNull(" flexo.port" )?.getString()?.toInt() ? : 8080
323+ return FlexoConfig (host, port)
324+ }
0 commit comments