Created
December 19, 2023 18:13
-
-
Save octoaea/abe90271a329e63a8edec3fb15eca95a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.aelamel.parallel; | |
| import jakarta.servlet.http.HttpServletRequest; | |
| import lombok.extern.slf4j.Slf4j; | |
| import org.springframework.web.context.request.RequestAttributes; | |
| import org.springframework.web.context.request.RequestContextHolder; | |
| import org.springframework.web.context.request.ServletRequestAttributes; | |
| @Slf4j | |
| public class CanalUtils { | |
| static String canal; // Maybe using a map instead of using a variable for each attribute | |
| private CanalUtils() { | |
| } | |
| public static String getCanal() { | |
| if (canal == null) { | |
| populateCanal(); | |
| } | |
| return canal; | |
| } | |
| public static void populateCanal() { | |
| RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); | |
| if (requestAttributes == null) { | |
| return; | |
| } | |
| if (requestAttributes instanceof ServletRequestAttributes) { | |
| HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest(); | |
| canal = request.getHeader("x-canal") != null ? request.getHeader("x-canal") : request.getParameter("canal"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment