Spring Boot

    Spring RequestContextHolder

    RequestContextHolder 개요 RequestContextHolder 는 Spring에서 전역으로 Request에 대한 정보를 가져오고자 할 때 사용하는 유틸성 클래스이다. 주로, Controller가 아닌 Business Layer 등에서 Request 객체를 참고하려 할 때 사용한다. Request Param이라던지.. UserAgent 라던지.. 매번 method의 call param으로 넘기기가 애매할 때 주로 쓰인다. 아래처럼 호출하면 같은 Request Thread 범위에 있는 경우 요청정보를 얻어낼 수 있다. RequestContextHolder.getRequestAttributes() 다만, 위에처럼 사용하면 Attribute만 얻어올 수 있으므로 아래와 같이 Wrapping해서..

    Spring Boot Prometheus Converter 406 Not Acceptable

    개요 Spring Boot Project에 actuator를 적용한 뒤, prometheus micrometer를 적용했을 때 WebMvcConfigurationSupport 를 customizing 하게 되면 발생하는 문제에 대한 해결책이다. 해당 문제를 보려면 일단 Spring Boot Project를 생성하자. (Spring boot Initializer를 사용하면 편리하다) 그 뒤, 아래의 dependency를 추가한다. org.springframework.boot spring-boot-starter-actuator io.micrometer micrometer-registry-prometheus application.properties에 아래 내용을 추가한다(추가하지 않으면 /actuator/pr..

    [Spring boot] Websocket connect / disconnect 관련

    spring boot로 websocket을 개발하다보면 Session의 Connect / Disconnect 되는 시점을 알고 싶을 때가 있는데(사용자 동시 접속 리스트 관리 차원) 그때는 ChannelInterceptorAdapter를 사용하면 된다. @Component public class StompHandler extends ChannelInterceptorAdapter { private final Logger logger = getLogger(this.getClass()); @Override public void postSend(Message message, MessageChannel channel, boolean sent) { StompHeaderAccessor accessor = StompH..

    [Spring Boot] Spring Security maximumSessions 관련

    spring boot security(라고 쓰고, spring security 라고 읽을 수도 있다) 에서 동시접속 세션수를 제한하는 기능이 있다. @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.sessionManagement() .maximumSessions(1) .maxSessionsPreventsLogin(true) } } 위와 같이 @Configuration에 @EnableWebSecurity 어노테이션을 붙인 뒤, WebSec..

    Netty 통신 서버 개발 관련 주저리

    Netty? Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. netty는 JAVA 진영의 Transport Layer에서 가장 유명한(?) 프레임워크이다. TCP 뿐만 아니라 HTTP, UDP 등 사실상 byte를 송/수신하는데에 두루두루 쓰이고 있는 상황이다. 수 많은 프레임워크들이 클러스터링 구성을 하거나 할 때 내부 통신(inner-communication)을 하는 프레임워크로 netty를 주로 사용하고 있다. 내부 구현은 JAVA NIO로 되어 있으며, 플랫폼에 따라 Epoll(..

    [Spring] spring boot XML Response 매핑

    Springboot에서 @RestController로 내려주는 Value에 대해서는 JSON 매핑을 알아서 변형해서 내려주지만, XML은 기본적으로 매핑되지 않아서 내려주지 않는다(Accept : application/xml로 요청 왔을 시 -> 406 Not Acceptable 로 떨군다) 해결법은 com.fasterxml.jackson.dataformat jackson-dataformat-xml 을 추가하면 된다 jackson 라이브러리의 dataformat-xml을 추가해주게 되면 JSON을 기반으로 내려주던 것을 XML로도 내려준다 그렇게 한 뒤에 Header에 Accept 값을 application/xml로 보내보면 xml로 파싱이 잘 된다.