Browse Source

fix bug for error req

herlanS_ 5 years ago
parent
commit
8ea783359a

+ 2 - 13
src/main/kotlin/co/id/datacomsolusindo/ipphonebridge/BridgeFIlter.kt

@@ -18,34 +18,28 @@ import javax.servlet.http.HttpServletRequest
 import javax.servlet.http.HttpServletResponse
 import javax.servlet.http.HttpServletResponse
 import kotlin.streams.toList
 import kotlin.streams.toList
 
 
-
 class ForwarderFilter(private val template: SimpMessagingTemplate) : Filter {
 class ForwarderFilter(private val template: SimpMessagingTemplate) : Filter {
-
     override fun doFilter(
     override fun doFilter(
             request: ServletRequest,
             request: ServletRequest,
             response: ServletResponse,
             response: ServletResponse,
             chain: FilterChain) {
             chain: FilterChain) {
-
         val req = request as HttpServletRequest
         val req = request as HttpServletRequest
         val splitPath = req.requestURI.split("/")
         val splitPath = req.requestURI.split("/")
         val client = splitPath[2]
         val client = splitPath[2]
         val toPath = "/" + splitPath.takeLast(splitPath.size - 3).joinToString("/")
         val toPath = "/" + splitPath.takeLast(splitPath.size - 3).joinToString("/")
 
 
-
         req.parameterMap.entries.forEach {
         req.parameterMap.entries.forEach {
             println(it.key + " : " + it.value.joinToString(", "))
             println(it.key + " : " + it.value.joinToString(", "))
         }
         }
         val headerMap = req.headerNames.toList().associateBy({ it }, { req.getHeader(it) })
         val headerMap = req.headerNames.toList().associateBy({ it }, { req.getHeader(it) })
         val body = req.reader.lines().toList().joinToString(System.lineSeparator())
         val body = req.reader.lines().toList().joinToString(System.lineSeparator())
 
 
-
         val reqId = UUID.randomUUID().toString()
         val reqId = UUID.randomUUID().toString()
         val rb = RequestBuilder(reqId, toPath, HttpMethod.valueOf(req.method), headerMap.toMutableMap())
         val rb = RequestBuilder(reqId, toPath, HttpMethod.valueOf(req.method), headerMap.toMutableMap())
         rb.body = body
         rb.body = body
 
 
-
         rb.queryString = req.parameterMap
         rb.queryString = req.parameterMap
-        Singletons.requestInstance[reqId] = RequestQue(reqId,rb,null)
+        Singletons.requestInstance[reqId] = RequestQue(reqId, rb, null)
 
 
         template.convertAndSend("/topic/$client", RequestTrigger(reqId))
         template.convertAndSend("/topic/$client", RequestTrigger(reqId))
 
 
@@ -72,18 +66,15 @@ class ForwarderFilter(private val template: SimpMessagingTemplate) : Filter {
         res.flushBuffer()
         res.flushBuffer()
         Singletons.requestInstance.remove(reqId)
         Singletons.requestInstance.remove(reqId)
         return
         return
-
     }
     }
 
 
-
-    // other methods
 }
 }
 
 
 class RequestQue(val id: String, val requestBuilder: RequestBuilder, var responseObj: ResponseObj?)
 class RequestQue(val id: String, val requestBuilder: RequestBuilder, var responseObj: ResponseObj?)
 
 
 class ResponseObj(val id: String, val statusCode: HttpStatus, val body: String?)
 class ResponseObj(val id: String, val statusCode: HttpStatus, val body: String?)
 
 
-class RequestTrigger(val id:String)
+class RequestTrigger(val id: String)
 
 
 class RequestBuilder(val id: String, val path: String, val method: HttpMethod, var headers: MutableMap<String, String>) : Serializable {
 class RequestBuilder(val id: String, val path: String, val method: HttpMethod, var headers: MutableMap<String, String>) : Serializable {
     // var method: HttpMethod = HttpMethod.GET
     // var method: HttpMethod = HttpMethod.GET
@@ -97,10 +88,8 @@ class FilterConfiguration(val template: SimpMessagingTemplate) {
     @Bean
     @Bean
     fun loggingFilter(): FilterRegistrationBean<ForwarderFilter> {
     fun loggingFilter(): FilterRegistrationBean<ForwarderFilter> {
         val registrationBean = FilterRegistrationBean<ForwarderFilter>()
         val registrationBean = FilterRegistrationBean<ForwarderFilter>()
-
         registrationBean.filter = ForwarderFilter(template)
         registrationBean.filter = ForwarderFilter(template)
         registrationBean.addUrlPatterns("/bridge/*")
         registrationBean.addUrlPatterns("/bridge/*")
-
         return registrationBean
         return registrationBean
     }
     }