فهرست منبع

change bridge filter

herlanS_ 3 سال پیش
والد
کامیت
57191067c7
1فایلهای تغییر یافته به همراه19 افزوده شده و 50 حذف شده
  1. 19 50
      src/main/kotlin/co/id/datacomsolusindo/ipphonebridge/BridgeFIlter.kt

+ 19 - 50
src/main/kotlin/co/id/datacomsolusindo/ipphonebridge/BridgeFIlter.kt

@@ -82,15 +82,8 @@ class BridgeFilter(private val template: SimpMessagingTemplate, val resourceLoad
         val splitPath = req.requestURI.split("/")
         val client = splitPath[1]
         val toPath = "/" + splitPath.takeLast(splitPath.size - 1).joinToString("/")
-        if (
-            client.startsWith("_")
-            || client.startsWith("resources")
-            || client.startsWith("clientStat")
-            || client.startsWith("actuator")
-        ) {
-            chain.doFilter(request, response)
-            return
-        } else {
+        val clientNumber = client.toIntOrNull()
+        if (clientNumber != null && clientNumber > 0 && clientNumber < 999) {
             val search = isResourceAvailable(toPath)
             if (search != null && !search.endsWith("assets/bootstrap.js")) {
                 res.sendRedirect("/resources/$search")
@@ -131,10 +124,11 @@ class BridgeFilter(private val template: SimpMessagingTemplate, val resourceLoad
                     //template.convertAndSend("/topic/request/$client",Singletons.sendQueue[mid]!!.first())
 
 
-                    LogManager.getLogger(this.javaClass).info("part size ${partStr.size}")
+//                    LogManager.getLogger(this.javaClass).info("part size ${partStr.size}")
 //                    if (partStr.size > 1) {
                     val partialID = UUID.randomUUID().toString()
                     val st2 = System.nanoTime()
+
                     partStr.forEachIndexed { idx, it ->
                         template.convertAndSend(
                             "/topic/partial/$client",
@@ -204,14 +198,22 @@ class BridgeFilter(private val template: SimpMessagingTemplate, val resourceLoad
                     ClientHolder.addFailedRequest(client)
                     return
                 }
-
-//                } else {
-//
-//                    response.status = HttpStatus.NOT_FOUND.value()
-//                    response.getWriter().write("Resource not found")
-//                }
             }
+        } else {
+            chain.doFilter(request, response)
+            return
         }
+//        if (
+//            client.startsWith("_")
+//            || client.startsWith("resources")
+//            || client.startsWith("clientStat")
+//            || client.startsWith("actuator")
+//        ) {
+//            chain.doFilter(request, response)
+//            return
+//        } else {
+//
+//        }
     }
 
     fun isResourceAvailable(path: String, itr: Int = 1): String? {
@@ -231,8 +233,6 @@ class BridgeFilter(private val template: SimpMessagingTemplate, val resourceLoad
 class RequestQue(val id: String, val requestBuilder: RequestBuilder, var responseObj: Resp?)
 class PartialData(val id: String, val total: Int, val idx: Int, val data: String, val startTime: Long)
 
-//class RequestTrigger(val id: String)
-
 class RequestBuilder(
     val id: String,
     val path: String,
@@ -246,35 +246,8 @@ class RequestBuilder(
 
 class FilePart(val name: String, val fileName: String, val data: String)
 
-//class Message(val id: String, val data: String, val part: Int, val total: Int) : Serializable
-
-//class MessageHandler(val message: Message, template: SimpMessagingTemplate, val onComplete: () -> Unit) {
-//    init {
-//        template.convertAndSend(message)
-//        Thread({
-//            while (!sent.get()) {
-//                Thread.sleep(300)
-//                if (sent.get()) {
-//                    break
-//                } else {
-//                    template.convertAndSend(message)
-//                }
-//            }
-//        }, "sendThread").start()
-//    }
-//
-//    fun complate() {
-//        sent.set(true)
-//        onComplete()
-//    }
-//
-//    private var sent: AtomicBoolean = AtomicBoolean(false)
-//}
-
-
 class Resp(val body: ByteArray?, val statusCode: Int, val headers: Map<String, Array<String>>? = null)
 
-
 object Singletons {
     //    val sendQueue: ConcurrentMap<String, MessageHandler> by lazy { ConcurrentHashMap<String, MessageHandler>() }
     val responseQue: MutableMap<String, Resp> by lazy { mutableMapOf<String, Resp>() }
@@ -294,23 +267,20 @@ class ChunkCollector(private val id: String) {
     private val listSocketChunk = mutableListOf<SocketChunkData>()
     fun add(dt: SocketChunkData) {
         if (!listSocketChunk.any { it.part == dt.part }) {
-//            LogManager.getLogger(this.javaClass).info("add chunk")
             listSocketChunk.add(dt)
         }
 
         if (dt.part == dt.totalPart - 1) {
-//            LogManager.getLogger(this.javaClass).info("timer completion")
             val tStart = LocalDateTime.now()
             fixedRateTimer("timer-$id", false, 20, 100) {
                 if (listSocketChunk.size == dt.totalPart) {
-//                    LogManager.getLogger(this.javaClass).info("chunk complete")
                     val bodyList = listSocketChunk.sortedBy { it.part }.mapNotNull { it.body }
                     var bd = ByteArray(0)
                     bodyList.forEach { bd += it }
                     Singletons.responseQue[id] = Resp(
                         bd,
                         dt.status,
-                        dt.header?.entries?.map { Pair(it.key, it.value.toTypedArray()) }?.toMap()
+                        dt.header?.entries?.associate { Pair(it.key, it.value.toTypedArray()) }
                     )
                     this.cancel()
                 }
@@ -319,7 +289,6 @@ class ChunkCollector(private val id: String) {
                 }
             }
         }
-
     }
 }