|
@@ -20,9 +20,9 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
|
|
import org.springframework.web.servlet.resource.PathResourceResolver
|
|
|
import java.io.IOException
|
|
|
-import java.io.InputStream
|
|
|
import java.io.Serializable
|
|
|
import java.net.InetAddress
|
|
|
+import java.nio.charset.StandardCharsets
|
|
|
import java.util.*
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
import javax.servlet.*
|
|
@@ -101,21 +101,27 @@ class BridgeFilter(private val template: SimpMessagingTemplate, val resourceLoad
|
|
|
res.status = HttpStatus.REQUEST_TIMEOUT.value()
|
|
|
res.writer.write("{\"message\":\"Request timeout. Client not responding\"}")
|
|
|
res.flushBuffer()
|
|
|
+ Singletons.requestInstance.remove(reqId)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
val resFromSocket = Singletons.responseQue[reqId]
|
|
|
- res.status = resFromSocket!!.statusCode
|
|
|
+
|
|
|
+ resFromSocket!!.body?.let {
|
|
|
+ res.outputStream.write(it)
|
|
|
+ }
|
|
|
+
|
|
|
+ res.status = resFromSocket.statusCode
|
|
|
resFromSocket.headers?.let {
|
|
|
- it.entries.forEach { en ->
|
|
|
-// println(en.key + " : " + en.value.joinToString(","))
|
|
|
+ it.entries.filter { f -> resFromSocket.statusCode < 400 || f.key == "Content-Type" }.forEach { en ->
|
|
|
+ println(en.key + " -> " + en.value.joinToString(","))
|
|
|
res.setHeader(en.key, en.value.joinToString(","))
|
|
|
}
|
|
|
}
|
|
|
- res.outputStream.write(IOUtils.toByteArray(resFromSocket.body))
|
|
|
-// resFromSocket.body.let { res.writer.write(it) }
|
|
|
+
|
|
|
res.flushBuffer()
|
|
|
+
|
|
|
Singletons.requestInstance.remove(reqId)
|
|
|
return
|
|
|
}
|
|
@@ -159,7 +165,7 @@ class RequestBuilder(val id: String, val path: String, val method: HttpMethod, v
|
|
|
var queryString: MutableMap<String, Array<String>>? = null
|
|
|
}
|
|
|
|
|
|
-class Resp(val body: InputStream?, val statusCode: Int, val headers: Map<String, Array<String>>? = null)
|
|
|
+class Resp(val body: ByteArray?, val statusCode: Int, val headers: Map<String, Array<String>>? = null)
|
|
|
|
|
|
object Singletons {
|
|
|
val responseQue: MutableMap<String, Resp> by lazy { mutableMapOf<String, Resp>() }
|
|
@@ -172,8 +178,9 @@ class BridgeRestController {
|
|
|
fun responseFromRest(@PathVariable("id") id: String, req: HttpServletRequest): String {
|
|
|
val objectMapper = ObjectMapper()
|
|
|
val typeRef: TypeReference<HashMap<String, Array<String>>> = object : TypeReference<HashMap<String, Array<String>>>() {}
|
|
|
+ val body = IOUtils.toByteArray(req.getPart("body").inputStream)
|
|
|
Singletons.responseQue[id] = Resp(
|
|
|
- req.getPart("body").inputStream,
|
|
|
+ body,
|
|
|
String(IOUtils.toByteArray(req.getPart("status").inputStream)).toInt(),
|
|
|
if (req.getPart("header") != null) {
|
|
|
objectMapper.readValue(String(IOUtils.toByteArray(req.getPart("header").inputStream)), typeRef)
|