spring clound @FeignClient @RequestHeader 设置token cookie
public Map<String, String> populateHeaders() { Map<String, String> headers = new HashMap(); String cookie = this.getCookie(); if (StringUtils.isNoneBlank(new CharSequence[]{cookie})) { headers.put("Cookie", cookie); } else{
// 获取cookie
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = Objects.requireNonNull(sra).getRequest();
Cookie[] cookies = request.getCookies();
StringBuilder cookieBuilder = new StringBuilder();
for (Cookie cookie : cookies) {
cookieBuilder.append(cookie.getName()).append("=").append(cookie.getValue()).append(";");
}
String cookie = cookieBuilder.substring(0,cookieBuilder.length()-1);
headers.put("Cookie", cookie);
} String accessToken = this.getAccessToken(); if (StringUtils.isNoneBlank(new CharSequence[]{accessToken})) { headers.put("accessToken", accessToken); } return headers; }
Map<String, String> headers = new HashMap();
headers.put("Cookie", cookie);
headers.put("accessToken", accessToken);
object bopFeign.getWarehouse(wRequest, headers);
@FeignClient(value = "test-bop-service")
public interface TestBopFeign {
@GetMapping(value = "/getPageWarehouse") object getWarehouse(@SpringQueryMap WarRequest wRequest,@RequestHeader Map<String, String> headers);
}