|
@@ -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")
|
|
@@ -137,10 +130,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",
|
|
@@ -210,14 +204,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? {
|
|
@@ -237,8 +239,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,
|
|
@@ -252,35 +252,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>() }
|
|
@@ -300,23 +273,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()
|
|
|
}
|
|
@@ -325,7 +295,6 @@ class ChunkCollector(private val id: String) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|