Compare commits
21 Commits
master
...
feature/ad
| Author | SHA1 | Date |
|---|---|---|
|
|
5cdcce465f | |
|
|
7bec311bad | |
|
|
7f109a3dec | |
|
|
186990a93e | |
|
|
4eea57c5cf | |
|
|
3e4e4533ca | |
|
|
5f71c60997 | |
|
|
b7a000e2ab | |
|
|
8b39e59c46 | |
|
|
4b026ec78c | |
|
|
e211caec2f | |
|
|
a5aa1d6931 | |
|
|
ee0f56cf57 | |
|
|
aebc35ca3e | |
|
|
035ad553a5 | |
|
|
85e5eecfbc | |
|
|
9cfe8ee7ba | |
|
|
66c99227b9 | |
|
|
91e23327a2 | |
|
|
9cb8099371 | |
|
|
cffefac613 |
|
|
@ -30,11 +30,13 @@ class ServerInfoAdvice(
|
||||||
response: ServerHttpResponse
|
response: ServerHttpResponse
|
||||||
): Any? {
|
): Any? {
|
||||||
for (service in serverInfoHeaders) {
|
for (service in serverInfoHeaders) {
|
||||||
|
val serverInfo = service.getHeaders()
|
||||||
|
|
||||||
|
serverInfo.map {
|
||||||
response
|
response
|
||||||
.headers
|
.headers
|
||||||
.addAll(
|
.add(it.first, it.second)
|
||||||
service.getHeaders()
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,6 @@ import org.springframework.context.annotation.Configuration
|
||||||
|
|
||||||
@Suppress("SpringFacetCodeInspection")
|
@Suppress("SpringFacetCodeInspection")
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan("ru.touchin.server.info.advices")
|
@ComponentScan("ru.touchin.server.info.advices", "ru.touchin.server.info.controllers")
|
||||||
@ConfigurationPropertiesScan("ru.touchin.server.info")
|
@ConfigurationPropertiesScan("ru.touchin.server.info")
|
||||||
class ServerInfo
|
class ServerInfo
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package ru.touchin.server.info.controllers
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
import ru.touchin.server.info.response.ServerInfoResponse
|
||||||
|
import ru.touchin.server.info.services.ServerInfoHeader
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/info")
|
||||||
|
class ServerInfoController(
|
||||||
|
private val serverInfoHeaders: List<ServerInfoHeader>
|
||||||
|
) {
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
fun getServerInfo(): ServerInfoResponse {
|
||||||
|
val serverInfoList = mutableListOf<Map<String, String>>()
|
||||||
|
|
||||||
|
for (service in serverInfoHeaders) {
|
||||||
|
val headers = service.getHeaders()
|
||||||
|
|
||||||
|
headers.map {
|
||||||
|
serverInfoList.add(
|
||||||
|
mapOf(it)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ServerInfoResponse(
|
||||||
|
serverInfo = serverInfoList
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package ru.touchin.server.info.response
|
||||||
|
|
||||||
|
import org.springframework.util.MultiValueMap
|
||||||
|
|
||||||
|
data class ServerInfoResponse(
|
||||||
|
val serverInfo: List<Map<String, String>>
|
||||||
|
)
|
||||||
|
|
@ -4,6 +4,6 @@ import org.springframework.util.MultiValueMap
|
||||||
|
|
||||||
interface ServerInfoHeader {
|
interface ServerInfoHeader {
|
||||||
|
|
||||||
fun getHeaders(): MultiValueMap<String, String>
|
fun getHeaders(): List<Pair<String, String>>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,10 @@ class BuildVersionHeader(
|
||||||
private val serverInfoProperties: ServerInfoProperties
|
private val serverInfoProperties: ServerInfoProperties
|
||||||
) : ServerInfoHeader {
|
) : ServerInfoHeader {
|
||||||
|
|
||||||
override fun getHeaders(): MultiValueMap<String, String> {
|
override fun getHeaders(): List<Pair<String, String>> {
|
||||||
return LinkedMultiValueMap<String, String>()
|
return listOf(
|
||||||
.apply {
|
"X-App-Build-Version" to serverInfoProperties.buildVersion
|
||||||
this.add("X-App-Build-Version", serverInfoProperties.buildVersion)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package ru.touchin.server.info.controllers
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
|
import org.springframework.test.context.ActiveProfiles
|
||||||
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
|
||||||
|
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
|
||||||
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
|
||||||
|
|
||||||
|
@ActiveProfiles("test")
|
||||||
|
@SpringBootTest
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
class ServerInfoControllerMvcTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var mockMvc: MockMvc
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldBeWrappedResponse() {
|
||||||
|
mockMvc
|
||||||
|
.perform(MockMvcRequestBuilders.get("/info"))
|
||||||
|
.andDo(MockMvcResultHandlers.print())
|
||||||
|
.andExpect(MockMvcResultMatchers.status().isOk)
|
||||||
|
.andExpect(MockMvcResultMatchers.content().json(
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"serverInfo": [
|
||||||
|
{
|
||||||
|
"X-App-Build-Version": "1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue