Skip to content

Instantly share code, notes, and snippets.

@octoaea
Created December 19, 2023 18:13
Show Gist options
  • Select an option

  • Save octoaea/abe90271a329e63a8edec3fb15eca95a to your computer and use it in GitHub Desktop.

Select an option

Save octoaea/abe90271a329e63a8edec3fb15eca95a to your computer and use it in GitHub Desktop.
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