|
@@ -67,70 +67,20 @@ class BridgeFilter(private val template: SimpMessagingTemplate) : Filter {
|
|
|
}
|
|
|
|
|
|
val resFromSocket = Singletons.responseQue[reqId]
|
|
|
-//, val headers: HttpHeaders? = null
|
|
|
res.status = resFromSocket!!.statusCode.value()
|
|
|
- resFromSocket.body?.let { res.writer.write(it) }
|
|
|
resFromSocket.headers?.let {
|
|
|
- it.entries.forEach {en-> res.setHeader(en.key,en.value.joinToString(", ")) }
|
|
|
+ it.entries.forEach {en->
|
|
|
+ println(en.key + " : " + en.value.joinToString (","))
|
|
|
+ res.setHeader(en.key,en.value.joinToString(","))
|
|
|
+ }
|
|
|
}
|
|
|
+ resFromSocket.body?.let { res.writer.write(it) }
|
|
|
res.flushBuffer()
|
|
|
Singletons.requestInstance.remove(reqId)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-//class ForwarderFilter(private val template: SimpMessagingTemplate) : Filter {
|
|
|
-// override fun doFilter(
|
|
|
-// request: ServletRequest,
|
|
|
-// response: ServletResponse,
|
|
|
-// chain: FilterChain) {
|
|
|
-// val req = request as HttpServletRequest
|
|
|
-// val splitPath = req.requestURI.split("/")
|
|
|
-// val client = splitPath[2]
|
|
|
-// val toPath = "/" + splitPath.takeLast(splitPath.size - 3).joinToString("/")
|
|
|
-//
|
|
|
-// req.parameterMap.entries.forEach {
|
|
|
-// println(it.key + " : " + it.value.joinToString(", "))
|
|
|
-// }
|
|
|
-// val headerMap = req.headerNames.toList().associateBy({ it }, { req.getHeader(it) })
|
|
|
-// val body = req.reader.lines().toList().joinToString(System.lineSeparator())
|
|
|
-//
|
|
|
-// val reqId = UUID.randomUUID().toString()
|
|
|
-// val rb = RequestBuilder(reqId, toPath, HttpMethod.valueOf(req.method), headerMap.toMutableMap())
|
|
|
-// rb.body = body
|
|
|
-//
|
|
|
-// rb.queryString = req.parameterMap
|
|
|
-// Singletons.requestInstance[reqId] = RequestQue(reqId, rb, null)
|
|
|
-//
|
|
|
-// template.convertAndSend("/topic/$client", RequestTrigger(reqId))
|
|
|
-//
|
|
|
-// val res = response as HttpServletResponse
|
|
|
-// var i = 0
|
|
|
-//
|
|
|
-// while (Singletons.responseQue[reqId] == null) {
|
|
|
-// TimeUnit.MILLISECONDS.sleep(100)
|
|
|
-// i++
|
|
|
-// if (i >= 600) {
|
|
|
-//
|
|
|
-// res.status = HttpStatus.REQUEST_TIMEOUT.value()
|
|
|
-// res.writer.write("{\"message\":\"Request timeout. Client not responding\"}")
|
|
|
-// res.flushBuffer()
|
|
|
-// return
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// val resFromSocket = Singletons.responseQue[reqId]
|
|
|
-//
|
|
|
-// res.status = resFromSocket!!.statusCode.value()
|
|
|
-// resFromSocket.body?.let { res.writer.write(it) }
|
|
|
-//
|
|
|
-// res.flushBuffer()
|
|
|
-// Singletons.requestInstance.remove(reqId)
|
|
|
-// return
|
|
|
-// }
|
|
|
-//
|
|
|
-//}
|
|
|
-
|
|
|
class RequestQue(val id: String, val requestBuilder: RequestBuilder, var responseObj: ResponseObj?)
|
|
|
|
|
|
class ResponseObj(val id: String, val statusCode: HttpStatus, val body: String?, val headers: HttpHeaders? = null)
|
|
@@ -138,25 +88,10 @@ class ResponseObj(val id: String, val statusCode: HttpStatus, val body: String?,
|
|
|
class RequestTrigger(val id: String)
|
|
|
|
|
|
class RequestBuilder(val id: String, val path: String, val method: HttpMethod, var headers: MutableMap<String, String>) : Serializable {
|
|
|
- // var method: HttpMethod = HttpMethod.GET
|
|
|
var body: String? = null
|
|
|
var queryString: MutableMap<String, Array<String>>? = null
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
-//@Component
|
|
|
-//class FilterConfiguration(val template: SimpMessagingTemplate) {
|
|
|
-// @Bean
|
|
|
-// fun loggingFilter(): FilterRegistrationBean<ForwarderFilter> {
|
|
|
-// val registrationBean = FilterRegistrationBean<ForwarderFilter>()
|
|
|
-// registrationBean.filter = ForwarderFilter(template)
|
|
|
-// registrationBean.addUrlPatterns("/bridge/*")
|
|
|
-// return registrationBean
|
|
|
-// }
|
|
|
-//
|
|
|
-//}
|
|
|
-//
|
|
|
-
|
|
|
@RestController
|
|
|
class BridgeRestController {
|
|
|
@PostMapping("/_response")
|