Post
EN

Spring Cloud Gateway AbstractGatewayFilterFactory

using abstractGatewayFilterFactory how to get body data

implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.2")
@Component class LoginFilter() : AbstractGatewayFilterFactory() { private val objectMapper = jacksonObjectMapper() override fun apply(config: Any?): GatewayFilter { return GatewayFilter { exchange, chain -> DataBufferUtils.join(exchange.request.body) .map { val bytes = ByteArray(it.readableByteCount()) it.read(bytes) DataBufferUtils.release(it) bytes }.flatMap { // request body data get val loginRequest = objectMapper.readValue(inputStream, LoginRequest::class.java) } } } data class LoginRequest @JsonCreator constructor( val loginId: String, val password: String, )

abstractGatewayFilterFactory에서 post method, request body에 데이터를 추출 하는 방법을 알아냈고 짧게 정리한다.

This article is licensed under CC BY 4.0 by the author.