124 lines
5.6 KiB
Kotlin
124 lines
5.6 KiB
Kotlin
//package kr.lunaticbum.back.lun.configs
|
|
//
|
|
//import io.netty.channel.ChannelOption
|
|
//import io.netty.handler.timeout.ReadTimeoutHandler
|
|
//import io.netty.handler.timeout.WriteTimeoutHandler
|
|
//import jakarta.servlet.ServletContext
|
|
//import jakarta.servlet.ServletException
|
|
//import kr.lunaticbum.back.lun.utils.LogService
|
|
//import lombok.RequiredArgsConstructor
|
|
//import org.springframework.beans.factory.annotation.Autowired
|
|
//import org.springframework.beans.factory.annotation.Qualifier
|
|
//import org.springframework.context.annotation.Bean
|
|
//import org.springframework.http.client.reactive.ReactorClientHttpConnector
|
|
//import org.springframework.web.WebApplicationInitializer
|
|
//import org.springframework.web.context.ContextLoaderListener
|
|
//import org.springframework.web.context.support.AnnotationConfigWebApplicationContext
|
|
//import org.springframework.web.reactive.function.client.ClientRequest
|
|
//import org.springframework.web.reactive.function.client.ClientResponse
|
|
//import org.springframework.web.reactive.function.client.ExchangeFilterFunction
|
|
//import org.springframework.web.reactive.function.client.WebClient
|
|
//import org.springframework.web.servlet.DispatcherServlet
|
|
//import org.springframework.web.servlet.HandlerInterceptor
|
|
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry
|
|
//import org.springframework.web.util.DefaultUriBuilderFactory
|
|
//import reactor.core.publisher.Mono
|
|
//import reactor.netty.Connection
|
|
//import reactor.netty.http.client.HttpClient
|
|
//import java.time.Duration
|
|
//import java.util.concurrent.TimeUnit
|
|
//import java.util.function.Consumer
|
|
//
|
|
//
|
|
//@RequiredArgsConstructor
|
|
//class WebConfig : WebApplicationInitializer {
|
|
//
|
|
// lateinit var logService : LogService
|
|
//
|
|
// var factory: DefaultUriBuilderFactory = DefaultUriBuilderFactory()
|
|
//
|
|
// var httpClient: HttpClient = HttpClient.create()
|
|
// .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000) // 10초
|
|
//
|
|
//
|
|
// @Throws(ServletException::class)
|
|
// override fun onStartup(servletContext: ServletContext) {
|
|
// // Spring MVC 프로젝트 설정을 위해 작성하는 클래스의 객체를 생성한다.
|
|
// val servletAppContext = AnnotationConfigWebApplicationContext()
|
|
//// servletAppContext.register(ServletAppContext::class.java)
|
|
//
|
|
// // 요청 발생 시 요청을 처리하는 서블릿을 DispatcherServlet으로 설정해준다.
|
|
//// val dispatcherServlet = DispatcherServlet(servletAppContext)
|
|
//// val servlet = servletContext.addServlet("dispatcher", dispatcherServlet)
|
|
////
|
|
//// // 부가 설정
|
|
//// servlet.setLoadOnStartup(1)
|
|
//// servlet.addMapping("/")
|
|
//
|
|
// // Bean을 정의하는 클래스를 지정한다.
|
|
// val rootAppContext = AnnotationConfigWebApplicationContext()
|
|
// rootAppContext.register(RootAppContext::class.java)
|
|
//
|
|
// val listener = ContextLoaderListener(rootAppContext)
|
|
// servletContext.addListener(listener)
|
|
// }
|
|
//
|
|
//
|
|
//
|
|
//
|
|
// @Bean
|
|
// fun webClient(): WebClient {
|
|
// /**
|
|
// * 통신시 timeout 세팅
|
|
// * - connect, read, write 를 모두 5000ms
|
|
// */
|
|
//
|
|
// val httpClient = HttpClient.create()
|
|
// .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
|
|
// .responseTimeout(Duration.ofMillis(5000))
|
|
// .doOnConnected { conn: Connection ->
|
|
// conn.addHandlerLast(ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS))
|
|
// .addHandlerLast(WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS))
|
|
// }
|
|
//
|
|
// val webClient = WebClient.builder()
|
|
// .baseUrl("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w")
|
|
// .clientConnector(ReactorClientHttpConnector(httpClient)) //생성한 HttpClient 연결
|
|
// //Request Header 로깅 필터
|
|
// .filter(
|
|
// ExchangeFilterFunction.ofRequestProcessor { clientRequest: ClientRequest ->
|
|
// logService.log(">>>>>>>>> REQUEST <<<<<<<<<<")
|
|
// logService.log("Request: ${clientRequest.method()} ${clientRequest.url()}")
|
|
// clientRequest.headers()
|
|
// .forEach { (name: String?, values: MutableList<String?>?) ->
|
|
// values.forEach(
|
|
// Consumer<String> { value: String? ->
|
|
// logService.log(
|
|
// "${name} : ${value}"
|
|
// )
|
|
// })
|
|
// }
|
|
// Mono.just<ClientRequest>(clientRequest)
|
|
// }
|
|
// ) //Response Header 로깅 필터
|
|
// .filter(
|
|
// ExchangeFilterFunction.ofResponseProcessor { clientResponse: ClientResponse ->
|
|
// logService.log(">>>>>>>>>> RESPONSE <<<<<<<<<<")
|
|
// clientResponse.headers().asHttpHeaders()
|
|
// .forEach { (name: String?, values: MutableList<String?>?) ->
|
|
// values.forEach(
|
|
// Consumer<String> { value: String? ->
|
|
// logService.log(
|
|
// "${name} ${value}"
|
|
// )
|
|
// })
|
|
// }
|
|
// Mono.just<ClientResponse>(clientResponse)
|
|
// }
|
|
// )
|
|
// .defaultHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8") //기본 헤더설정
|
|
// .build()
|
|
//
|
|
// return webClient
|
|
// }
|
|
//} |